Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init_dir: use masterkey arg #831

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func parseCliOpts(osArgs []string) (args argContainer) {
tlog.Fatal.Printf("The options -passfile and -masterkey cannot be used at the same time")
os.Exit(exitcodes.Usage)
}
if len(args.extpass) > 0 && args.masterkey != "" {
if len(args.extpass) > 0 && args.masterkey != "" && !args.init {
tlog.Fatal.Printf("The options -extpass and -masterkey cannot be used at the same time")
os.Exit(exitcodes.Usage)
}
Expand Down
1 change: 1 addition & 0 deletions init_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func initDir(args *argContainer) {
DeterministicNames: args.deterministic_names,
XChaCha20Poly1305: args.xchacha,
LongNameMax: args.longnamemax,
Masterkey: handleArgsMasterkey(args),
})
if err != nil {
tlog.Fatal.Println(err)
Expand Down
8 changes: 6 additions & 2 deletions internal/configfile/config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type CreateArgs struct {
DeterministicNames bool
XChaCha20Poly1305 bool
LongNameMax uint8
Masterkey []byte
}

// Create - create a new config with a random key encrypted with
Expand Down Expand Up @@ -126,8 +127,11 @@ func Create(args *CreateArgs) error {
return err
}
{
// Generate new random master key
key := cryptocore.RandBytes(cryptocore.KeyLen)
key := args.Masterkey
if key == nil {
// Generate new random master key
key = cryptocore.RandBytes(cryptocore.KeyLen)
}
tlog.PrintMasterkeyReminder(key)
// Encrypt it using the password
// This sets ScryptObject and EncryptedKey
Expand Down
15 changes: 15 additions & 0 deletions tests/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package cli

import (
"bytes"
"encoding/hex"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -97,6 +99,19 @@ func TestInitReverse(t *testing.T) {
}
}

// Test -init with -masterkey
func TestInitMasterkey(t *testing.T) {
var testMk = make([]byte, 32)
dir := test_helpers.InitFS(t, fmt.Sprintf("-masterkey=%s", hex.EncodeToString(testMk)))
m, _, err := configfile.LoadAndDecrypt(dir+"/"+configfile.ConfDefaultName, testPw)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(testMk, m) {
t.Error("masterkey does not match")
}
}

// testPasswd changes the password from "test" to "test" using
// the -extpass method, then from "test" to "newpasswd" using the
// stdin method.
Expand Down
Loading