Skip to content

crypto/x509: fix certificate request creation with RSA-PSS #55153

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/crypto/x509/x509.go
Original file line number Diff line number Diff line change
Expand Up @@ -2110,8 +2110,16 @@ func CreateCertificateRequest(rand io.Reader, template *CertificateRequest, priv
signed = h.Sum(nil)
}

var signerOpts crypto.SignerOpts = hashFunc
if template.SignatureAlgorithm != 0 && template.SignatureAlgorithm.isRSAPSS() {
signerOpts = &rsa.PSSOptions{
SaltLength: rsa.PSSSaltLengthEqualsHash,
Hash: hashFunc,
}
}

var signature []byte
signature, err = key.Sign(rand, signed, hashFunc)
signature, err = key.Sign(rand, signed, signerOpts)
if err != nil {
return
}
Expand Down
1 change: 1 addition & 0 deletions src/crypto/x509/x509_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,7 @@ func TestCreateCertificateRequest(t *testing.T) {
sigAlgo SignatureAlgorithm
}{
{"RSA", testPrivateKey, SHA256WithRSA},
{"RSA-PSS-SHA256", testPrivateKey, SHA256WithRSAPSS},
{"ECDSA-256", ecdsa256Priv, ECDSAWithSHA256},
{"ECDSA-384", ecdsa384Priv, ECDSAWithSHA256},
{"ECDSA-521", ecdsa521Priv, ECDSAWithSHA256},
Expand Down