Reject certificates with trailing data. Avoid copying trailing data to WOLFSSL_X509 structs.#10755
Open
kareem-wolfssl wants to merge 2 commits into
Open
Reject certificates with trailing data. Avoid copying trailing data to WOLFSSL_X509 structs.#10755kareem-wolfssl wants to merge 2 commits into
kareem-wolfssl wants to merge 2 commits into
Conversation
In addition, only copy the certificate itself to WOLFSSL_X509, omitting trailing bytes. Thanks to Lucca Hirschi (Inria, France) and the tlspuffin team for the report.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens X.509 parsing behavior to prevent accepting and re-emitting certificates that have extra trailing bytes beyond the certificate’s outer ASN.1 SEQUENCE, while preserving support for OpenSSL/RFC “TRUSTED CERTIFICATE” blobs that legitimately carry auxiliary trust data after the cert.
Changes:
- Add strict-mode detection/rejection of trailing bytes after the certificate’s outer SEQUENCE (with an internal opt-out for TRUSTED_CERT_TYPE).
- Ensure WOLFSSL_X509 DER storage never includes trailing bytes by truncating copies to the parsed outer-SEQUENCE end.
- Adjust TRUSTED_CERT_TYPE handling to be recognized centrally in ParseCertRelative and fix an API test to use the actual DER length.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| wolfssl/wolfcrypt/asn.h | Adds DecodedCert.allowTrailing bit to permit trusted-cert auxiliary trailing data internally. |
| wolfcrypt/src/asn.c | Rejects trailing bytes in strict builds; centralizes TRUSTED_CERT_TYPE handling to allow aux trailing data. |
| tests/api.c | Fixes a test to use the returned DER length (avoids unintended trailing bytes). |
| src/x509.c | Uses ParseCertRelative’s TRUSTED_CERT_TYPE handling and clarifies trusted-cert truncation behavior. |
| src/internal.c | Truncates stored DER in X509/ACERT objects to the end of the outer SEQUENCE (prevents re-emitting trailing bytes). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+22040
to
+22044
| if ((ret == 0) && (!done) && (!stopAtPubKey) && (!stopAfterPubKey) && | ||
| (!cert->allowTrailing) && (cert->srcIdx != cert->maxIdx) | ||
| #ifdef WOLFSSL_CERT_REQ | ||
| && (!cert->isCSR) | ||
| #endif |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes zd#22010
Testing
Provided reproducer, built-in tests
Checklist