Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cmd/ssh-tpm-keygen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func checkFile(f string) error {
return err
}
if !bytes.Equal(s, []byte("y")) {
return nil
return fmt.Errorf("not overwriting %s", f)
}
}
return nil
Expand Down
20 changes: 19 additions & 1 deletion cmd/ssh-tpm-keygen/testdata/script/keygen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@
exec ssh-tpm-keygen
exists .ssh/id_ecdsa.pub
exists .ssh/id_ecdsa.tpm
rm .ssh

# Declining to overwrite keeps the existing key, "y" replaces it
cp .ssh/id_ecdsa.tpm orig.tpm
stdin no.txt
! exec ssh-tpm-keygen -f .ssh/id_ecdsa
stderr 'not overwriting .ssh/id_ecdsa.tpm'
cmp .ssh/id_ecdsa.tpm orig.tpm
# keygen asks once per existing file (a minor UX quirk: one key, two
# confirmations), and piped stdin only reaches the first prompt, so
# answer "y" via askpass, which runs for every prompt
chmod 755 askpass-yes
exec env SSH_ASKPASS_REQUIRE=force SSH_ASKPASS=./askpass-yes ssh-tpm-keygen -f .ssh/id_ecdsa
! cmp .ssh/id_ecdsa.tpm orig.tpm
rm .ssh orig.tpm

# Check that we can create RSA keys
exec ssh-tpm-keygen -t rsa
Expand Down Expand Up @@ -54,3 +67,8 @@ rm test

-- save_name.txt --
.ssh/new_name
-- no.txt --
n
-- askpass-yes --
#!/bin/sh
echo y
Loading