crypto/x509: reject critical AIA extensions

Updates #65085

Change-Id: I86d8a85130286e1ec2aca3249808ec1dc8ec97ca
Reviewed-on: https://go-review.googlesource.com/c/go/+/562342
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Roland Shoemaker 2024-02-07 12:12:14 -08:00
parent 5856162487
commit f4bb7b9186
2 changed files with 29 additions and 0 deletions

View File

@ -764,6 +764,10 @@ func processExtensions(out *Certificate) error {
}
} else if e.Id.Equal(oidExtensionAuthorityInfoAccess) {
// RFC 5280 4.2.2.1: Authority Information Access
if e.Critical {
// Conforming CAs MUST mark this extension as non-critical
return errors.New("x509: authority info access incorrectly marked critical")
}
val := cryptobyte.String(e.Value)
if !val.ReadASN1(&val, cryptobyte_asn1.SEQUENCE) {
return errors.New("x509: invalid authority info access")

View File

@ -4010,3 +4010,28 @@ func TestGob(t *testing.T) {
t.Fatal(err)
}
}
func TestRejectCriticalAIA(t *testing.T) {
template := Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{CommonName: "Cert"},
NotBefore: time.Unix(1000, 0),
NotAfter: time.Unix(100000, 0),
ExtraExtensions: []pkix.Extension{
{
Id: asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 1, 1},
Critical: true,
Value: []byte{1, 2, 3},
},
},
}
certDER, err := CreateCertificate(rand.Reader, &template, &template, rsaPrivateKey.Public(), rsaPrivateKey)
if err != nil {
t.Fatalf("CreateCertificate() unexpected error: %v", err)
}
expectedErr := "x509: authority info access incorrectly marked critical"
_, err = ParseCertificate(certDER)
if err == nil || err.Error() != expectedErr {
t.Fatalf("ParseCertificate() unexpected error: %v, want: %s", err, expectedErr)
}
}