Repository navigation
Conversation
|
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical flaws allow unauthorized or failed-handshake updates to extend cached CA validity, bypass issuer expiry checks, and introduce a data race in shared CA state.
7 open issues
Check issuer dates after accepting a leaf date error · New Commit renewed CA dates only after stapled status checks succeed · New Read and update CA validity under the same lock · New Require issuer authorization before extending cached intermediate dates · New Skip accepted CA date errors during subsequent certificate walks · New Refresh duplicate CA dates when the renewal omits AKI · New Stop issuer walks at user-loaded trust anchors · New
What changed in this PR
This PR adds validity checks for cached chain CAs in TLS and certificate-manager verification, aiming to make verification consistent whether peers send their intermediates or omit them.
Changes:
- Store validity dates on cached chain signers and check them along the issuer path.
- Refresh cached dates when a verified CA renewal uses the same key.
- Add regression tests for expiration, callback overrides, renewal, and application-loaded trust anchors.
| File | Description |
|---|---|
wolfssl/wolfcrypt/asn.h |
Defines signer validity storage and shared helper declarations. |
wolfssl/internal.h |
Declares cached-CA date-check and update helpers. |
wolfcrypt/src/asn.c |
Stores and frees signer dates; exposes issuer lookup. |
tests/api/test_ssl_cert.h |
Registers the cached-CA validity test. |
tests/api/test_ssl_cert.c |
Tests cached expiration, renewal, and verification behavior. |
src/ssl_certman.c |
Checks cached issuer dates and updates stored validity. |
src/internal.c |
Integrates date checks and renewal updates into handshakes. |
Review effort: Balanced
ac540f9 to
6301a67
Compare
6301a67 to
6d36ea3
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11942
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_ssl_cert.h
Coverage: 6 of 7 in-scope changed file(s) opened by the reviewer; not opened: wolfssl/internal.h
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
a477ded to
6458b7f
Compare
|
ChainCADatesAwaitStatus() is now compiled only when Certificate Status Request v2 is enabled. Builds without that feature failed with -Werror because the function was unused. The three review threads are answered in 6458b7f. |
|
retest this please |
|
@claude review |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11942
Scan targets checked: none
Failed targets: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_ssl_cert.h
💬 2 finding(s) from an earlier review are still open and were not re-posted:
- Renewed chain CA dates are never stored when CSR2 multi is configured but not negotiated —
src/internal.c:21554 - Cached-CA date check is skipped when the leaf has an overridable error that isn't a date error —
src/internal.c:20934
Review tier: Lite
22cefa3 to
ec02eaf
Compare
philljj
left a comment
There was a problem hiding this comment.
seeing build errors:
multi-test:
unescaped error code operands (missing WC_NO_ERR_TRACE()):
src/ssl_certman.c:3092: if (dateErr == ASN_BEFORE_DATE_E)
src/ssl_certman.c:3094: else if (dateErr == ASN_AFTER_DATE_E)pic32 harmony:
In file included from /tmp/wolfssl-src-harmony-ef/wolfcrypt/src/asn.c:363:
/tmp/wolfssl-src-harmony-ef/wolfssl/internal.h:3017:38: error: unknown type name 'time_t'
3017 | time_t atTime,
| ^~~~~~
/tmp/wolfssl-src-harmony-ef/wolfssl/internal.h:207:1: note: 'time_t' is defined in header '<time.h>'; did you forget to '#include <time.h>'?etc
In file included from /home/runner/Arduino/libraries/wolfssl/src/src/ssl.c:428:0:
/home/runner/Arduino/libraries/wolfssl/src/src/ssl_certman.c:917:41: error: unknown type name 'ChainCADate'
int dateCheck, time_t atTime, const ChainCADate* caDates, int* caDateOut)ec02eaf to
2c5891a
Compare
|
@philljj The three build failures are fixed in 2c5891a. The branch is one commit, rebased onto 3fd873c.
A local |
|
Jenkins retest this please |
Frauschi
left a comment
There was a problem hiding this comment.
Two build breaks and a few gaps in the X509 store path, details inline.
b6bbcf0 to
5860f0a
Compare
|
Rebased onto 82e1f1a. The conflict was in src/x509_str.c. The chain-CA date checks are unchanged. The verify callback, including the second call for a cached CA date error, now goes through X509StoreCallVerifyCb(). test_wolfSSL_chain_ca_cached_dates passes with --enable-opensslextra --enable-crl --enable-certgen --enable-certext and -Werror. The previous commit's checks were green. This commit had no jobs because the branch conflicted with master. |
|
retest this please |
1 similar comment
|
retest this please |
A CA cached from a peer chain is checked again each time it verifies a certificate. wolfSSL_X509_verify_cert() reports an expired cached CA on the certificate that CA issued. A CA supplied by the chain builder stops that walk. The X509 link files the supplied CA under GetHashId() of its subject key id, the same hash the signer table uses. An SM2/SM3 build pads a shorter key id, so a raw-length compare skipped the link and reported the expired CA on the leaf.
29f30d1 to
863593e
Compare
|
The all-sm failure is fixed. The link now uses |
There was a problem hiding this comment.
🟡 Changes recommended
A same-key CA renewal can persist new validity dates with the cached signer’s old name constraints, allowing later leaf-only connections outside the renewed constraints after the original certificate expires. Independently, verification stops after the first expired cached intermediate, so a callback that permits only one expiry can accept a chain containing another expired intermediate without being asked to approve it.
4 open issues
7 resolved since last review
Require issuer authorization before extending cached intermediate dates Read and update CA validity under the same lock Commit renewed CA dates only after stapled status checks succeed Check issuer dates after accepting a leaf date error Stop issuer walks at user-loaded trust anchors Refresh duplicate CA dates when the renewal omits AKI Skip accepted CA date errors during subsequent certificate walks
Review effort: Balanced
| if (dateErr != 0) { | ||
| ret = dateErr; | ||
| break; |
| WOLFSSL_MSG("Updating dates of cached chain CA"); | ||
| XMEMCPY(signer->validity, validity, sizeof(*validity)); |
| const Signer* issuer = cert->ca; | ||
|
|
||
| if (cert->selfSigned || issuer == NULL || issuer->publicKey == NULL) | ||
| return 0; | ||
|
|
||
| if (wc_LockMutex(&cm->caLock) != 0) | ||
| return BAD_MUTEX_E; | ||
| signer = cm_find_signer_locked(cm, hash); | ||
| if (signer != NULL && signer != issuer && | ||
| signer->type == WOLFSSL_CHAIN_CA && signer->validity != NULL && | ||
| XMEMCMP(signer->validity, validity, sizeof(*validity)) != 0 && | ||
| cm_signer_key_is(signer, keyHash) && |
| /* subjKeyId is the raw extension. The signer table files the CA under | ||
| * GetHashId() of that extension. An SM2/SM3 build keeps a larger key-id | ||
| * buffer and pads a shorter id, so the two lengths are not always equal. */ | ||
| if (issuer == NULL || !issuer->subjKeyIdSet || issuer->subjKeyId == NULL || | ||
| issuer->subjKeyIdSz == 0 || | ||
| issuer->pubKey.buffer == NULL || issuer->pubKey.length <= 0) | ||
| return 0; | ||
| XMEMSET(link, 0, sizeof(*link)); | ||
| if (GetHashId(issuer->subjKeyId, (int)issuer->subjKeyIdSz, link->hash, | ||
| HashIdAlg((word32)issuer->sigOID)) != 0) | ||
| return 0; |


Description
After a handshake,
ProcessPeerCerts()adds each verified CA from the peer's chain to the certificate manager as aWOLFSSL_CHAIN_CA. The cachedSignerkept no validity dates. A later peer that sent only its leaf was then verified with the cached CA, and only the leaf's own dates were checked. The same chain was rejected withASN_AFTER_DATE_Ewhen the expired CA was sent, or when a new context was used, and accepted when the CA was omitted.This change makes the result independent of whether the CA is sent:
Signergains avaliditypointer that holds the DER encodednotBeforeandnotAfter. It is allocated only for aWOLFSSL_CHAIN_CA, so CAs the application loads cost one pointer each.wolfssl_local_CheckChainCADates()walks from the issuer of the leaf up to the trust anchor and checks the dates of every chain CA on the way. It runs once, for the leaf. A date error on a cached CA is reported asASN_BEFORE_DATE_EorASN_AFTER_DATE_Eat depth 0 and goes through the verify callback like any other date error. When the leaf has a date error too, the callback gets the leaf's error first, then the cached CA's error, so accepting one does not accept the other.wc_AsnSetSkipDateCheck()turns the walk off as it does the other date checks.WOLFSSL_USER_CA,WOLFSSL_USER_INTER), because that CA is the trust anchor of the path. Those CAs are not checked again, as before. A chain CA retyped withwolfSSL_CertManagerLoadCABufferType()follows its new type.wolfssl_local_FindSignerByAkidOrName(), with the same cycle guard andWOLFSSL_MAX_CHAIN_DEPTHlimit. WithIGNORE_NAME_CONSTRAINTSonly the direct issuer is checked. Certificate Status Request v2 pending signers are searched too.caLock, because another handshake can update them.AddCA()already has a signer under its subject key identifier. When the peer sends such a CA and it verifies, its dates are recorded for the handshake and the walk uses them. They are stored on the cached CA only when the peer is verified. With Certificate Status Request v2 multi-stapling,TLSX_CSR2_MergePendingCA()stores them after the stapled status is accepted, andTLSX_CSR2_ClearPendingCA()drops them. A failed chain drops them.wolfssl_local_IsChainCARenewal()accepts a renewal only when the cached CA is aWOLFSSL_CHAIN_CAwith the same public key and other dates, the new certificate has the same issuer, it is not self-signed, and it was not verified with the cached CA's own key. The cached CA is found by the hashAddCA()uses, so a renewal without an Authority Key Identifier is found too.wolfSSL_CertManagerVerifyBuffer()checks cached chain CAs the same way.wolfSSL_CertManagerLoadCABufferType()stores the dates of a CA loaded asWOLFSSL_CHAIN_CA, for example one saved through the CA cache callback.Notes for review:
sizeof(Signer)changes, so aPERSIST_CERT_CACHEfile saved before this change is rejected on restore, as with anySignerlayout change. A restored signer has no type or dates and is not checked, as today. Keep CA restrictions when restoring the persisted cert cache #11875 rebuilds each CA from its DER.WOLFSSLgains one pointer,chainCaDates. The list is freed at the end of the certificate message, at the end of the handshake and inwolfSSL_free().wolfssl_local_FindSignerByAkidOrName()with an identical hunk, so the two merge cleanly in either order.Testing
test_wolfSSL_chain_ca_cached_datesgenerates a CA that expires before its leaf and moves the clock withwc_SetTimeCb(). T1 is now and T2 is after the CA expires.One client context is reused across handshakes:
ASN_AFTER_DATE_E, as beforeASN_AFTER_DATE_EASN_AFTER_DATE_ENew client contexts:
ASN_AFTER_DATE_EASN_AFTER_DATE_EwolfSSL_CertManagerVerifyBuffer():WOLFSSL_CHAIN_CAat T1 and T2, and asWOLFSSL_USER_CAat T2ASN_AFTER_DATE_EWOLFSSL_CHAIN_CA, and a CA below it loaded asWOLFSSL_USER_CA: a leaf from the lower CA verifiesWithout the library change, the test fails at the leaf-alone T2 case (
0 != -151). With the first commit only, seven checks fail: the not-valid-yet leaf (TLS and certificate manager), the depth 1 waiver, the self-signed certificate, the renewal without an Authority Key Identifier (two checks) and the loaded CA below a chain CA.This revision is built with CMake and
-Werror -Wpedantic -Wshadow -Wdeclaration-after-statement, withWOLFSSL_ALL, with the default options, withWOLFSSL_ALLplusNO_ASN_TIME_CHECK, and withWOLFSSL_ALLplusIGNORE_KEY_EXTENSIONS. WithNO_SKID, the only errors are theGetCAByNameerrors that master also has. The full unit test passes withWOLFSSL_ALL. Thessl_cert,certman,ocspandssl_crl_ocspgroups pass with AddressSanitizer and UndefinedBehaviorSanitizer.leaksreports no leaks for the new test.The test does not cover the multi-stapling path with a failed status for a renewed CA, because that needs an OCSP responder for the chain CA.
Tested on macOS arm64 (Apple clang).
Checklist