diff options
author | Jakob Unterwurzacher | 2016-10-16 18:17:28 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-10-16 18:17:28 +0200 |
commit | c487e176bd517d815315583dfc795dc629ffb20a (patch) | |
tree | 133948cbad8e84063dd034bf0295934a60424bab /main.go | |
parent | ca3cc5eca37617d617c3e0250e3e3aa683fc2b1e (diff) |
main: allow password change with -masterkey
Requested at https://github.com/rfjakob/gocryptfs/issues/28
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 25 |
1 files changed, 21 insertions, 4 deletions
@@ -59,9 +59,14 @@ func loadConfig(args *argContainer) (masterkey []byte, confFile *configfile.Conf os.Exit(ErrExitLoadConf) } fd.Close() - pw := readpassword.Once(args.extpass) - tlog.Info.Println("Decrypting master key") - masterkey, confFile, err = configfile.LoadConfFile(args.config, pw) + if args.masterkey != "" { + masterkey = parseMasterKey(args.masterkey) + _, confFile, err = configfile.LoadConfFile(args.config, "") + } else { + pw := readpassword.Once(args.extpass) + tlog.Info.Println("Decrypting master key") + masterkey, confFile, err = configfile.LoadConfFile(args.config, pw) + } if err != nil { tlog.Fatal.Println(err) os.Exit(ErrExitLoadConf) @@ -75,12 +80,24 @@ func changePassword(args *argContainer) { tlog.Info.Println("Please enter your new password.") newPw := readpassword.Twice(args.extpass) confFile.EncryptKey(masterkey, newPw, confFile.ScryptObject.LogN()) + if args.masterkey != "" { + bak := args.config + ".bak" + err := os.Link(args.config, bak) + if err != nil { + tlog.Fatal.Printf("Could not create backup file: %v", err) + os.Exit(ErrExitInit) + } + tlog.Info.Printf(tlog.ColorGrey+ + "A copy of the old config file has been created at %q.\n"+ + "Delete it after you have verified that you can access your files with the new password."+ + tlog.ColorReset, bak) + } err := confFile.WriteFile() if err != nil { tlog.Fatal.Println(err) os.Exit(ErrExitInit) } - tlog.Info.Printf("Password changed.") + tlog.Info.Printf(tlog.ColorGreen + "Password changed." + tlog.ColorReset) os.Exit(0) } |