summaryrefslogtreecommitdiff
path: root/masterkey.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2020-05-09 16:32:11 +0200
committerJakob Unterwurzacher2020-05-09 16:53:12 +0200
commitff04b1d83ab120197add2fe4d6f6d3ff7a34f1ff (patch)
tree202580b73b47b99b5ee81d9c2e2e9580e15a6520 /masterkey.go
parent7622c9f538d324ba4ed704ff836942af39d2b1f9 (diff)
main: untangle `-masterkey` handling and config loading
This was handled both in getMasterKey(). Split it apart.
Diffstat (limited to 'masterkey.go')
-rw-r--r--masterkey.go35
1 files changed, 11 insertions, 24 deletions
diff --git a/masterkey.go b/masterkey.go
index 3d3b951..7b6779d 100644
--- a/masterkey.go
+++ b/masterkey.go
@@ -5,7 +5,6 @@ import (
"os"
"strings"
- "github.com/rfjakob/gocryptfs/internal/configfile"
"github.com/rfjakob/gocryptfs/internal/cryptocore"
"github.com/rfjakob/gocryptfs/internal/exitcodes"
"github.com/rfjakob/gocryptfs/internal/readpassword"
@@ -34,21 +33,18 @@ func unhexMasterKey(masterkey string, fromStdin bool) []byte {
return key
}
-// getMasterKey looks at "args" to determine where the master key should come
-// from (-masterkey=a-b-c-d or stdin or from the config file).
-// If it comes from the config file, the user is prompted for the password
-// and a ConfFile instance is returned.
-// Calls os.Exit on failure.
-func getMasterKey(args *argContainer) (masterkey []byte, confFile *configfile.ConfFile) {
- masterkeyFromStdin := false
+// handleArgsMasterkey looks at `args.masterkey` and `args.zerokey`, gets the
+// masterkey from the source the user wanted (string on the command line, stdin, all-zero),
+// and returns it in binary. Returns nil if no masterkey source was specified.
+func handleArgsMasterkey(args *argContainer) (masterkey []byte) {
// "-masterkey=stdin"
if args.masterkey == "stdin" {
- args.masterkey = string(readpassword.Once(nil, "", "Masterkey"))
- masterkeyFromStdin = true
+ in := string(readpassword.Once(nil, "", "Masterkey"))
+ return unhexMasterKey(in, true)
}
// "-masterkey=941a6029-3adc6a1c-..."
if args.masterkey != "" {
- return unhexMasterKey(args.masterkey, masterkeyFromStdin), nil
+ return unhexMasterKey(args.masterkey, false)
}
// "-zerokey"
if args.zerokey {
@@ -56,18 +52,9 @@ func getMasterKey(args *argContainer) (masterkey []byte, confFile *configfile.Co
tlog.Info.Printf(tlog.ColorYellow +
"ZEROKEY MODE PROVIDES NO SECURITY AT ALL AND SHOULD ONLY BE USED FOR TESTING." +
tlog.ColorReset)
- return make([]byte, cryptocore.KeyLen), nil
- }
- var err error
- // Load master key from config file (normal operation).
- // Prompts the user for the password.
- masterkey, confFile, err = loadConfig(args)
- if err != nil {
- if args._ctlsockFd != nil {
- // Close the socket file (which also deletes it)
- args._ctlsockFd.Close()
- }
- exitcodes.Exit(err)
+ return make([]byte, cryptocore.KeyLen)
}
- return masterkey, confFile
+ // No master key source specified on the command line. Caller must parse
+ // the config file.
+ return nil
}