Skip to content

Commit f4bb7b9

Browse files
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 <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 5856162 commit f4bb7b9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/crypto/x509/parser.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,10 @@ func processExtensions(out *Certificate) error {
764764
}
765765
} else if e.Id.Equal(oidExtensionAuthorityInfoAccess) {
766766
// RFC 5280 4.2.2.1: Authority Information Access
767+
if e.Critical {
768+
// Conforming CAs MUST mark this extension as non-critical
769+
return errors.New("x509: authority info access incorrectly marked critical")
770+
}
767771
val := cryptobyte.String(e.Value)
768772
if !val.ReadASN1(&val, cryptobyte_asn1.SEQUENCE) {
769773
return errors.New("x509: invalid authority info access")

src/crypto/x509/x509_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4010,3 +4010,28 @@ func TestGob(t *testing.T) {
40104010
t.Fatal(err)
40114011
}
40124012
}
4013+
4014+
func TestRejectCriticalAIA(t *testing.T) {
4015+
template := Certificate{
4016+
SerialNumber: big.NewInt(1),
4017+
Subject: pkix.Name{CommonName: "Cert"},
4018+
NotBefore: time.Unix(1000, 0),
4019+
NotAfter: time.Unix(100000, 0),
4020+
ExtraExtensions: []pkix.Extension{
4021+
{
4022+
Id: asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 1, 1},
4023+
Critical: true,
4024+
Value: []byte{1, 2, 3},
4025+
},
4026+
},
4027+
}
4028+
certDER, err := CreateCertificate(rand.Reader, &template, &template, rsaPrivateKey.Public(), rsaPrivateKey)
4029+
if err != nil {
4030+
t.Fatalf("CreateCertificate() unexpected error: %v", err)
4031+
}
4032+
expectedErr := "x509: authority info access incorrectly marked critical"
4033+
_, err = ParseCertificate(certDER)
4034+
if err == nil || err.Error() != expectedErr {
4035+
t.Fatalf("ParseCertificate() unexpected error: %v, want: %s", err, expectedErr)
4036+
}
4037+
}

0 commit comments

Comments
 (0)