Skip to content

Commit 63fb021

Browse files
committed
crypto/x509: fix certificate request creation with RSA-PSS
In case of a RSA-PSS algorithm, the hashFunc of CreateCertificateRequest is embedded in a rsa.PSSOptions struct. Given to key.Sign(), this will generate a proper RSA-PSS signature. Pasted from the RSA-PSS handling code in CreateCertificate() Fixes #45990
1 parent 1d33b53 commit 63fb021

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/crypto/x509/x509.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -2110,8 +2110,16 @@ func CreateCertificateRequest(rand io.Reader, template *CertificateRequest, priv
21102110
signed = h.Sum(nil)
21112111
}
21122112

2113+
var signerOpts crypto.SignerOpts = hashFunc
2114+
if template.SignatureAlgorithm != 0 && template.SignatureAlgorithm.isRSAPSS() {
2115+
signerOpts = &rsa.PSSOptions{
2116+
SaltLength: rsa.PSSSaltLengthEqualsHash,
2117+
Hash: hashFunc,
2118+
}
2119+
}
2120+
21132121
var signature []byte
2114-
signature, err = key.Sign(rand, signed, hashFunc)
2122+
signature, err = key.Sign(rand, signed, signerOpts)
21152123
if err != nil {
21162124
return
21172125
}

0 commit comments

Comments
 (0)