Skip to content
Open
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
12 changes: 11 additions & 1 deletion cmd/age/age.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,20 @@ func decryptNotPass(flags identityFlags, in io.Reader, out io.Writer) {
}

func decryptPass(in io.Reader, out io.Writer) {
passphrase := passphrasePromptForDecryption

if in != os.Stdin && !term.IsTerminal(int(os.Stdin.Fd())) {
passphrase = func() (string, error) {
b, err := io.ReadAll(os.Stdin)
b = bytes.TrimRight(b, "\n")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimming newline to make test case work and improve usability when passphrase is coming from a file or via echo.

return string(b), err
}
}

identities := []age.Identity{
// If there is an scrypt recipient (it will have to be the only one and)
// this identity will be invoked.
&LazyScryptIdentity{passphrasePromptForDecryption},
&LazyScryptIdentity{passphrase},
}

decrypt(identities, in, out)
Expand Down
2 changes: 1 addition & 1 deletion cmd/age/testdata/output_file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ cmp inputcopy input
# https://github.com/FiloSottile/age/issues/159
ttyin terminal
age -p -a -o test.age input
ttyin terminalwrong
ttyin -stdin terminalwrong
! age -o test.out -d test.age
ttyout 'Enter passphrase'
stderr 'incorrect passphrase'
Expand Down
6 changes: 3 additions & 3 deletions cmd/age/testdata/scrypt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ ttyout 'Enter passphrase'
! stdout .

# decrypt with a provided passphrase
ttyin terminal
ttyin -stdin terminal
age -d test.age
ttyout 'Enter passphrase'
! stderr .
cmp stdout input

# decrypt with the wrong passphrase
ttyin wrong
ttyin -stdin wrong
! age -d test.age
stderr 'incorrect passphrase'

Expand All @@ -27,7 +27,7 @@ ttyin empty
age -p -o test.age
! stderr .
! stdout .
ttyin autogenerated
ttyin -stdin autogenerated
age -d test.age
cmp stdout input

Expand Down
9 changes: 8 additions & 1 deletion cmd/age/testdata/terminal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ age -p -a -o test.age
ttyout 'Enter passphrase'
! stderr .
# check the file was encrypted correctly
ttyin terminal
ttyin -stdin terminal
age -d test.age
cmp stdout input

# read passphrase from stdin
stdin password
age -d test.age
cmp stdout input

Expand All @@ -53,5 +58,7 @@ test
-- terminal --
password
password
-- password --
password
-- empty --

Loading