cmd/age: confirm encryption passphrase

Fixes #39
This commit is contained in:
Filippo Valsorda
2019-12-30 00:41:53 +01:00
parent 0da94651f3
commit dd887fdc87

View File

@@ -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
}