Repository navigation
Fix handling of multiple certs in a single DER in wolfSSL_d2i_X509. - #12073
kareem-wolfssl wants to merge 1 commit into
Conversation
The trailing data rejection broke this function. Trailing data check should be disabled for it as it processes one cert at a time and advances the input pointer. If there is trailing junk, the next call will catch it.
aaf18b3 to
837583f
Compare
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change restoring concatenated DER certificate decoding.
No open issues 🎉
What changed in this PR
Restores wolfSSL_d2i_X509 support for concatenated DER certificates by allowing trailing data while decoding one certificate and advancing the input pointer past it.
Changes:
- Enables trailing data for
wolfSSL_d2i_X509while preserving strict handling in the exact-length certificate and request APIs. - Adds regression tests for concatenated certificates, pointer advancement, truncated input, and trailing junk.
| File | Description |
|---|---|
tests/api/test_ossl_x509_io.h |
Declares and registers the new regression test. |
tests/api/test_ossl_x509_io.c |
Tests certificate decoding boundaries and trailing-data behavior. |
src/x509.c |
Adds a trailing-data option to the shared decoder and enables it for wolfSSL_d2i_X509. |
Review effort: Balanced
|
@claude review |
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. It turns off a strict trailing-data check on a public certificate-parsing API, so a human look is still worthwhile.
What was reviewed:
- How far
*inmoves:derCert->lengthcomes fromAllocCopyDecodedDer(). On the template path it is capped atsrcIdx, and on the non-template path at the reboundedmaxIdx. Either way the pointer moves past one certificate and not past the trailing bytes. - Who is affected: only
wolfSSL_d2i_X509()getsallowTrailing=1.wolfSSL_X509_d2i(),wolfSSL_X509_d2i_ex()andwolfSSL_X509_REQ_d2i()still pass 0, and the existing CSR exemption is unchanged. - Heap: hardcoding NULL changes nothing, because the old path through
wolfSSL_X509_d2i()also passed NULL.
Extended reasoning...
The change is in src/x509.c. It adds an allowTrailing parameter to the static d2i_X509orX509REQ() helper, sets it only for the OpenSSL-compat wolfSSL_d2i_X509(), and adds a test for concatenated DER certificates. It reuses the existing DecodedCert allowTrailing bitfield, which the TRUSTED CERTIFICATE path already uses to skip the asn.c trailing-data rejection. The security-sensitive surface is X.509 DER parsing: the change relaxes the strict trailing-data check for one public API. The diff is small and follows an existing pattern, but because it loosens a parsing strictness check, I deferred instead of approving.
|
Description
The trailing data rejection broke this function. Trailing data check should be disabled for it as it processes one cert at a time and advances the input pointer.
If there is trailing junk, the next call will catch it.
Fixes zd#22757
Testing
Provided test case from user, as well as built in and added tests.
Checklist