Skip to content

Commit

Permalink
better check for passphrase
Browse files Browse the repository at this point in the history
  • Loading branch information
mikew committed Oct 21, 2024
1 parent 3b00fd5 commit bc19c09
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,20 @@ func getSignerForIdentityFile(hostname string) (ssh.Signer, error) {

signer, err := ssh.ParsePrivateKey(key)
if err != nil {
slog.Error("Unable to parse private key, maybe it's password protected", "err", err)
if _, ok := err.(*ssh.PassphraseMissingError); ok {
passPhrase, _ := askForPassword(fmt.Sprintf("Passphrase for %s: ", identityFile))

fmt.Printf("Passphrase for %s: ", identityFile)
passPhrase, _ := term.ReadPassword(0)
fmt.Println()
signer, signerErr := ssh.ParsePrivateKeyWithPassphrase(key, passPhrase)
if signerErr != nil {
slog.Error("Unable to parse private key", "err", signerErr)
return nil, signerErr
}

signer, signerErr := ssh.ParsePrivateKeyWithPassphrase(key, passPhrase)
if signerErr != nil {
slog.Error("Unable to parse private key", "err", signerErr)
return nil, signerErr
return signer, nil
}

return signer, nil
slog.Error("Unable to parse private key", "err", err)
return nil, err
}

return signer, nil
Expand Down

0 comments on commit bc19c09

Please sign in to comment.