Commit 97fc06af06 for golang
commit 97fc06af06eec8411c12549d90446dafcbc0ac5b
Author: Roland Shoemaker <bracewell@google.com>
Date: Sat Nov 28 23:11:54 2026 +0000
crypto/x509: allow NULL parameters for ECDSA signature algorithms
CL 856903 restricted ECDSA AlgorithmIdentifier parameters to be absent
per RFC 3279 Section 2.2.3 and RFC 5758 Section 3.2. However, deployed
hardware/firmware certificates (such as older MbedTLS firmware and
Supermicro BMC platform certificates) and enterprise PKI implementations
(such as Venafi CSRs) emit ASN.1 NULL parameters for ECDSA signature
algorithms.
Allow ASN.1 NULL (in addition to absent) parameters for
oidSignatureECDSAWithSHA{1,256,384,512}, while continuing to reject
non-NULL parameters.
Fixes #83468
Change-Id: I894a38f81b0369f0ebb785a262ca6acb9d1e80ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/868201
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
diff --git a/src/crypto/x509/x509.go b/src/crypto/x509/x509.go
index d5d3f221e9..834922b073 100644
--- a/src/crypto/x509/x509.go
+++ b/src/crypto/x509/x509.go
@@ -547,13 +547,16 @@ func getSignatureAlgorithmFromAI(ai pkix.AlgorithmIdentifier) SignatureAlgorithm
return UnknownSignatureAlgorithm
}
- // RFC 3279, Section 2.2.3 and RFC 5758, Section 3.2
- // > the encoding MUST omit the parameters field
+ // RFC 3279, Section 2.2.3 and RFC 5758, Section 3.2 require omitting the
+ // parameters field for ECDSA, however we allow ASN.1 NULL for compatibility
+ // with deployed hardware/firmware certificates (such as older MbedTLS
+ // firmware and Supermicro BMC platform certificates) and enterprise PKI
+ // implementations (such as Venafi CSRs). See #83468.
case ai.Algorithm.Equal(oidSignatureECDSAWithSHA1),
ai.Algorithm.Equal(oidSignatureECDSAWithSHA256),
ai.Algorithm.Equal(oidSignatureECDSAWithSHA384),
ai.Algorithm.Equal(oidSignatureECDSAWithSHA512):
- if len(params) != 0 {
+ if len(params) != 0 && !bytes.Equal(params, asn1.NullBytes) {
return UnknownSignatureAlgorithm
}
diff --git a/src/crypto/x509/x509_test.go b/src/crypto/x509/x509_test.go
index 601c7070dc..8c064afba3 100644
--- a/src/crypto/x509/x509_test.go
+++ b/src/crypto/x509/x509_test.go
@@ -3239,6 +3239,47 @@ func TestAcceptablePSSParametersEncodings(t *testing.T) {
}
}
+func TestSignatureAlgorithmParameters(t *testing.T) {
+ garbage := []byte{0x02, 0x01, 0x00} // INTEGER 0
+ tests := []struct {
+ name string
+ oid asn1.ObjectIdentifier
+ params []byte
+ want SignatureAlgorithm
+ }{
+ {"ECDSAWithSHA256/absent", oidSignatureECDSAWithSHA256, nil, ECDSAWithSHA256},
+ {"ECDSAWithSHA256/NULL", oidSignatureECDSAWithSHA256, asn1.NullBytes, ECDSAWithSHA256},
+ {"ECDSAWithSHA256/garbage", oidSignatureECDSAWithSHA256, garbage, UnknownSignatureAlgorithm},
+ {"ECDSAWithSHA1/absent", oidSignatureECDSAWithSHA1, nil, ECDSAWithSHA1},
+ {"ECDSAWithSHA1/NULL", oidSignatureECDSAWithSHA1, asn1.NullBytes, ECDSAWithSHA1},
+ {"ECDSAWithSHA1/garbage", oidSignatureECDSAWithSHA1, garbage, UnknownSignatureAlgorithm},
+ {"ECDSAWithSHA384/absent", oidSignatureECDSAWithSHA384, nil, ECDSAWithSHA384},
+ {"ECDSAWithSHA384/NULL", oidSignatureECDSAWithSHA384, asn1.NullBytes, ECDSAWithSHA384},
+ {"ECDSAWithSHA384/garbage", oidSignatureECDSAWithSHA384, garbage, UnknownSignatureAlgorithm},
+ {"ECDSAWithSHA512/absent", oidSignatureECDSAWithSHA512, nil, ECDSAWithSHA512},
+ {"ECDSAWithSHA512/NULL", oidSignatureECDSAWithSHA512, asn1.NullBytes, ECDSAWithSHA512},
+ {"ECDSAWithSHA512/garbage", oidSignatureECDSAWithSHA512, garbage, UnknownSignatureAlgorithm},
+ {"Ed25519/absent", oidSignatureEd25519, nil, PureEd25519},
+ {"Ed25519/NULL", oidSignatureEd25519, asn1.NullBytes, UnknownSignatureAlgorithm},
+ {"DSAWithSHA256/absent", oidSignatureDSAWithSHA256, nil, DSAWithSHA256},
+ {"DSAWithSHA256/NULL", oidSignatureDSAWithSHA256, asn1.NullBytes, UnknownSignatureAlgorithm},
+ {"SHA256WithRSA/absent", oidSignatureSHA256WithRSA, nil, SHA256WithRSA},
+ {"SHA256WithRSA/NULL", oidSignatureSHA256WithRSA, asn1.NullBytes, SHA256WithRSA},
+ {"SHA256WithRSA/garbage", oidSignatureSHA256WithRSA, garbage, UnknownSignatureAlgorithm},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ai := pkix.AlgorithmIdentifier{
+ Algorithm: tt.oid,
+ Parameters: asn1.RawValue{FullBytes: tt.params},
+ }
+ if got := getSignatureAlgorithmFromAI(ai); got != tt.want {
+ t.Errorf("getSignatureAlgorithmFromAI(%v, %x) = %v, want %v", tt.oid, tt.params, got, tt.want)
+ }
+ })
+ }
+}
+
func TestUnknownExtKey(t *testing.T) {
const errorContains = "unknown extended key usage"