Skip to content

Commit 239a7c0

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 0f15920 commit 239a7c0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/crypto/x509/x509.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1970,8 +1970,16 @@ func CreateCertificateRequest(rand io.Reader, template *CertificateRequest, priv
19701970
signed = h.Sum(nil)
19711971
}
19721972

1973+
var signerOpts crypto.SignerOpts = hashFunc
1974+
if template.SignatureAlgorithm != 0 && template.SignatureAlgorithm.isRSAPSS() {
1975+
signerOpts = &rsa.PSSOptions{
1976+
SaltLength: rsa.PSSSaltLengthEqualsHash,
1977+
Hash: hashFunc,
1978+
}
1979+
}
1980+
19731981
var signature []byte
1974-
signature, err = key.Sign(rand, signed, hashFunc)
1982+
signature, err = key.Sign(rand, signed, signerOpts)
19751983
if err != nil {
19761984
return
19771985
}

0 commit comments

Comments
 (0)