diff --git a/cmd/age/age.go b/cmd/age/age.go index f98c538..a604bb6 100644 --- a/cmd/age/age.go +++ b/cmd/age/age.go @@ -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) } @@ -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 { @@ -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 }