-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
crypto/x509: malformed signature algorithm identifier error while version and serialNumber swapped #70269
Comments
The TBSCertificate is your certificate looks like this: serialNumber, version, signature. The spec does not allow this kind of order of fields: RFC 5280:
The version is checked first, but it is optional (has a DEFAULT), thus we are skipping it (because of an unexpected tag). After that the parser is still at the same spot, it does not skip the badly-placed serialNumber field, so now the sertialNumber parsing succeeds. After that, the AlgorithmIdentifier parsing fails, because it contains an unexpected tag (badly placed version). I think that the error is correct. See the implementation for reference: Lines 829 to 883 in 5123f38
|
Go version
go version go1.23.2 linux/amd64
Output of
go env
in your module/workspace:What did you do?
Use x509.ParseCertificate to parse the der certificate.

The version and serial number of the certificate are swapped.
case.zip
What did you see happen?
Parse error:malformed signature algorithm identifier
What did you expect to see?
Swap the positions of serialnumber and version, and the value of serialnumber is the same as version. Since the type of version is OPTIONAL[0] + INTEGER, and the type of serialnumber is INTEGER, the invalid version should be checked first instead of throwing an alformed signature algorithm identifier.
The text was updated successfully, but these errors were encountered: