Skip to content

Commit

Permalink
fix: report on errors in reading the ssh identity file
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanholsteijn committed Aug 3, 2023
1 parent 32f2fed commit 521690b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,16 @@ func identityFileAuthentication(user string, host string) (auth transport.AuthMe

var keyFile = sshconfig.Get(host, "IdentityFile")
if keyFile, err = homedir.Expand(keyFile); err != nil {
return nil, err
return nil, fmt.Errorf("ERROR: failed to expand home directory of IdentityFile %s, %s",
sshconfig.Get(host, "IdentityFile"), err)
}

if user == "" {
user = sshconfig.Get(host, "User")
}

if _, err = os.Stat(keyFile); os.IsNotExist(err) {
log.Printf("INFO: IdentityFile %s not found", keyFile)
return nil, nil
}

Expand All @@ -144,6 +146,8 @@ func identityFileAuthentication(user string, host string) (auth transport.AuthMe
signer, parseError := ssh.ParsePrivateKey(key)
if parseError == nil {
return &gitssh.PublicKeys{User: user, Signer: signer}, nil
} else {
log.Printf("WARNING: failed to parse private key from %s, %s", keyFile, err)
}

if missingErr, ok := parseError.(*ssh.PassphraseMissingError); ok {
Expand All @@ -153,7 +157,6 @@ func identityFileAuthentication(user string, host string) (auth transport.AuthMe
if publicKey, _, _, _, publicKeyParseError := ssh.ParseAuthorizedKey(key); publicKeyParseError == nil {
return sshAgentAuthentication(user, host, keyFile, publicKey)
}

return nil, fmt.Errorf("ERROR: failed to read private key from '%s', %s", keyFile, parseError)
}

Expand Down

0 comments on commit 521690b

Please sign in to comment.