From 16ff95a5a70c79f85db967f01b4c0be0f9dd5b89 Mon Sep 17 00:00:00 2001 From: Nicholas Hebert <68243838+n-hebert@users.noreply.github.com> Date: Wed, 10 Aug 2022 18:18:07 -0300 Subject: [PATCH] Permit hands-free passphrase generation --- cmd/age/age.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/age/age.go b/cmd/age/age.go index 4a68489d..edbcbf46 100644 --- a/cmd/age/age.go +++ b/cmd/age/age.go @@ -291,11 +291,16 @@ func passphrasePromptForEncryption() (string, error) { fmt.Fprintln(os.Stderr, "Using passphrase from environment variable.") return pass, nil } - pass, err := readSecret("Enter passphrase (leave empty to autogenerate a secure one):") - if err != nil { - return "", fmt.Errorf("could not read passphrase: %v", err) + p := "" + if _, exists := os.LookupEnv("AGE_AUTOGENERATE_PASSPHRASE"); exists { + fmt.Fprintln(os.Stderr, "Skipping request for the user to enter a passphrase.") + } else { + pass, err := readSecret("Enter passphrase (leave empty to autogenerate a secure one):") + if err != nil { + return "", fmt.Errorf("could not read passphrase: %v", err) + } + p = string(pass) } - p := string(pass) if p == "" { var words []string for i := 0; i < 10; i++ {