Repository navigation
Conversation
|
Contributor
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
sameehj
force-pushed
the
fix-chain-ca-expired-signer
branch
from
November 2, 2026 10:27
ac540f9 to
6301a67
Compare
After a handshake, ProcessPeerCerts() adds each verified CA from the peer's chain to the certificate manager as a WOLFSSL_CHAIN_CA. The Signer kept no validity dates, so a later peer that sent only its leaf was verified with the cached CA even after that CA had expired. Sending the expired CA, or using a new context, failed with ASN_AFTER_DATE_E. Keep the DER encoded notBefore and notAfter of a chain CA in its Signer, and after parsing each peer certificate walk from its issuer up to the self-signed trust anchor, checking the dates of every chain CA on the way. The error is reported as ASN_BEFORE_DATE_E or ASN_AFTER_DATE_E on that certificate, so a verify callback can accept it as before. CAs the application loaded are trust anchors and are not checked again. The walk uses the name constraints issuer lookup, exported as wolfssl_local_FindSignerByAkidOrName(). With IGNORE_NAME_CONSTRAINTS only the direct issuer is checked. A CA renewed with the same key is not added again, so the peer sending it now updates the dates of the cached CA. Otherwise the cached copy would fail a chain that includes a valid renewed CA. wolfSSL_CertManagerVerifyBuffer() checks cached chain CAs the same way, and wolfSSL_CertManagerLoadCABufferType() stores the dates of a CA loaded as WOLFSSL_CHAIN_CA. Add test_wolfSSL_chain_ca_cached_dates, which reuses one client context for a full chain, a leaf alone before and after the CA expires, a verify callback accepting the error and a renewed CA, and checks certificate manager verification.
Address the review of the cached chain CA date check. The walk over cached chain CAs now runs once, for the leaf, and not for each certificate as it is parsed. A date error on a cached CA is reported at depth 0, after the verify callback has seen the error of the leaf itself, so accepting a leaf date error does not hide an expired cached CA. wolfSSL_CertManagerVerifyBuffer() does the same. The walk reads the type and dates of each CA under caLock and stops at a CA that the application loaded (WOLFSSL_USER_CA or WOLFSSL_USER_INTER), as that CA is the trust anchor of the path. A CA in the peer's chain whose date error the verify callback accepted is recorded for the handshake, so the walk does not report that error again at depth 0. A renewed CA no longer changes the cached dates while the chain is processed. Its dates are recorded for the handshake, used by the walk, and stored on the cached CA only after the peer is verified. With Certificate Status Request v2 multi-stapling that is when the stapled status of the chain CAs is accepted, in TLSX_CSR2_MergePendingCA(), and a failed status drops them. A renewal is found by the subject key identifier, the same hash AddCA() uses, so a renewed CA without an Authority Key Identifier is found too. It must have the same key as the cached CA, be issued by the same issuer, not be self-signed and not be signed by the cached CA's own key. Extend test_wolfSSL_chain_ca_cached_dates for a leaf that is not yet valid, a CA date error accepted at depth 1, a self-signed certificate with the cached CA's name and key, a renewal without an Authority Key Identifier and a loaded CA below a cached chain CA.
sameehj
force-pushed
the
fix-chain-ca-expired-signer
branch
from
November 17, 2026 06:51
6301a67 to
6d36ea3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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