mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 12:16:20 +08:00
disable signing with MD5WithRSA #56
This commit is contained in:
parent
ff60ecbcc8
commit
60f734b82c
@ -1203,6 +1203,10 @@ func signingParamsForPublicKey(pub interface{}, requestedSigAlgo SignatureAlgori
|
|||||||
err = errors.New("x509: cannot sign with hash function requested")
|
err = errors.New("x509: cannot sign with hash function requested")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if hashFunc == crypto.MD5 {
|
||||||
|
err = errors.New("x509: signing with MD5 is not supported")
|
||||||
|
return
|
||||||
|
}
|
||||||
if isRSAPSS(requestedSigAlgo) {
|
if isRSAPSS(requestedSigAlgo) {
|
||||||
sigAlgo.Parameters = hashToPSSParameters[hashFunc]
|
sigAlgo.Parameters = hashToPSSParameters[hashFunc]
|
||||||
}
|
}
|
||||||
@ -1400,16 +1404,9 @@ func CreateCertificate(rand io.Reader, template, parent *x509.Certificate, pub,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check the signature to ensure the crypto.Signer behaved correctly.
|
// Check the signature to ensure the crypto.Signer behaved correctly.
|
||||||
sigAlg := getSignatureAlgorithmFromAI(signatureAlgorithm)
|
if err := checkSignature(getSignatureAlgorithmFromAI(signatureAlgorithm), c.Raw, signature, key.Public(), true); err != nil {
|
||||||
switch sigAlg {
|
|
||||||
case MD5WithRSA:
|
|
||||||
// We skip the check if the signature algorithm is only supported for
|
|
||||||
// signing, not verification.
|
|
||||||
default:
|
|
||||||
if err := checkSignature(sigAlg, c.Raw, signature, key.Public(), true); err != nil {
|
|
||||||
return nil, fmt.Errorf("x509: signature over certificate returned by signer is invalid: %w", err)
|
return nil, fmt.Errorf("x509: signature over certificate returned by signer is invalid: %w", err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return signedCert, nil
|
return signedCert, nil
|
||||||
}
|
}
|
||||||
|
@ -2358,8 +2358,8 @@ func TestCreateCertificateLegacy(t *testing.T) {
|
|||||||
SignatureAlgorithm: sigAlg,
|
SignatureAlgorithm: sigAlg,
|
||||||
}
|
}
|
||||||
_, err := CreateCertificate(rand.Reader, template.asX509(), template.asX509(), testPrivateKey.Public(), &brokenSigner{testPrivateKey.Public()})
|
_, err := CreateCertificate(rand.Reader, template.asX509(), template.asX509(), testPrivateKey.Public(), &brokenSigner{testPrivateKey.Public()})
|
||||||
if err != nil {
|
if err == nil {
|
||||||
t.Fatalf("CreateCertificate failed when SignatureAlgorithm = %v: %s", sigAlg, err)
|
t.Fatal("CreateCertificate didn't fail when SignatureAlgorithm = MD5WithRSA")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user