Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry SSH key verification with additional CRLF if it failed #28392

Merged
merged 11 commits into from
Dec 14, 2023
4 changes: 3 additions & 1 deletion models/asymkey/ssh_key_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func VerifySSHKey(ctx context.Context, ownerID int64, fingerprint, token, signat
return "", ErrKeyNotExist{}
}

if err := sshsig.Verify(bytes.NewBuffer([]byte(token)), []byte(signature), []byte(key.Content), "gitea"); err != nil {
// edge case for Windows based shells that will add CR LF if piped to ssh-keygen command
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
errcrlf := sshsig.Verify(bytes.NewBuffer([]byte(token+"\r\n")), []byte(signature), []byte(key.Content), "gitea")
if err := sshsig.Verify(bytes.NewBuffer([]byte(token)), []byte(signature), []byte(key.Content), "gitea"); err != nil && errcrlf != nil {
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
log.Error("Unable to validate token signature. Error: %v", err)
return "", ErrSSHInvalidTokenSignature{
Fingerprint: key.Fingerprint,
Expand Down