Skip to content

x509: stricter parsing - #22799

Closed
icing wants to merge 6 commits into
curl:masterfrom
icing:x509-check-validity-length
Closed

icing wants to merge 6 commits into
curl:masterfrom
icing:x509-check-validity-length

Conversation

@icing

@icing icing commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Check that the "validity" ASN.1 field has a length matching the contained date elements and fail the parsing otherwise.

This is a precaution against malformed cert data that should have been caught by the TLS backend already. A bit added defense.

Check that the "validity" ASN.1 field has a length matching the contained
date elements and fail the parsing otherwise.

This is a precaution against malformed cert data that should have been
caught by the TLS backend already. A bit added defense.
@github-actions github-actions Bot added the TLS label Sep 2, 2026
@icing
icing requested a review from bagder September 2, 2026 11:03
@bagder

bagder commented Sep 2, 2026

Copy link
Copy Markdown
Member

How about adding something to unit test 1657 for this as well?

@icing

icing commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

How about adding something to unit test 1657 for this as well?

I can add a malformed cert PEM into the test, but that makes binary data in our source...meh. Constructing a cert ASN.1 via code is not for the faint of heart. I mean, it can be done, but...

Any idea?

- make DER data args type uint8_t
- add PEMs to test1657 for certificate parse checks
  (not a fan of the binary blobs)
@github-actions github-actions Bot added the tests label Sep 2, 2026
@cpu

cpu commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Any idea?

If you're open to an external tool I've used der-ascii for this sort of thing in the past. You could check in the der2ascii output and then ascii2der it back to the DER at runtime.

If you don't need a valid signature it's also helpful for making annoying mutations to get invalid DER that are hard to do with smarter tools.

@icing

icing commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @cpu! Found der2ascii on my machine which some go code installed..uhm, ok. And I found openssl asn1dump which is also nice to see the structure. But all those have no reversal.

Hmm. I think I'll stick with adding the PEM into the unit tests for now, not requiring external tools on all our test platforms.

@bagder bagder closed this in ed13174 Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants