Skip to content

Commit 671696a

Browse files
rolandshoemakergopherbot
authored andcommitted
crypto/x509: reject critical AKI
Updates #65085 Change-Id: I8cc60990737d582edf4f7f85ec871f5e42f82b78 Reviewed-on: https://go-review.googlesource.com/c/go/+/562341 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Auto-Submit: Roland Shoemaker <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]>
1 parent 2064413 commit 671696a

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
@@ -723,6 +723,10 @@ func processExtensions(out *Certificate) error {
723723

724724
case 35:
725725
// RFC 5280, 4.2.1.1
726+
if e.Critical {
727+
// Conforming CAs MUST mark this extension as non-critical
728+
return errors.New("x509: authority key identifier incorrectly marked critical")
729+
}
726730
val := cryptobyte.String(e.Value)
727731
var akid cryptobyte.String
728732
if !val.ReadASN1(&akid, cryptobyte_asn1.SEQUENCE) {

src/crypto/x509/x509_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,6 +4011,31 @@ func TestGob(t *testing.T) {
40114011
}
40124012
}
40134013

4014+
func TestRejectCriticalAKI(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{2, 5, 29, 35},
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 key identifier 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+
}
4038+
40144039
func TestRejectCriticalAIA(t *testing.T) {
40154040
template := Certificate{
40164041
SerialNumber: big.NewInt(1),

0 commit comments

Comments
 (0)