Skip to content

Commit 9cc6138

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 fbe54a1 commit 9cc6138

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
@@ -2001,8 +2001,16 @@ func CreateCertificateRequest(rand io.Reader, template *CertificateRequest, priv
20012001
signed = h.Sum(nil)
20022002
}
20032003

2004+
var signerOpts crypto.SignerOpts = hashFunc
2005+
if template.SignatureAlgorithm != 0 && template.SignatureAlgorithm.isRSAPSS() {
2006+
signerOpts = &rsa.PSSOptions{
2007+
SaltLength: rsa.PSSSaltLengthEqualsHash,
2008+
Hash: hashFunc,
2009+
}
2010+
}
2011+
20042012
var signature []byte
2005-
signature, err = key.Sign(rand, signed, hashFunc)
2013+
signature, err = key.Sign(rand, signed, signerOpts)
20062014
if err != nil {
20072015
return
20082016
}

0 commit comments

Comments
 (0)