Skip to content

Commit e0aab32

Browse files
crypto/x509: reject critical SKI extensions
Updates #65085 Change-Id: I8a00fff6b2af4e55bcb88456813b5ee1f7b1c01d Reviewed-on: https://go-review.googlesource.com/c/go/+/562344 Reviewed-by: Filippo Valsorda <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent f4bb7b9 commit e0aab32

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
@@ -741,6 +741,10 @@ func processExtensions(out *Certificate) error {
741741
}
742742
case 14:
743743
// RFC 5280, 4.2.1.2
744+
if e.Critical {
745+
// Conforming CAs MUST mark this extension as non-critical
746+
return errors.New("x509: subject key identifier incorrectly marked critical")
747+
}
744748
val := cryptobyte.String(e.Value)
745749
var skid cryptobyte.String
746750
if !val.ReadASN1(&skid, cryptobyte_asn1.OCTET_STRING) {

src/crypto/x509/x509_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4035,3 +4035,28 @@ func TestRejectCriticalAIA(t *testing.T) {
40354035
t.Fatalf("ParseCertificate() unexpected error: %v, want: %s", err, expectedErr)
40364036
}
40374037
}
4038+
4039+
func TestRejectCriticalSKI(t *testing.T) {
4040+
template := Certificate{
4041+
SerialNumber: big.NewInt(1),
4042+
Subject: pkix.Name{CommonName: "Cert"},
4043+
NotBefore: time.Unix(1000, 0),
4044+
NotAfter: time.Unix(100000, 0),
4045+
ExtraExtensions: []pkix.Extension{
4046+
{
4047+
Id: asn1.ObjectIdentifier{2, 5, 29, 14},
4048+
Critical: true,
4049+
Value: []byte{1, 2, 3},
4050+
},
4051+
},
4052+
}
4053+
certDER, err := CreateCertificate(rand.Reader, &template, &template, rsaPrivateKey.Public(), rsaPrivateKey)
4054+
if err != nil {
4055+
t.Fatalf("CreateCertificate() unexpected error: %v", err)
4056+
}
4057+
expectedErr := "x509: subject key identifier incorrectly marked critical"
4058+
_, err = ParseCertificate(certDER)
4059+
if err == nil || err.Error() != expectedErr {
4060+
t.Fatalf("ParseCertificate() unexpected error: %v, want: %s", err, expectedErr)
4061+
}
4062+
}

0 commit comments

Comments
 (0)