-
Notifications
You must be signed in to change notification settings - Fork 18.1k
crypto/x509: invalid authority key identifier parsing older root "Starfield Class 2 Certification Authority" #46854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Old parser code: type authKeyId struct {
Id []byte `asn1:"optional,tag:0"`
}
// RFC 5280, 4.2.1.1
var a authKeyId
if rest, err := asn1.Unmarshal(e.Value, &a); err != nil {
return nil, err
} else if len(rest) != 0 {
return nil, errors.New("x509: trailing data after X.509 authority key-id")
}
out.AuthorityKeyId = a.Id New parser code: // RFC 5280, 4.2.1.1
val := cryptobyte.String(e.Value)
var akid cryptobyte.String
if !val.ReadASN1(&akid, cbasn1.SEQUENCE) {
return errors.New("x509: invalid authority key identifier")
}
if !akid.ReadASN1(&akid, cbasn1.Tag(0).ContextSpecific()) {
return errors.New("x509: invalid authority key identifier")
}
out.AuthorityKeyId = akid This certificate does have a weird structure compared to modern certificates in the wild. OpenSSL renders it as:
|
Blergh. This is caused by the new parser being somewhat stricter about what it accepts and sort of a bug. Whereas the old parser would allow SEQUENCEs to lack expected fields, and contain unexpected trailing fields (the latter of which is a perfectly reasonable thing to do in ASN.1). We're expecting an optional field to be present (because it's the only actual field that is actually used) and ignoring other optional fields, really we shouldn't do the former but should continue to do the latter. I'll write up a fix for this. |
Change https://golang.org/cl/331689 mentions this issue: |
Uh oh!
There was an error while loading. Please reload this page.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
It does not reproduce with Go 1.16. It only occurs on tip on or after 51ff3a6, when the certificate parser was rewritten.
What operating system and processor architecture are you using (
go env
)?darwin/amd64, macOS 11.4. It has also been reproduced on Linux.
What did you do?
Given the sample program:
And the "Starfield Class 2 Certification Authority" certificate: https://crt.sh/?q=d73494e3446b02167573b3cde3ae1c8584ac26e15e45ac3ec0326708425d90fb
Running this program on Go 1.16.5 produces no error. On tip (7a5e704) following 1.17beta1, you get the error
x509: invalid authority key identifier
.What did you expect to see?
The program should terminate without error.
What did you see instead?
x509: invalid authority key identifier
The text was updated successfully, but these errors were encountered: