Closed tomjamescn closed 13 hours ago
How was the certificate generated?
@Freeaqingme This is a certificate generated from third-party sdk and the generate code is closed source.
I think this post will help: https://groups.google.com/forum/#!topic/golang-nuts/SCzlQPNfURk it pointed out that the certificate is not qualified and java, python and openssl command line can parse it.
Should crypto/x509 be lenient in parsing ?
Looking at that other thread, in the golang-nuts
I think the extensions in your certificate might be invalid. Namely CRL Distribution Points: 2.5.29.31 Per the RFC https://www.ietf.org/rfc/rfc5280.txt, the cRLDistributionPoints has to respect a certain definition and is sequence of distributionPoint(s). In your case it seems to be empty.
The relevant code here is x509.ParseCertificate https://github.com/golang/go/blob/master/src/crypto/x509/x509.go#L1497
If e.Value is a single byte, of value 0 as described, then attempt to Unmarshal would fail when it calls into parseTagAndLength https://github.com/golang/go/blob/master/src/encoding/asn1/asn1.go#L524
It appears that some leniency was added when iterating the array of distributionPoint per line 1504 of x509.go checking name. Perhaps some upfront checks on this field, and possibly others, for "empty value" type conditions could be added for leniency. Alternatively, giving clarity on the "truncated tag or length" for this specific condition in x509.go
I don't think it makes sense to add an exception here, the provided certificate is very badly encoded. I'm actually quite surprised Java will happily parse it.
The cRLDistributionPoints
extension value here is just a single byte, 0
(not even ASN.1 NULL), rather than, say, an empty sequence (which would also be invalid given the 5280 definition, but somewhat more understandable to mess up).
sounds like a won't fix.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have a pem which can parsed correctly in java, such as code below:
But in Golang, the code below will return err:
What did you expect to see?
I think x509 implement would be the same and golang code could parse certificate correctly.
What did you see instead?
golang output is:
panic: failed to parse certificate: asn1: syntax error: truncated tag or length