Skip to content

Commit 52046b9

Browse files
nekrondevHeiko Besemannwxiaoguang
authored
Retry SSH key verification with additional CRLF if it failed (#28392)
Windows-based shells will add a CRLF when piping the token into ssh-keygen command resulting in verification error. This resolves #21527. --------- Co-authored-by: Heiko Besemann <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent cbf923e commit 52046b9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

models/asymkey/ssh_key_verify.go

+9-4
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)