Skip to content

Commit 6db272d

Browse files
mateusz834rolandshoemaker
authored andcommitted
crypto/x509: properly pouplate the RevocationList.AuthorityKeyId field
This looks like a oversight in CL 416354. Fixes #67571 Fixes #57461 Change-Id: I564c008989fecf84b437e123d27121ac907642fa GitHub-Last-Rev: fec88bb GitHub-Pull-Request: #67576 Reviewed-on: https://go-review.googlesource.com/c/go/+/587455 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Roland Shoemaker <roland@golang.org>
1 parent ac6dea7 commit 6db272d

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/crypto/x509/parser.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,26 @@ func parseSANExtension(der cryptobyte.String) (dnsNames, emailAddresses []string
416416
return
417417
}
418418

419+
func parseAuthorityKeyIdentifier(e pkix.Extension) ([]byte, error) {
420+
// RFC 5280, Section 4.2.1.1
421+
if e.Critical {
422+
// Conforming CAs MUST mark this extension as non-critical
423+
return nil, errors.New("x509: authority key identifier incorrectly marked critical")
424+
}
425+
val := cryptobyte.String(e.Value)
426+
var akid cryptobyte.String
427+
if !val.ReadASN1(&akid, cryptobyte_asn1.SEQUENCE) {
428+
return nil, errors.New("x509: invalid authority key identifier")
429+
}
430+
if akid.PeekASN1Tag(cryptobyte_asn1.Tag(0).ContextSpecific()) {
431+
if !akid.ReadASN1(&akid, cryptobyte_asn1.Tag(0).ContextSpecific()) {
432+
return nil, errors.New("x509: invalid authority key identifier")
433+
}
434+
return akid, nil
435+
}
436+
return nil, nil
437+
}
438+
419439
func parseExtKeyUsageExtension(der cryptobyte.String) ([]ExtKeyUsage, []asn1.ObjectIdentifier, error) {
420440
var extKeyUsages []ExtKeyUsage
421441
var unknownUsages []asn1.ObjectIdentifier
@@ -723,21 +743,9 @@ func processExtensions(out *Certificate) error {
723743
}
724744

725745
case 35:
726-
// RFC 5280, 4.2.1.1
727-
if e.Critical {
728-
// Conforming CAs MUST mark this extension as non-critical
729-
return errors.New("x509: authority key identifier incorrectly marked critical")
730-
}
731-
val := cryptobyte.String(e.Value)
732-
var akid cryptobyte.String
733-
if !val.ReadASN1(&akid, cryptobyte_asn1.SEQUENCE) {
734-
return errors.New("x509: invalid authority key identifier")
735-
}
736-
if akid.PeekASN1Tag(cryptobyte_asn1.Tag(0).ContextSpecific()) {
737-
if !akid.ReadASN1(&akid, cryptobyte_asn1.Tag(0).ContextSpecific()) {
738-
return errors.New("x509: invalid authority key identifier")
739-
}
740-
out.AuthorityKeyId = akid
746+
out.AuthorityKeyId, err = parseAuthorityKeyIdentifier(e)
747+
if err != nil {
748+
return err
741749
}
742750
case 37:
743751
out.ExtKeyUsage, out.UnknownExtKeyUsage, err = parseExtKeyUsageExtension(e.Value)
@@ -1226,7 +1234,10 @@ func ParseRevocationList(der []byte) (*RevocationList, error) {
12261234
return nil, err
12271235
}
12281236
if ext.Id.Equal(oidExtensionAuthorityKeyId) {
1229-
rl.AuthorityKeyId = ext.Value
1237+
rl.AuthorityKeyId, err = parseAuthorityKeyIdentifier(ext)
1238+
if err != nil {
1239+
return nil, err
1240+
}
12301241
} else if ext.Id.Equal(oidExtensionCRLNumber) {
12311242
value := cryptobyte.String(ext.Value)
12321243
rl.Number = new(big.Int)

src/crypto/x509/x509_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,9 +2908,9 @@ func TestCreateRevocationList(t *testing.T) {
29082908
t.Fatalf("Generated CRL has wrong Number: got %s, want %s",
29092909
parsedCRL.Number.String(), tc.template.Number.String())
29102910
}
2911-
if !bytes.Equal(parsedCRL.AuthorityKeyId, expectedAKI) {
2912-
t.Fatalf("Generated CRL has wrong Number: got %x, want %x",
2913-
parsedCRL.AuthorityKeyId, expectedAKI)
2911+
if !bytes.Equal(parsedCRL.AuthorityKeyId, tc.issuer.SubjectKeyId) {
2912+
t.Fatalf("Generated CRL has wrong AuthorityKeyId: got %x, want %x",
2913+
parsedCRL.AuthorityKeyId, tc.issuer.SubjectKeyId)
29142914
}
29152915
})
29162916
}

0 commit comments

Comments
 (0)