Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved certificate parsing issues can silently truncate bundles or client chains and misclassify CSRs, causing incorrect acceptance or rejection of certificate layouts.
2 open issues
What changed in this PR
This PR enables wolfCert to send TLS client certificate chains and load concatenated-DER trust-anchor bundles, supporting devices whose certificates are issued by intermediates.
Changes:
- Loads client chains and DER trust anchors with layout checks and trailing-data handling.
- Preserves EST reenrollment chains while reading only the leaf for CSR and key extraction.
- Adds parser, TLS roundtrip, and CLI tests, plus public API documentation.
| File | Description |
|---|---|
wolfcert/types.h |
Documents certificate-chain and trust-anchor layouts. |
wolfcert/http.h |
Clarifies HTTP TLS certificate inputs. |
tests/unit/test_parse_negative.c |
Adds DER traversal and classification cases. |
tests/unit/test_csr.c |
Tests renewal from a DER chain’s leaf. |
tests/integration/test_est_chain_roundtrip.c |
Tests chain transmission, anchors, layouts, and reenrollment. |
tests/integration/cli_proto_scoping.sh |
Exercises CLI reenrollment with certificate chains. |
tests/CMakeLists.txt |
Registers the chain roundtrip test. |
src/keygen.c |
Limits certificate key extraction to the DER leaf. |
src/internal.h |
Declares DER parsing helpers. |
src/internal.c |
Implements DER traversal and certificate-shape checks. |
src/http.c |
Loads client chains and multiple DER trust anchors. |
src/csr.c |
Reads renewal identity from the DER leaf. |
Makefile.am |
Registers the roundtrip test for Autotools. |
docs/ARCHITECTURE.md |
Explains intermediate certificates in client identities. |
cli/wolfcert_client.c |
Preserves the certificate chain for EST reenrollment. |
Review effort: Balanced
6c18196 to
8f93bab
Compare
|
@claude review |
trust_anchors is documented as PEM or DER, and setup_tls_ex() handed it
to wolfSSL_CTX_load_verify_buffer() in one call. PEM loads every
certificate; ASN.1 loads the first, ignores the rest and returns
success. A bundle whose server issuer is not first, such as a DER
wolfcert_client_get_ca() result fed back as trust_anchors, then failed
the handshake with a bare WOLFCERT_ERR_TLS.
Add wolfcert_der_next(), which splits concatenated DER SEQUENCE by
SEQUENCE and skips 0x00, 0xFF and whitespace filler between and after
them, and wolfcert_der_is_cert(), which recognizes a certificate by its
layout: SEQUENCE { TBS, SEQUENCE, BIT STRING } whose TBS holds a serial,
a signature AlgorithmIdentifier, an issuer and a Validity, which a
PKCS#10 request or a CRL does not, with or without the [0] version tag,
so a v1 certificate counts. Each certificate is loaded on its own, and
one wolfSSL refuses is skipped, as its PEM loader does.
The walk ends at the first item that does not parse or does not have a
certificate's shape, and everything from there on is trailing data. It
is ignored, as it was when wolfSSL loaded only the first certificate, so
a certificate in a padded flash slot or followed by a trailer, a key or
text still loads. If a certificate starts anywhere in the trailing data,
DER of any version or a PEM certificate header, the bundle is refused
instead, naming the byte where the trailing data starts, since ending
the walk there would silently drop the anchors after it. The search
starts where the trailing data starts, so it also finds a certificate
that a stray SEQUENCE header, such as the text "0\n", ran into.
A first SEQUENCE whose length runs past the buffer, a buffer holding
only filler, and garbage before the first SEQUENCE fail with
WOLFCERT_ERR_TLS and a message naming the offset; a length too large for
wolfSSL is WOLFCERT_ERR_BAD_ARG. A bundle with no certificate wolfSSL
accepts fails with WOLFCERT_ERR_TLS and keeps wolfSSL's last refusal for
wolfcert_last_wolfssl_err(). Running out of memory is
WOLFCERT_ERR_MEMORY. Both trust_anchors fields describe the DER layout.
test_parse_negative tables the walker and the certificate check, with a
request and a CRL that it refuses.
Fixes F-16512.
setup_tls_ex() loaded client_cert with wolfSSL_CTX_use_certificate_buffer(), which keeps only the first certificate. A device certificate that chains through an intermediate, such as an IEEE 802.1AR IDevID issued by a manufacturer intermediate, could not authenticate to a server that trusts only the root: the server failed with ASN_NO_SIGNER_E and the client saw WOLFCERT_ERR_TLS or WOLFCERT_ERR_IO. EST reenroll loads current_cert the same way, and an enroll result now carries the issuing chain after the device certificate. Load client_cert with wolfSSL_CTX_use_certificate_chain_buffer_format(), leaf first, then intermediates. A single certificate behaves as before, and the chain goes to ctx->certChain only, so trust anchors are never sent. wolfSSL copies each DER item of the chain into the Certificate message without parsing it, and fails on any byte between or after the items. So a DER client_cert is walked first, and only the leaf and the certificates right behind it reach wolfSSL, v1 ones included, as with a PEM chain. The walk ends at the first item that does not parse or is not a certificate, so a private key, CSR or text stored after the chain is dropped and never goes out in the handshake, as with the old loader. Filler between certificates is refused with a message naming the offset, and a certificate anywhere after the end of the walk, DER or a PEM certificate header, is refused, naming the byte where the trailing data starts, rather than silently cutting the chain short. Each of these fails with WOLFCERT_ERR_TLS before the handshake. A chain longer than wolfSSL's MAX_CHAIN_DEPTH fails with a message saying so, where the old loader ignored everything after the leaf. copy_cert_identity() parsed a DER current_cert as one certificate, so a DER chain failed the reenroll CSR with ASN_PARSE_E; it now reads only the first certificate, and so does cert_spki() behind wolfcert_key_from_id(). wc_GetSubjectPubKeyInfoDerFromCert() already ignores the bytes after the first certificate, so that change is defensive and no test can tell it apart. The server's reenroll identity check reads the peer leaf. client_cert in WolfCertServerCfg and WolfCertHttpSessionCfg, and the mTLS section of ARCHITECTURE.md, now say leaf, then any intermediates; WolfCertServerCfg also gives the DER layout rules and the MAX_CHAIN_DEPTH cap. wolfcert-client reenroll converted --cert to a single DER certificate, so EST reenroll dropped the intermediates and refused a DER chain as a bad --cert. It now passes the file from a DER certificate after any leading whitespace, else from its first PEM header, so leading text that starts with '0' (0x30) is not taken for DER and a DER leaf with PEM after it is refused by the library instead of renewing the PEM certificate. SCEP keeps the single certificate it signs with. test_est_chain_roundtrip covers a PEM and a DER chain against a server whose client CA is only the root, filler or stray bytes between certificates, a key after the chain with and without filler before it and a key before an intermediate, a generated request after the chain or before an intermediate, '0' text before an intermediate, a v1-shaped or PEM certificate after stray bytes or the DER chain, a PEM key, '0' text or padding after the chain, a chain past MAX_CHAIN_DEPTH, DER trust anchor bundles in any order with filler, padding, '0' text, a PEM key, a request or a cut certificate after them, stray data, '0' text, a request or a SEQUENCE that is not a certificate before a certificate, PEM after DER and a certificate wolfSSL refuses, the certificates a server receives for a chain, a chain with a v1 certificate or a key after it and a cut intermediate, and reenroll with a chain as current_cert. test_csr renews from a DER chain, and cli_proto_scoping runs EST reenroll with a PEM and a DER chain as --cert, with a PEM file whose first line starts with '0', and refuses a DER leaf with a PEM certificate after it. Its chain cases only show the bytes are accepted, since the server already trusts the appended CA; test_est_chain_roundtrip carries the coverage that a chain is sent and needed. Fixes F-18187.
8f93bab to
99634fe
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #74
Scan targets checked: wolfcert-src, wolfcert-bugs
Not reviewed (no scan target covers them): Makefile.am, docs/ARCHITECTURE.md, src/csr.c, src/http.c, src/internal.c, src/internal.h, src/keygen.c, tests/CMakeLists.txt, tests/integration/cli_proto_scoping.sh
Coverage: 1 of 6 in-scope changed file(s) opened by the reviewer; not opened: tests/integration/test_est_chain_roundtrip.c, tests/unit/test_csr.c, tests/unit/test_parse_negative.c, wolfcert/http.h, wolfcert/types.h
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Max

A device certificate issued by an intermediate, such as an 802.1AR IDevID, could not authenticate to a server that trusts only the root: wolfCert sent only the leaf. A concatenated-DER trust anchor bundle also loaded only its first certificate. Both now load every certificate.
Changes
client_cert(and EST reenroll'scurrent_cert) is sent as leaf plus intermediates, PEM or concatenated DER, up to wolfSSL'sMAX_CHAIN_DEPTH.trust_anchorsload certificate by certificate, skipping ones wolfSSL refuses, as the PEM loader does.wolfcert_key_from_id()read only the leaf of a DER chain.wolfcert-client reenrollpasses the whole--certfile for EST, so the chain is sent.types.h,http.hand ARCHITECTURE.md describe the chain and DER layout.Testing
test_est_chain_roundtrip: PEM and DER chains against a root-only client CA, what the server receives, data around the chain, DER anchor bundles, reenroll.test_parse_negativetables forwolfcert_der_nextandwolfcert_der_is_cert;test_csrrenews from a DER chain;cli_proto_scopingruns EST reenroll with PEM and DER chains.Merge note
Carries a copy of
wolfcert_der_first_lenfrom #72, which drops out on rebase; conflicts with #75 insetup_tls_ex. Thecurrent_certheader docs follow after #72.Fixes F-16512, F-18187.