summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-06-15 22:43:31 +0200
committerJakob Unterwurzacher2016-06-15 22:44:24 +0200
commitc89455063cfd9c531c0a671251ccfcd46f09403d (patch)
tree1bd5330aad0ac7b16ecb5b35150a304e56271be3 /main.go
parent218bf83ce399832a0eccfbd025e5dd0399db6bed (diff)
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
Diffstat (limited to 'main.go')
-rw-r--r--main.go14
1 files changed, 5 insertions, 9 deletions
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 {