From 4b251f3ce1f0a0472ed10a00aeef70c69ba03a5d Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Mon, 3 Jan 2022 15:18:59 +0100 Subject: readpassword: bubble up errors instead of exiting the process This allows cleanups to happen in the caller, like removing the control socket. Fixes https://github.com/rfjakob/gocryptfs/issues/634 --- main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 0ac7423..d1bf0c3 100644 --- a/main.go +++ b/main.go @@ -55,11 +55,15 @@ func loadConfig(args *argContainer) (masterkey []byte, cf *configfile.ConfFile, if cf.IsFeatureFlagSet(configfile.FlagFIDO2) { if args.fido2 == "" { tlog.Fatal.Printf("Masterkey encrypted using FIDO2 token; need to use the --fido2 option.") - os.Exit(exitcodes.Usage) + return nil, nil, exitcodes.NewErr("", exitcodes.Usage) } pw = fido2.Secret(args.fido2, cf.FIDO2.CredentialID, cf.FIDO2.HMACSalt) } else { - pw = readpassword.Once([]string(args.extpass), []string(args.passfile), "") + pw, err = readpassword.Once([]string(args.extpass), []string(args.passfile), "") + if err != nil { + tlog.Fatal.Println(err) + return nil, nil, exitcodes.NewErr("", exitcodes.ReadPassword) + } } tlog.Info.Println("Decrypting master key") masterkey, err = cf.DecryptMasterKey(pw) @@ -93,7 +97,11 @@ func changePassword(args *argContainer) { os.Exit(exitcodes.Usage) } tlog.Info.Println("Please enter your new password.") - newPw := readpassword.Twice([]string(args.extpass), []string(args.passfile)) + newPw, err := readpassword.Twice([]string(args.extpass), []string(args.passfile)) + if err != nil { + tlog.Fatal.Println(err) + os.Exit(exitcodes.ReadPassword) + } logN := confFile.ScryptObject.LogN() if args._explicitScryptn { logN = args.scryptn -- cgit v1.2.3