From c89455063cfd9c531c0a671251ccfcd46f09403d Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Wed, 15 Jun 2016 22:43:31 +0200 Subject: readpassword: create internal package for password reading * Supports stdin * Add tests for extpass and stdin As per user request at https://github.com/rfjakob/gocryptfs/issues/30 --- main.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 6896f11..61b56e6 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,7 @@ import ( "github.com/rfjakob/gocryptfs/internal/fusefrontend" "github.com/rfjakob/gocryptfs/internal/nametransform" "github.com/rfjakob/gocryptfs/internal/prefer_openssl" + "github.com/rfjakob/gocryptfs/internal/readpassword" "github.com/rfjakob/gocryptfs/internal/toggledlog" ) @@ -38,7 +39,6 @@ const ( ERREXIT_CIPHERDIR = 6 ERREXIT_INIT = 7 ERREXIT_LOADCONF = 8 - ERREXIT_PASSWORD = 9 ERREXIT_MOUNTPOINT = 10 ) @@ -71,7 +71,7 @@ func initDir(args *argContainer) { } else { toggledlog.Info.Printf("Using password provided via -extpass.") } - password := readPasswordTwice(args.extpass) + password := readpassword.Twice(args.extpass) creator := toggledlog.ProgramName + " " + GitVersion err = configfile.CreateConfFile(args.config, password, args.plaintextnames, args.scryptn, creator) if err != nil { @@ -121,17 +121,13 @@ func loadConfig(args *argContainer) (masterkey []byte, confFile *configfile.Conf toggledlog.Fatal.Printf(colorRed+"Config file not found: %v\n"+colorReset, err) os.Exit(ERREXIT_LOADCONF) } - if args.extpass == "" { - fmt.Fprintf(os.Stderr, "Password: ") - } - pw := readPassword(args.extpass) - toggledlog.Info.Printf("Decrypting master key... ") + pw := readpassword.Once(args.extpass) + toggledlog.Info.Println("Decrypting master key") masterkey, confFile, err = configfile.LoadConfFile(args.config, pw) if err != nil { toggledlog.Fatal.Println(colorRed + err.Error() + colorReset) os.Exit(ERREXIT_LOADCONF) } - toggledlog.Info.Printf("done.") return masterkey, confFile } @@ -140,7 +136,7 @@ func loadConfig(args *argContainer) (masterkey []byte, confFile *configfile.Conf func changePassword(args *argContainer) { masterkey, confFile := loadConfig(args) toggledlog.Info.Println("Please enter your new password.") - newPw := readPasswordTwice(args.extpass) + newPw := readpassword.Twice(args.extpass) confFile.EncryptKey(masterkey, newPw, confFile.ScryptObject.LogN()) err := confFile.WriteFile() if err != nil { -- cgit v1.2.3