]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/x509: don't fail on optional auth key id fields
authorRoland Shoemaker <roland@golang.org>
Tue, 29 Jun 2021 16:20:04 +0000 (09:20 -0700)
committerRoland Shoemaker <roland@golang.org>
Wed, 30 Jun 2021 01:29:49 +0000 (01:29 +0000)
If a certificate contains an AuthorityKeyIdentifier extension that
lacks the keyIdentifier field, but contains the authorityCertIssuer
and/or the authorityCertSerialNumber fields, don't return an error and
continue parsing.

Fixes #46854

Change-Id: I82739b415441f639a722755cc1f449d73078adfc
Reviewed-on: https://go-review.googlesource.com/c/go/+/331689
Trust: Roland Shoemaker <roland@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
src/crypto/x509/parser.go
src/crypto/x509/x509_test.go

index 3d51ddd7f57be5c908eeda4f257442c077ee4cc8..f085162a4e88be3d998cdb1bdfebb61282cdee0f 100644 (file)
@@ -734,10 +734,12 @@ func processExtensions(out *Certificate) error {
                                if !val.ReadASN1(&akid, cryptobyte_asn1.SEQUENCE) {
                                        return errors.New("x509: invalid authority key identifier")
                                }
-                               if !akid.ReadASN1(&akid, cryptobyte_asn1.Tag(0).ContextSpecific()) {
-                                       return errors.New("x509: invalid authority key identifier")
+                               if akid.PeekASN1Tag(cryptobyte_asn1.Tag(0).ContextSpecific()) {
+                                       if !akid.ReadASN1(&akid, cryptobyte_asn1.Tag(0).ContextSpecific()) {
+                                               return errors.New("x509: invalid authority key identifier")
+                                       }
+                                       out.AuthorityKeyId = akid
                                }
-                               out.AuthorityKeyId = akid
                        case 37:
                                out.ExtKeyUsage, out.UnknownExtKeyUsage, err = parseExtKeyUsageExtension(e.Value)
                                if err != nil {
index 802bce0f9afc814b42e453e16624c365b353acd2..a4053abf41d4160c6d8112164fabb5ba2bef51e4 100644 (file)
@@ -3174,3 +3174,45 @@ func TestSigAlgMismatch(t *testing.T) {
                }
        }
 }
+
+const optionalA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E5ldHdvcmsxFzAVBgNVBAoTDlZhbGlD
+ZXJ0LCBJbmMuMTUwMwYDVQQLEyxWYWxpQ2VydCBDbGFzcyAyIFBvbGljeSBWYWxp
+ZGF0aW9uIEF1dGhvcml0eTEhMB8GA1UEAxMYaHR0cDovL3d3dy52YWxpY2VydC5j
+b20vMSAwHgYJKoZIhvcNAQkBFhFpbmZvQHZhbGljZXJ0LmNvbYIBATAPBgNVHRMB
+Af8EBTADAQH/MDkGCCsGAQUFBwEBBC0wKzApBggrBgEFBQcwAYYdaHR0cDovL29j
+c3Auc3RhcmZpZWxkdGVjaC5jb20wSgYDVR0fBEMwQTA/oD2gO4Y5aHR0cDovL2Nl
+cnRpZmljYXRlcy5zdGFyZmllbGR0ZWNoLmNvbS9yZXBvc2l0b3J5L3Jvb3QuY3Js
+MFEGA1UdIARKMEgwRgYEVR0gADA+MDwGCCsGAQUFBwIBFjBodHRwOi8vY2VydGlm
+aWNhdGVzLnN0YXJmaWVsZHRlY2guY29tL3JlcG9zaXRvcnkwDgYDVR0PAQH/BAQD
+AgEGMA0GCSqGSIb3DQEBBQUAA4GBAKVi8afCXSWlcD284ipxs33kDTcdVWptobCr
+mADkhWBKIMuh8D1195TaQ39oXCUIuNJ9MxB73HZn8bjhU3zhxoNbKXuNSm8uf0So
+GkVrMgfHeMpkksK0hAzc3S1fTbvdiuo43NlmouxBulVtWmQ9twPMHOKRUJ7jCUSV
+FxdzPcwl
+-----END CERTIFICATE-----`
+
+func TestAuthKeyIdOptional(t *testing.T) {
+       b, _ := pem.Decode([]byte(optionalAuthKeyIDPEM))
+       if b == nil {
+               t.Fatalf("couldn't decode test certificate")
+       }
+       _, err := ParseCertificate(b.Bytes)
+       if err != nil {
+               t.Fatalf("ParseCertificate to failed to parse certificate with optional authority key identifier fields: %s", err)
+       }
+}