Skip to content

Report the failing certificate field through the verify callback (1/6) - #12319

Open
sameehj wants to merge 17 commits into
wolfSSL:masterfrom
sameehj:cert-verify-detail
Open

sameehj wants to merge 17 commits into
wolfSSL:masterfrom
sameehj:cert-verify-detail

Conversation

@sameehj

@sameehj sameehj commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Pull request Add certificate validation events (1/6: core) #11972 added a separate certificate-event callback. Review found that the same information belongs on the verify callback and the CRL error callback that applications already set. Pull request Revert "Add certificate validation events (1/6: core)" #12297 reverted Add certificate validation events (1/6: core) #11972 so the callback could be reworked.
  • The verify callback and the CRL error callback are unchanged. Returning ok only logs. Returning a non-zero value from the verify callback still accepts the certificate. One certificate error calls that callback once.
  • Returning 0 from the CRL callback keeps the CRL failure. Returning non-zero waives a signature, signer, or nextUpdate failure. A bad encoding and an unknown critical extension stay failures, because the signature check has yet to run. A waived CRL is stored unverified, so the signature is checked again at use.
  • The store context carries the field, the reason, the condition, the role, and the extension OID of the one error that stopped the certificate. The CRL carries the same detail while the CRL callback runs, including a CRL that fails while it is loaded. X509_verify_cert fills the caller's store with that detail.

Test plan

  • ./configure --enable-opensslextra --enable-crl CFLAGS="-Werror" and make
  • ./tests/unit.test -test_wolfSSL_CertVerifyDetail -test_wolfSSL_CrlVerifyDetail
  • ./tests/unit.test --group certman

Copilot AI balanced review requested due to automatic review settings November 30, 2026 12:47
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m0plus

  • FLASH: .text +1,352 B (+2.1%, 74,040 B / 262,144 B, total: 28% used)

gcc-arm-cortex-m3

  • FLASH: .text +1,980 B (+1.6%, 137,284 B / 262,144 B, total: 52% used)

gcc-arm-cortex-m4

  • FLASH: .text +1,856 B (+1.0%, 216,222 B / 262,144 B, total: 82% used)

gcc-arm-cortex-m4-baremetal

  • FLASH: .text +1,216 B (+1.9%, 76,724 B / 262,144 B, total: 29% used)

gcc-arm-cortex-m4-crypto-only

  • FLASH: .text +1,152 B (+0.7%, 186,299 B / 262,144 B, total: 71% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .rodata +200 B, .text +1,856 B (+1.0%, 203,628 B / 1,048,576 B, total: 19% used)

gcc-arm-cortex-m4-min-ecc

  • FLASH: .text +1,216 B (+2.0%, 71,190 B / 262,144 B, total: 27% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .rodata +200 B, .text +3,776 B (+0.5%, 811,312 B / 1,048,576 B, total: 77% used)

gcc-arm-cortex-m4-pkcs7

  • FLASH: .text +1,088 B (+0.6%, 228,540 B / 262,144 B, total: 87% used)

gcc-arm-cortex-m4-pq

  • FLASH: .rodata +192 B, .text +1,856 B (+0.6%, 322,208 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .rodata +200 B, .text +2,944 B (+0.9%, 353,056 B / 1,048,576 B, total: 34% used)

gcc-arm-cortex-m4-sp-math

  • FLASH: .text +1,216 B (+2.0%, 71,190 B / 262,144 B, total: 27% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +1,984 B (+1.6%, 138,004 B / 262,144 B, total: 53% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +1,984 B (+0.9%, 258,808 B / 262,144 B, total: 99% used)

gcc-arm-cortex-m7

  • FLASH: .text +1,856 B (+1.0%, 216,222 B / 262,144 B, total: 82% used)

gcc-arm-cortex-m7-pq

  • FLASH: .rodata +192 B, .text +1,920 B (+0.7%, 323,104 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .text +1,984 B (+0.9%, 258,808 B / 262,144 B, total: 99% used)

stm32-sim-stm32h753

  • FLASH: .text +3,112 B (+1.4%, 223,680 B / 2,097,152 B, total: 11% used)

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

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

Unresolved issues allow unauthenticated CRLs to bypass signature verification, introduce shared-state data races, and break error-tracing builds, alongside callback and error-detail defects.

12 open issues
What changed in this PR

Reworks certificate-failure reporting to use wolfSSL’s existing verify and CRL error callbacks instead of a separate certificate-event callback.

Changes:

  • Adds stable field, reason, condition, and role identifiers, plus public error-detail accessors.
  • Records certificate parsing failures and exposes details during verification and CRL-load callbacks.
  • Adds tests for malformed certificates, expiration, callback overrides, and CRL failures.
File Description
wolfssl/​wolfcrypt/​asn.h Adds decoded-certificate failure metadata and CRL signer tracking.
wolfssl/​wolfcrypt/​asn_public.h Defines public error-detail enums.
wolfssl/​ssl.h Adds store-context metadata and public detail accessors.
wolfssl/​openssl/​ssl.h Adds compatibility aliases for the new accessors.
wolfssl/​internal.h Adds CRL callback-detail storage.
wolfssl/​crl.h Extends internal CRL checks with missing-CRL reporting control.
wolfcrypt/​src/​asn.c Records certificate failure details and CRL signer presence.
tests/​api/​test_certman.h Registers the new detail tests.
tests/​api/​test_certman.c Tests certificate and CRL callback details.
src/​x509_str.c Implements store-context getters and adjusts CRL-stack scanning.
src/​ssl_certman.c Reports parser-recorded failures through the certificate-manager callback.
src/​internal.c Populates callback details and adds fatal-failure observation hooks.
src/​crl.c Classifies CRL failures, invokes load-error callbacks, and implements getters.

Review effort: Balanced

Comment thread src/crl.c Resolved
Comment thread src/crl.c Resolved
Comment thread wolfcrypt/src/asn.c Resolved
Comment thread src/crl.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/x509_str.c Resolved
Comment thread tests/api/test_certman.c Resolved
Comment thread wolfcrypt/src/asn.c Resolved
Comment thread wolfcrypt/src/asn.c Resolved
Comment thread wolfssl/ssl.h Resolved
sameehj added a commit to sameehj/wolfssl that referenced this pull request Nov 30, 2026
The leaf path called the verify callback and then called it again on the fatal exit. A CRL load waiver now keeps a CRL only when the signature check has run, and stores that CRL unverified. The caller's X509 store receives the failing field. Key usage, extended key usage, and CRL results are filled when the parser left them empty.

The verify callback and the CRL callback are unchanged. Returning ok only logs. Returning non-zero still accepts a certificate. Returning non-zero from the CRL callback still waives a signature, signer, or nextUpdate failure. This follows wolfSSL#12319, which replaced wolfSSL#11972 after the revert in wolfSSL#12297.
MarkAtwood
MarkAtwood previously approved these changes Nov 30, 2026
@MarkAtwood

Copy link
Copy Markdown
Contributor

the make check linux (2) red here is the test's guards, not the parsing change, and it is not a compile break. i built it both ways at f9d7c8a.

--enable-coding=no turns off NO_CODING, which leaves WOLFSSL_PEM_TO_DER undefined, so there is no pem decoder. test_wolfSSL_CertVerifyDetail then dies on its pem ca:

ERROR - tests/api/test_certman.c line 6107 failed with:
    expected: wolfSSL_CertManagerLoadCA(cm, caCert, ((void *)0)) == WOLFSSL_SUCCESS
    result:   -140 != 1

f9d7c8a fixed the pqc variant of this, the coding=no one is still open. the date case is also the only thing in there that needs a clock, so NO_ASN_TIME belongs on that block rather than on the whole test.

@@ -6001,7 +6001,7 @@ int test_certman_decision_coverage(void)
 #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
-    !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_ASN_TIME) && \
+    !defined(NO_WOLFSSL_CM_VERIFY) && \
     (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
@@ -6028,8 +6028,11 @@ static int verifyDetailCb(int ok, WOLFSSL_X509_STORE_CTX* ctx)
 #if !defined(WOLFSSL_APPLE_NATIVE_CERT_VALIDATION) && \
+    defined(WOLFSSL_PEM_TO_DER) && !defined(NO_ASN_TIME) && \
     (!defined(NO_RSA) || defined(HAVE_ECC))
 static time_t verifyDetailAfterExpiry(time_t* t)
@@ -6046,7 +6049,7 @@ int test_wolfSSL_CertVerifyDetail(void)
 #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
-    !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_ASN_TIME) && \
+    !defined(NO_WOLFSSL_CM_VERIFY) && \
     (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
@@ -6095,6 +6098,7 @@ int test_wolfSSL_CertVerifyDetail(void)
 #if !defined(WOLFSSL_APPLE_NATIVE_CERT_VALIDATION) && \
+    defined(WOLFSSL_PEM_TO_DER) && !defined(NO_ASN_TIME) && \
     (!defined(NO_RSA) || defined(HAVE_ECC))
     if (cm != NULL) {

the trap is that the outer condition appears twice, once at file scope over the verifyDetail struct and verifyDetailCb, once inside the function. i changed only the in-function copy the first time and got 'verifyDetail' undeclared. both copies have to stay identical.

this does not cost coverage in coding=no. the three der fixtures still run there, only the pem date case drops out, which the baseline run shows too since it got all the way to 6107 before failing.

built at f9d7c8a, make check each time:

config without the patch with it
--enable-coding=no FAIL: scripts/unit.test, exit 2, dies at 6107 PASS, exit 0, CertVerifyDetail : passed
CFLAGS=-DNO_ASN_TIME test compiled out entirely by the outer guard PASS, exit 0, CertVerifyDetail : passed

so NO_ASN_TIME gains the test rather than skipping it.

separately, certs/test/include.am never picked up the six new certs/test/cert-detail/*.der fixtures, and nothing else in the build system names them, so make dist ships a tarball those tests cannot run from. one EXTRA_DIST += block fixes it.

@sameehj sameehj changed the title Report the failing certificate field through the verify callback Report the failing certificate field through the verify callback (1/6) Dec 1, 2026
@sameehj

sameehj commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

The guard fix and the dist entry are in c318fce. Both copies of the outer guard match. The date case requires WOLFSSL_PEM_TO_DER and a certificate time check, so the DER cases still run when the clock is off. certs/test/include.am ships the fixtures with one directory entry, EXTRA_DIST += certs/test/cert-detail.

This pull request is 1/6. The store and trust-anchor part and the CRL part will follow as the next pull requests on this callback.

Pull request wolfSSL#11972 added a separate certificate-event callback. Review found that the same information belongs on the verify callback and the CRL error callback. Pull request wolfSSL#12297 reverted wolfSSL#11972.

The verify callback and the CRL error callback are unchanged. Returning ok only logs. Returning non-zero from the verify callback still accepts the certificate. One certificate error calls that callback once.

Returning 0 from the CRL callback keeps the CRL failure. Returning non-zero waives a signature, signer, or nextUpdate failure. A bad encoding and an unknown critical extension stay failures. A waived CRL is stored unverified.

The store and the CRL carry the field, the reason, the condition, the role, and the extension OID of the one error that stopped the check. That includes a key below the minimum size, an issuer the peer sent that is not a CA, a CA without keyCertSign, an empty Certificate message, a chain past the depth limit, and a negative pathLen integer.

The OpenWrt 21.02 test fetches its package indexes from the archive.

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

Critical defects can bypass TLS Finished verification, accept incompletely parsed CRLs, and expose another verification’s callback details when thread-local storage is unavailable.

10 open issues
12 resolved since last review

Review effort: Balanced

Comment thread src/crl.c Resolved
Comment thread src/crl.c Resolved
Comment thread src/tls13.c Resolved
Comment thread src/crl.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/x509_str.c Resolved
Comment thread src/x509_str.c Resolved
Comment thread tests/api/test_asn.c Resolved
Comment thread tests/api/test_certman.c Resolved
Report the certificate and CRL detail from the review without letting an empty Certificate or a waived nextUpdate change the old result.
The Apple native build no longer compiles the unused depth helper, and the OpenWrt 22.03 test reads its package indexes from the archive.
The verify callback still sees that error. Its return cannot accept the certificate or skip the alert.

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

In builds without real thread-local storage, uninitialized CRL error state can expose indeterminate metadata, while several verification paths omit or retain stale callback details.

3 open issues
4 previously missed issues

In code that hasn't changed since last review

Medium severity Issuer callback inherits leaf error detail

src/​x509_str.c:724

After a callback waives a leaf error, X509StoreVerifyIssuer() can notify the trusted issuer with ok=1 while the detail still describes the leaf's failure. That helper resets and restores error and error_depth, but not the new detail members. Save, clear, and restore the detail around issuer notifications so a successful callback cannot expose another certificate's condition or extension OID.

Medium severity Populate detail for path-length and invalid-CA failures

src/​x509_str.c:726

X509StoreCheckPathLen() reports PATH_LENGTH_EXCEEDED after successful per-certificate checks have cleared the new detail, so its callback and the returned store expose condition NONE. Populate CHAIN/CONSTRAINT/CERT_PATH_LEN and the signer role before reporting that failure, clearing unrelated extension data. The direct INVALID_CA callback at src/x509_str.c:1277–1280 also needs matching chain-failure detail.

Medium severity Capture OIDs for revoked-entry extensions

wolfcrypt/​src/​asn.c:40862

The OID is recorded only for CRL-level extensions. ParseCRL_EntryExtensions() also returns ASN_CRIT_EXT_E for an unknown critical revoked-entry extension, but never fills these members. For example, loading certs/crl/extra-crls/crl_critical_entry.pem with a CRL error callback reports CRL_EXT_UNKNOWN_CRITICAL while wolfSSL_CRL_get_error_ext_oid() returns NULL. Please retain the OID in the entry-extension parser too, so both rejection paths supply the advertised detail.

Medium severity Long-form OID headers are not decoded

wolfcrypt/​src/​asn_orig.c:9755

A valid OID with 128 or more content octets uses a long-form DER length and skips this assignment entirely. With the original ASN parser, the normalized ASN_PARSE_E is then reported as ENCODING/CRL_FORMAT, with no extension OID. Decode the OID header with GetASNObjectId() rather than assuming a two-byte header.

10 resolved since last review

Review effort: Balanced

Comment thread src/crl.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/x509_str.c Resolved

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

The new error-detail API can retain stale expiry information after successful context reuse or incorrectly attribute an expired leaf’s failure to a successful issuer callback. Path-length failures, signature failures under WOLFSSL_SMALL_CERT_VERIFY, and critical revoked-entry extensions also lack expected detail or OID information. CRL-loading callbacks that return nonzero additionally need regression coverage to verify that permitted waivers remain unverified and are rechecked at use, while malformed and unknown-critical-extension CRLs remain rejected with both ASN parsers.

7 open issues

Review effort: Balanced

Comment thread src/crl.c Resolved
Comment thread src/crl.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/x509_str.c Resolved
Comment thread src/x509_str.c Resolved
Comment thread src/x509_str.c Resolved
Comment thread doc/dox_comments/header_files/ssl.h Resolved
A revoked-entry extension keeps its OID, a waived CRL is checked again at use, and a reused store context does not keep the previous failure.
@sameehj
sameehj requested a balanced review from Copilot December 3, 2026 09:02
@sameehj

sameehj commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot review

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

With NO_ASN_TIME, the test still expects a not-yet-valid failure, but both date checks in X509StoreVerifyCert() are compiled out. No such failure reaches storeDetailCb, so the assertions at tests/api/test_certman.c:6721 compare zero-initialized fields against the expected validity error values and fail.

1 open issue
7 resolved since last review

Review effort: Balanced

Comment thread tests/api/test_certman.c Resolved

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.

🔵 Needs a closer look

Certificate-version and invalid-CA rejection paths may provide incomplete failure details or incorrect certificate roles to verification callbacks, requiring human review of those paths.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@sameehj
sameehj requested a balanced review from Copilot December 3, 2026 18:52
@sameehj sameehj assigned wolfSSL-Bot and unassigned sameehj Dec 3, 2026

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

Verification callbacks receive missing or misleading failure details: with ALLOW_V1_EXTENSIONS disabled, the template parser leaves version failures unidentified for v1/v2 certificates containing extensions; the non-CA issuer path can expose unset or stale details; and certificate and CRL checks with matching RSA-PSS OIDs but differing parameters report encoding/format errors instead of signature-algorithm mismatches.

4 open issues

Review effort: Balanced

Comment thread src/x509_str.c Resolved
Comment thread wolfcrypt/src/asn.c Resolved
Comment thread wolfcrypt/src/asn.c Resolved
Comment thread wolfcrypt/src/asn.c Resolved
@sameehj sameehj assigned sameehj and unassigned wolfSSL-Bot Dec 3, 2026
The callback was reading an empty or earlier result for that rejection.
Master calls VerifyCRLE with the old argument list. The extra pointer names a missing cRLSign bit, and this case does not use it.
@sameehj sameehj assigned wolfSSL-Bot and unassigned sameehj Dec 4, 2026
@sameehj
sameehj requested a balanced review from Copilot December 4, 2026 08:26

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.

🔵 Needs a closer look

CRL load waivers change trust decisions across TLS and X.509 verification. It remains unconfirmed whether waiver ordering, signature rechecks, and fatal-certificate callbacks preserve the intended rejection and waiver semantics across both ASN.1 parsers and supported feature configurations, including platforms without real thread-local storage. Maintainer review and configuration-matrix runtime validation are needed to resolve these security-sensitive uncertainties.

3 open issues
1 resolved since last review

Review effort: Balanced

A v1 or v2 certificate with extensions and a parameter mismatch were reaching the callback as an unnamed or generic format error. The error codes stay the same.

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.

🔵 Needs a closer look

Certificate-version failures detected during TLS processing may leave both error getters reporting NONE, so the error classification behavior needs human review.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

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.

5 participants