Skip to content

Keep CA restrictions when restoring the persisted cert cache - #11875

Open
sameehj wants to merge 1 commit into
wolfSSL:masterfrom
sameehj:fix-persist-cert-cache-signer
Open

sameehj wants to merge 1 commit into
wolfSSL:masterfrom
sameehj:fix-persist-cert-cache-signer

Conversation

@sameehj

@sameehj sameehj commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

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 ParseCert and FillSigner. PERSIST_CERT_CACHE enables WOLFSSL_SIGNER_DER_CERT so 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 stores issuerKeyHash. 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.

FillSigner now passes cert->heap to AllocDer for the CA DER copy, so a static-memory build uses its pool.

WOLFSSL_CACHE_CERT_VERSION is now 3. A cache in an older layout returns CACHE_MATCH_ERROR.

Testing

Built with the default configure flags plus -DPERSIST_CERT_CACHE -DWOLFSSL_ALT_NAMES, with -Werror on ssl.c and tests/api/test_certman.c.

  • test_wolfSSL_CertManagerNameConstraint_cert_cache
  • test_wolfSSL_CertManagerPathLen_cert_cache
  • The name-constraint test also passed with NO_SKID and with WOLFSSL_SMALL_STACK.
  • A full --api run 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:

./autogen.sh
./configure --enable-savecert CPPFLAGS=-DWOLFSSL_ALT_NAMES
make tests/unit.test
./tests/unit.test -test_wolfSSL_CertManagerNameConstraint_cert_cache
./tests/unit.test -test_wolfSSL_CertManagerPathLen_cert_cache

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 (origin is the wolfSSL/wolfssl remote):

base=$(git merge-base HEAD origin/master)
git checkout "$base" -- src/ssl_certman.c wolfcrypt/src/asn.c wolfssl/wolfcrypt/settings.h
make tests/unit.test
./tests/unit.test -test_wolfSSL_CertManagerNameConstraint_cert_cache
git checkout HEAD -- src/ssl_certman.c wolfcrypt/src/asn.c wolfssl/wolfcrypt/settings.h

The test reports Failed/Skipped/Passed/All: 1/0/0/1 with:

ERROR - tests/api/test_certman.c line 4771 failed with:
    expected: wolfSSL_CertManagerVerify(cm, attacker_leaf_chain, WOLFSSL_FILETYPE_PEM) == (ASN_NAME_INVALID_E)
    result:   1 != -198

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

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

Copilot AI balanced review requested due to automatic review settings October 23, 2026 15:06
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +320 B (+0.0%, 807,656 B / 1,048,576 B, total: 77% used)

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +108 B, text +13,904 B (+5.0%, 296,484 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@sameehj
sameehj force-pushed the fix-persist-cert-cache-signer branch from 90590a6 to d3e3582 Compare October 23, 2026 15:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread src/ssl_certman.c Resolved
Comment thread src/ssl_certman.c Resolved
Comment thread wolfssl/wolfcrypt/settings.h Resolved
@sameehj

sameehj commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

retest this please

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread wolfcrypt/src/asn.c Resolved
Comment thread src/ssl_certman.c Resolved
Comment thread src/ssl_certman.c Resolved
@JacobBarthelmeh

Copy link
Copy Markdown
Contributor

@sameehj can you investigate into the PRB-master-job failure and recent Fenrir bot comments?

@sameehj
sameehj force-pushed the fix-persist-cert-cache-signer branch from 8ec958d to 58b2aa9 Compare November 17, 2026 10:44
@sameehj

sameehj commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@JacobBarthelmeh Thanks. I fixed the three Fenrir findings, added a regression test, and replied on each thread:

  • The pending CA is now decoded with the certificate manager heap. FillSigner() moves buffers of the decoded cert into a signer that the manager keeps after the connection is freed.
  • The cache header row counts are now bounded by the buffer size, so their sum cannot overflow. The new test_wolfSSL_CertManager_cert_cache_bad_count fails without the bound.
  • cm_restore_signer() now sets the 32-bit unknown extension callback, as AddCA() does.

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.

@sameehj
sameehj force-pushed the fix-persist-cert-cache-signer branch from 58b2aa9 to fbda238 Compare November 19, 2026 16:55
@sameehj

sameehj commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current master. The review threads are answered. The failed check 1.31.1.1 stopped on a timeout while downloading from openresty.org. I started a re-run of that job.

@sameehj sameehj assigned wolfSSL-Bot and unassigned sameehj Nov 23, 2026
@sameehj

sameehj commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@JacobBarthelmeh Ready for a review

MarkAtwood
MarkAtwood previously approved these changes Nov 23, 2026

@MarkAtwood MarkAtwood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approve, with one ask: this needs a changelog entry before it merges.

all six earlier findings check out. the branch was force pushed so the reply commits arent in the tree any more, and i verified against the code as it now stands rather than against the replies.

copilot:

  • inherited restrictions lost when the post pass cant find the issuer: fixed. an effective path length is serialized per entry (1619-1628) and applied as a hard ceiling in cm_restore_clamp_pathlen (2092-2107).
  • issuerKeyHash left zero for non self issued signers under HAVE_OCSP: fixed. serialized in the entry prefix (1301-1310), restored unconditionally (1557-1567), re-derived from the restored issuer when present (2110-2131). the unconditional overwrite is the right call, ParseCert would otherwise leave a hash derived from the old live table and that gets correctly discarded.
  • FillSigner passing NULL heap and breaking static memory pools: fixed at asn.c:27075, now cert->heap, so AllocDer and FreeDer agree, and all three call sites supply a heap outliving the cert manager.

fenrir:

  • use after free on the static memory heap hint: fixed, also by asn.c:27075. note the src/internal.c diff in this pr is comment only, SSL_CM(ssl)->heap at 17939 was already in the base, so asn.c is what actually fixes it.
  • int overflow in summed row counts: fixed, 2196-2209 bounds each column by maxSigners minus the running count, derived from the real remaining buffer.
  • missing unknownExtCallback32: fixed, 1445-1450 sets both callbacks in AddCAs order.

the property i wanted established

final maxPathLen is min(recomputed, saved) per signer, and the recompute only ever lowers since next is capped at refs[i].base (2070). so restore can never come back looser than save. that holds in both configs copilot named, including IGNORE_NAME_CONSTRAINTS with ocsp/crl/akid off, where cm_table_find_issuer always returns NULL, the recompute is skipped, and the clamp alone holds the saved value.

the load bearing detail is the clamps indexing, since saved[i] is indexed by table order while savedPath is filled in buffer order. they agree because AddCA buckets at HashSigner(subjectKeyIdHash) (3865) and restore recomputes the same hash from the same der and appends to the tail (1570), so source row i lands in bucket i in read order, and the savedPath write and the table append are 1:1 inside one ret == 0 chain (1554-1583). if that ordering were off the clamp would put the wrong ceiling on the wrong signer. it isnt off.

full signer round trip: 22 fields reproduced cleanly from the serialized der via ParseCert + FillSigner. maxPathLen and issuerKeyHash arent der derivable and are now explicitly serialized. type being saved as one byte is an improvement, the baseline lost it and restored 0 which isnt a valid enum value. selfSigned isnt a plain der field but is reproduced, since ConfirmSelfSignature does run under NO_VERIFY (asn.c:26980-26991, gated only on verify != VERIFY_NAME).

also checked and clean: an old cache is rejected rather than misread, the header layout is byte identical so the version field sits at the same offset both directions (2172-2179) and signerSz additionally discriminates HAVE_OCSP and NO_SKID. bounds on the untrusted restore buffer are clean and better than the baseline, both length reads checked against the remaining buffer before use (1525, 1545) with no pointer arithmetic past the object, unlike the baselines start + minSz + pubKeySize > end. the issuer missing fallback fails closed. and partial restore is the best part of the change, a private table swapped in only on full success under caLock (2258), memset before cleanup so nothing double frees, which is also why GetCA taking caLock itself doesnt deadlock.

the ask

src/ssl_certman.c:1260 bumps the cache format from 1 to 3 and the ChangeLog.md diff is empty. two things users will hit:

  • an upgraded deployment calling RestoreCertCache on an existing v1 file gets CACHE_MATCH_ERROR and has to regenerate every cache
  • PERSIST_CERT_CACHE now force defines WOLFSSL_SIGNER_DER_CERT, so per ca ram grows by the full der

one line covering the format bump and the memory change is enough, and thats the only thing im holding this for.

happy as separate issues, not blocking

  • src/ssl_certman.c:1569-1583 vs 3880: AddCA sets signer->cm_idx = row but restore never does, so every restored signer has cm_idx 0. on renesas tsip/fspsm Renesas_cmn_checkCA is return (cmIdx == g_CAscm_Idx), so if g_CAscm_Idx is 0 every restored ca claims to be the tsip verified root (asn.c:26797), otherwise tsip is just unavailable. pre existing, the baseline restore didnt set it either. one line at the append site.
  • src/ssl_certman.c:1561: savedPath[*savedCount] has no explicit bound and is safe only by an invariant computed two functions away. not reachable today, but any future change to signerCount turns it into a heap write. pass signerCount in and gate on it.
  • src/ssl_certman.c:1362-1375: cm_get_cert_cache_mem_size accumulates in int with no overflow check, and per signer bytes went from about 100 to the full der, so the existing open fenrir finding on this is roughly 20x more reachable. still about 1M cas to trigger. accumulate in size_t and fail past INT_MAX, or call that one explicitly out of scope here.

tests

all three added tests genuinely fail if the fix is reverted, which is the question i actually cared about:

  • NameConstraint_cert_cache: the baseline format never serialized permittedNames/excludedNames, so the attacker leaf would verify instead of returning ASN_NAME_INVALID_E.
  • PathLen_cert_cache: its first restore, all 4 cas, is satisfied by the recompute alone and doesnt test the clamp. the second restore with ica4 removed does: ica3 has no pathLength extension so its seeded at WOLFSSL_MAX_PATH_LEN, apply_pathlen skips it because its issuer is absent, ica2 then computes MAX-1, and only cm_restore_clamp_pathlen pulls ica3 to its saved 1 and ica2 to its saved 0 to produce the asserted ASN_PATHLEN_INV_E.
  • cert_cache_bad_count: the unguarded sum wraps to exactly 0, savedPath is never allocated and 1557 returns MEMORY_E, not the asserted BUFFER_E. so the missing bound doesnt actually cause a heap overflow, the savedPath == NULL guard catches it, but the test still discriminates.

fc0fa58b61 was the right fix and is load bearing: the test now calls wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_DEFAULT, NULL) on every context before loading, and without it the ica1 load succeeds and both negative assertions are vacuous.

oracles are independent, fixed error codes and rfc 5280 semantics, and the ocsp hash assertions compare against values captured from the live table before the save, so the reference path rather than self validation.

one coverage gap, not a defect: nothing tests IGNORE_NAME_CONSTRAINTS with ocsp, crl and akid all off, because the tests own guard excludes that build. the clamp makes it safe by construction there anyway.

to be straight about the evidence: the "fails without the fix" conclusions above are traced from source, nobody re-ran the suite with the clamp removed. your green ci is the evidence for the passing direction.

@sameehj

sameehj commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@mark-atwood The changelog line is in 42e5745. The branch is one commit, rebased onto 3fd873c.

PERSIST_CERT_CACHE stores each CA's DER and rebuilds the signer on restore, and it defines WOLFSSL_SIGNER_DER_CERT, so each CA keeps that DER in memory. WOLFSSL_CACHE_CERT_VERSION is 3. Restoring a version 1 file returns CACHE_MATCH_ERROR. Saved caches need to be regenerated.

MarkAtwood
MarkAtwood previously approved these changes Nov 24, 2026

@MarkAtwood MarkAtwood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-approve. code and tests are byte identical to fbda238, which i already approved, and the only new file is the changelog i asked for.

it covers the version 3 bump, CACHE_MATCH_ERROR on a version 1 restore, the per-CA DER now kept in memory, and regenerating saved caches.

make check (2) is cancelled, not failed, 45m16s with no failure logs, same cap as #11972. the other 445 passed on the rebased base.

@sameehj

sameehj commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current master (833186a).

The content conflict was in tests/api/test_certman.c and tests/api/test_certman.h. The branch keeps the new master name-constraint tests and the persisted-cache tests. src/internal.c, src/ssl_certman.c, and wolfcrypt/src/asn.c already contained both changes.

The name-constraint cache test, the path-length cache test, the bad row-count test, and the new master chain-CA name-constraint tests pass locally with --enable-savecert and WOLFSSL_ALT_NAMES.

@sameehj

sameehj commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

retest this please

MarkAtwood
MarkAtwood previously approved these changes Nov 30, 2026
@sameehj sameehj removed their assignment Dec 1, 2026
@philljj
philljj requested a review from Frauschi December 1, 2026 15:22
@philljj philljj self-assigned this Dec 2, 2026
@philljj

philljj commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Additional findings (outside the current diff — GitHub can't attach inline comments there):

  • 🟡 src/ssl_certman.c — If one cached CA fails to re-parse, the whole cache restore fails and the CA table stays as it was. This can happen when the unknown-extension callback is not registered before restore. cm_restore_signer() runs ParseCert with whatever callbacks are registered at restore time. A CA that was accepted at save time only because a callback handled its critical custom extension now fails with ASN_CRIT_EXT_E. Fix: document that the callbacks must be set before restoring the cache, or record the acceptance at save time. Another option is to skip the one entry that fails instead of aborting the restore.

    Why this was flagged

    The condition is an application that loads CAs with a critical private extension, accepted through wolfSSL_CertManagerSetUnknownExtCallback (ssl_certman.c:751), and later calls wolfSSL_CTX_restore_cert_cache before registering that callback on the new context. cm_restore_signer (ssl_certman.c:151-161) copies cm->unknownExtCallback only if it is set, then calls ParseCert(cert, CA_TYPE, NO_VERIFY, cm). That call returns the critical-extension error for that CA. cm_restore_cert_row returns the error and CM_MemRestoreCertCache aborts, so none of the cached CAs are restored. On the base branch, restore copied the stored key and name fields directly. It never re-parsed the certificate, so the same cache restored without the callback. Nothing in the API or the ChangeLog entry says the callbacks must be registered before restore.

    Verification: cm_restore_signer (src/ssl_certman.c ~1443-1452) attaches the unknown-ext callbacks only if non-NULL, then calls ParseCert. ParseCertRelative ends with if (cert->criticalExt != 0) return cert->criticalExt; (asn.c ~27302). CM_MemRestoreCertCache (ssl_certman.c ~2223-2229) breaks on added < 0, so the whole restore fails. On the base branch, restore never parsed.

  • 🟣 src/ssl_certman.c — After a cache restore, mutually cross-certified CAs can end up with path length 0, so valid chains through them fail with ASN_PATHLEN_INV_E. The fixed-point loop in cm_restore_apply_pathlen() repeats count times. When two non-self-issued CAs name each other as issuer, every pass lowers both values, which can drive them to 0. Fix: compute each CA's inherited limit once in issuer-first order, as ParseCert did at load time, and stop at a cycle. Alternatively, never lower a signer below the value it had when the cache was saved.

    Why this was flagged

    The trigger is a CA table holding two non-self-issued CAs, X issued by Y and Y issued by X, matched by AKID/SKID or by name in cm_table_find_issuer(). This can happen with bridge-style cross-certificates when the self-signed roots with the same SKIDs are not in the table. At load time ParseCert saw only the issuer already present, so the saved values were X=127 and Y=126. On restore, each pass of the for (guard = 0; guard < count; guard++) loop (ssl_certman.c:606-644) sets X = Y-1, then Y = X-1. Both drop by about 2 per pass and are clamped at 0 once the cache holds about 64 or more CAs. cm_restore_clamp_pathlen() only lowers values, so it cannot undo this. An intermediate issued by X or Y then hits cert->ca->maxPathLen == 0 in ParseCert (asn.c:26965) and is rejected with ASN_PATHLEN_INV_E. Before this change, the restore did not recompute inherited path lengths and loaded each saved CA without this loop.

    Verification: pre-existing. Trigger: the restored CA table holds a cycle of non-self-issued CAs that resolve to each other as issuers through cm_table_find_issuer(), for example mutual cross-certificates loaded without the matching self-signed roots.

    How it happens: cm_restore_apply_pathlen() (src/ssl_certman.c:2002-2087; the candidate's line 644 is wrong) first sets refs[i].base to each signer's own pathLength. It then runs for (guard = 0; guard < count; guard++). Each pass sets s->maxPathLen to min(issuer->maxPathLen - 1, base), or to 0 when the issuer's value is 0 (lines 2065-2072).

Comment thread src/ssl_certman.c Resolved
@philljj
philljj requested a review from julek-wolfssl December 2, 2026 12:55
@philljj philljj assigned julek-wolfssl and unassigned philljj Dec 2, 2026

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main point is that the saved path length makes the restore-time inheritance pass unnecessary; the rest are small.

Comment thread src/ssl_certman.c Resolved
Comment thread src/ssl_certman.c Resolved
Comment thread src/ssl_certman.c Resolved
Comment thread src/ssl_certman.c Resolved
Comment thread wolfssl/wolfcrypt/settings.h Resolved
@sameehj

sameehj commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@Frauschi @julek-wolfssl The notes from Dec 2 are in c697171. Please review again.

Comment thread src/ssl_certman.c Resolved
@julek-wolfssl julek-wolfssl assigned sameehj and unassigned wolfSSL-Bot Dec 3, 2026
PERSIST_CERT_CACHE is now version 3. Restore rebuilds each signer from
its saved DER and defines WOLFSSL_SIGNER_DER_CERT. A build that also
defines WOLFSSL_NO_SIGNER_DER_CERT fails at compile time. Restore keeps
the path length that was in use. A CA that is not self-signed takes its
issuer key hash from the restored issuer when the authority key id can
be checked.
@sameehj
sameehj force-pushed the fix-persist-cert-cache-signer branch from c6302cb to 6019c0b Compare December 4, 2026 03:45
@sameehj

sameehj commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current master and squashed to one commit, 6019c0b.

ChangeLog.md conflicted with the new OCSP and CRL timeout entry. Both entries are kept. The persisted CA cache entry is unchanged, including the WOLFSSL_NO_SIGNER_DER_CERT compile error.

@sameehj
sameehj requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot December 4, 2026 08:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cache restoration can lose issuer links, rejecting valid chains or skipping ancestor name constraints, and the new test can write out of bounds for small CA tables.

3 open issues
3 resolved since last review

Review effort: Balanced

Comment thread src/ssl_certman.c
else {
cert->maxPathLen = (word16)WOLFSSL_MAX_PATH_LEN;
}
ret = FillSigner(signer, cert, type, der);
Comment thread src/ssl_certman.c
while (s != NULL) {
Signer* issuer;

if (!s->selfSigned) {
Comment thread tests/api/test_certman.c
int test_wolfSSL_CertManager_cert_cache_bad_count(void)
{
EXPECT_DECLS;
#if defined(PERSIST_CERT_CACHE) && !defined(NO_FILESYSTEM) && \

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #11875

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): ChangeLog.md, doc/dox_comments/header_files/ssl.h, tests/api/test_certman.h
Coverage: 2 of 4 in-scope changed file(s) opened by the reviewer; not opened: src/internal.c, tests/api/test_certman.c

Findings: 1
1 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: Lite

Comment thread src/ssl_certman.c
if (!s->selfSigned) {
issuer = cm_table_find_issuer(table, s);
if ((issuer != NULL) && (issuer != s)) {
XMEMCPY(s->issuerKeyHash, issuer->subjectKeyHash,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore overwrites a correct saved issuerKeyHash with the key hash of the first CA matching only by subject name · Certificate and trust chain validation bypass

For a CA with no AKID, cm_table_find_issuer falls back to cm_table_find_name, which returns the first CA with the same subject name. Its subjectKeyHash then replaces the correct saved issuerKeyHash. With two same-named CAs (key rollover), CheckOcspResponder trusts a delegated responder for the wrong issuer key.

Suggested fix: Overwrite the saved issuerKeyHash only when the issuer is matched by AKID/SKID; otherwise keep the saved value.

Related known findings (similar but distinct; listed for context, not part of this finding)

  • F-11701 (open): (1) File/function: same file, but the candidate is cm_restore_apply_issuer_key_hash in the cert-cache restore path, while F-11701 is GetCAByKeyHash, a lookup helper. (2) Operation: the candidate XMEMCPYs the subjectKeyHash of the first same-named CA over the saved issuerKeyHash. F-11701 returns a stale non-matching signer because ret is not reset before the fallback scan. (3) Root cause: the candidate's cause is a subject-name-only fallback in cm_table_find_issuer that replaces a correct saved val

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants