Skip to content

Commit

Permalink
cmd/age: confirm encryption passphrase
Browse files Browse the repository at this point in the history
Fixes #39
  • Loading branch information
FiloSottile committed Dec 29, 2019
1 parent 0da9465 commit dd887fd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/age/age.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func main() {
case decryptFlag:
decrypt(identityFlags, in, out)
case passFlag:
pass, err := passphrasePromptWithDefault()
pass, err := passphrasePromptForEncryption()
if err != nil {
logFatalf("Error: %v", err)
}
Expand All @@ -158,7 +158,7 @@ func main() {
}
}

func passphrasePromptWithDefault() (string, error) {
func passphrasePromptForEncryption() (string, error) {
fmt.Fprintf(os.Stderr, "Enter passphrase (leave empty to autogenerate a secure one): ")
pass, err := readPassphrase()
if err != nil {
Expand All @@ -172,6 +172,15 @@ func passphrasePromptWithDefault() (string, error) {
}
p = strings.Join(words, "-")
fmt.Fprintf(os.Stderr, "Using the autogenerated passphrase %q.\n", p)
} else {
fmt.Fprintf(os.Stderr, "Confirm passphrase: ")
confirm, err := readPassphrase()
if err != nil {
return "", fmt.Errorf("could not read passphrase: %v", err)
}
if string(confirm) != p {
return "", fmt.Errorf("passphrases didn't match")
}
}
return p, nil
}
Expand Down

0 comments on commit dd887fd

Please sign in to comment.