Skip to content

Commit b47482d

Browse files
GiteaBotnekrondevHeiko Besemannwxiaoguang
authored
Retry SSH key verification with additional CRLF if it failed (#28392) (#28464)
Backport #28392 by @nekrondev 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: nekrondev <[email protected]> Co-authored-by: Heiko Besemann <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 74ab798 commit b47482d

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
@@ -29,10 +29,15 @@ func VerifySSHKey(ownerID int64, fingerprint, token, signature string) (string,
2929
return "", ErrKeyNotExist{}
3030
}
3131

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

0 commit comments

Comments
 (0)