Repository navigation
Conversation
|
90590a6 to
d3e3582
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Restoration can still lose inherited restrictions and OCSP issuer metadata, while mandatory DER retention exposes a static-memory allocation failure.
3 open issues
What changed in this PR
This PR changes wolfSSL’s persistent CA cache to rebuild signers from certificate DER, aiming to preserve certificate restrictions across save and restore.
Changes:
- Introduces cache format version 2, storing DER and signer type and rejecting the old format.
- Rebuilds signers in a private table, reapplies inherited path limits, and replaces the live table only after successful restoration.
- Adds name-constraint and inherited path-length regression tests.
| File | Description |
|---|---|
wolfssl/wolfcrypt/settings.h |
Enables signer DER retention for persistent certificate caches. |
tests/api/test_certman.h |
Registers the two cache regression tests. |
tests/api/test_certman.c |
Tests name constraints and inherited path limits after restoration. |
src/ssl_certman.c |
Implements the new cache format and transactional signer reconstruction. |
Review effort: Balanced
60c7daf to
e46d64f
Compare
|
retest this please |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11875
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_certman.h
Coverage: 3 of 4 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_certman.c
Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Max
|
@sameehj can you investigate into the PRB-master-job failure and recent Fenrir bot comments? |
The PERSIST_CERT_CACHE save/restore of the CA table only stored the public key, key OID, common name and name hashes of each Signer. Everything else FillSigner takes from the certificate (key usage, extended key usage, path length, self-signed flag, name constraints, AKID, issuer and serial hashes, ...) came back zeroed after a restore, so a restored CA table did not behave like the one that was saved. Store the DER encoding and type of each CA instead and rebuild the Signer with ParseCert/FillSigner on restore, so new Signer fields are picked up without having to change the cache layout again. PERSIST_CERT_CACHE now enables WOLFSSL_SIGNER_DER_CERT so the CA table keeps the DER. The restored signers are built into a separate table and swapped in under the CA lock, so a failed restore leaves the existing CA table in place. Bump WOLFSSL_CACHE_CERT_VERSION to 2 so caches in the old layout are rejected with CACHE_MATCH_ERROR. Add a test that saves and restores a cache holding a name-constrained CA chain and checks a leaf outside the permitted subtree is still rejected.
Rebuilding each CA from its DER recovers the path length stored in that certificate. It does not recover the tighter limit ParseCert copies from the issuer, because restore parses each CA before the new table is installed. After every CA is rebuilt, apply that inherited limit from the restored table before swapping it in. Add a test that saves and restores the chainJ CA set and checks that a further CA under an issuer whose effective path length is 0 is still rejected.
A new context can load CAs with verification off. A path length of 0 is then stored and the load still succeeds, so the test accepted ICA1. Set the default verify mode before the load, which is what CertManagerLoadCA does, so that CA is rejected again.
Restore can raise a path length to the certificate's own limit when the issuer is not in the restored table. Store the path length in use and do not raise it above that value. Store the OCSP issuer key hash as well, and copy the issuer's subject key hash when that issuer is restored. Pass the certificate heap to the CA DER allocation so a context memory pool is used. Bump the cache version to 3 so an older layout is rejected. The path length test now drops the CA that carries the path length extension before a second save and checks the descendant is still rejected.
cm_restore_apply_pathlen() assigns the result of XMALLOC to a struct pointer. A C++ build rejects that conversion. Name the struct and cast the result. Initialize the restore fields so an -Og build does not treat them as uninitialized. The values are set before use when the row header is valid.
- Decode the pending CA with the certificate manager heap. FillSigner() moves buffers of the decoded cert into the signer, which the manager keeps after the connection is freed. - Bound each row count in the cache header by the buffer size, so the sum of the counts cannot overflow and undersize the saved path array. - Set the 32-bit unknown extension callback when a signer is restored, as AddCA() does. - Add test_wolfSSL_CertManager_cert_cache_bad_count.
8ec958d to
58b2aa9
Compare
|
@JacobBarthelmeh Thanks. I fixed the three Fenrir findings, added a regression test, and replied on each thread:
The last PRB-master-job run was skipped because the PR had merge conflicts. I rebased the PR on master, and the CI is running again. I do not have access to the Jenkins console, so I could not read the earlier failure. If the new run fails, I will look at it. |


Description
A CA table restored from the persisted cert cache did not match the table that was saved. The old cache stored only the public key, key OID, common name, and name hashes of each CA. Key usage, extended key usage, path length, the self-signed flag, name constraints, and the issuer link came back empty. The path length a CA inherits from its issuer was also lost, because that value is computed at load time and is not stored in the certificate.
The cache now stores each CA's DER and signer type and rebuilds the signer with
ParseCertandFillSigner.PERSIST_CERT_CACHEenablesWOLFSSL_SIGNER_DER_CERTso the CA table keeps the DER. The new signers are swapped in under the CA lock, so a failed restore leaves the current table in place.Each cache entry also stores the path length in use. After every CA is rebuilt, restore computes the inherited limit from the issuers in the new table and keeps the lower of that limit and the saved one. The limit cannot increase when the issuer is not in the cache. With
HAVE_OCSP, each entry also storesissuerKeyHash. A CA that is not self-issued takes the subject key hash of its issuer when that issuer is restored, and keeps the saved hash when it is not.FillSignernow passescert->heaptoAllocDerfor the CA DER copy, so a static-memory build uses its pool.WOLFSSL_CACHE_CERT_VERSIONis now 3. A cache in an older layout returnsCACHE_MATCH_ERROR.Testing
Built with the default configure flags plus
-DPERSIST_CERT_CACHE -DWOLFSSL_ALT_NAMES, with-Werroronssl.candtests/api/test_certman.c.test_wolfSSL_CertManagerNameConstraint_cert_cachetest_wolfSSL_CertManagerPathLen_cert_cacheNO_SKIDand withWOLFSSL_SMALL_STACK.--apirun of that build reported 0 failed and 636 passed. The remaining tests were skipped by that build.The path-length test fails if the inherited-limit pass is left out: after restore, the further CA is accepted.
How to reproduce
Build and run the new tests:
Both report
Failed/Skipped/Passed/All: 0/0/1/1.To see the bug, keep the new tests and put back the library files from master (
originis the wolfSSL/wolfssl remote):The test reports
Failed/Skipped/Passed/All: 1/0/0/1with:The restored CA has lost its name constraints, so a leaf outside the permitted names verifies. The path-length test passes on master too: master restores each CA as a zeroed signer, so that test checks the new layout and not the master bug.
Tested on macOS arm64 (Apple clang) at 60c7daf.
Checklist