Skip to content

Commit d53d40b

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Retry SSH key verification with additional CRLF if it failed (go-gitea#28392)
2 parents cb0c502 + 52046b9 commit d53d40b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

models/asymkey/ssh_key_verify.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ func VerifySSHKey(ctx context.Context, ownerID int64, fingerprint, token, signat
3030
return "", ErrKeyNotExist{}
3131
}
3232

33-
if err := sshsig.Verify(bytes.NewBuffer([]byte(token)), []byte(signature), []byte(key.Content), "gitea"); err != nil {
34-
log.Error("Unable to validate token signature. Error: %v", err)
35-
return "", ErrSSHInvalidTokenSignature{
36-
Fingerprint: key.Fingerprint,
33+
err = sshsig.Verify(bytes.NewBuffer([]byte(token)), []byte(signature), []byte(key.Content), "gitea")
34+
if err != nil {
35+
// edge case for Windows based shells that will add CR LF if piped to ssh-keygen command
36+
// see https://github.com/PowerShell/PowerShell/issues/5974
37+
if sshsig.Verify(bytes.NewBuffer([]byte(token+"\r\n")), []byte(signature), []byte(key.Content), "gitea") != nil {
38+
log.Error("Unable to validate token signature. Error: %v", err)
39+
return "", ErrSSHInvalidTokenSignature{
40+
Fingerprint: key.Fingerprint,
41+
}
3742
}
3843
}
3944

0 commit comments

Comments
 (0)