Skip to content

Trusted cert cache and verify callbacks#353

Draft
bigbrett wants to merge 11 commits intowolfSSL:mainfrom
bigbrett:trusted-cert-cache
Draft

Trusted cert cache and verify callbacks#353
bigbrett wants to merge 11 commits intowolfSSL:mainfrom
bigbrett:trusted-cert-cache

Conversation

@bigbrett
Copy link
Copy Markdown
Contributor

@bigbrett bigbrett commented May 5, 2026

Introduces two new features:

  1. Adds a "Trusted cert cache" maintained by the server for each client that "remembers" certificates (intermediate and leaf) after they are verified as trusted in a cert chain verification operation (based on the SHA256 over the cert). Any time the cert is subsequently encountered in a chain verification operation, the public key verification is short-circuited, and the cert is automatically registered as trusted. This feature exists to enhance performance in scenarios where the same cert chain is expected to be encountered multiple times (think wolfBoot cert chain auth for a time-critical boot).
  2. Adds the ability for the user to inject a verify callback into the certificate manager for cert chain verification. This allows the chain verification to be further exteneded or overriden by the user (domain name/SAN validation, etc.). Note that callbacks will NOT be invoked on cached/trusted certs, as this short circuits the entire verification process for that cert.

Copilot AI review requested due to automatic review settings May 5, 2026 16:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wh_server_cert.c
Comment thread src/wh_server_cert.c Outdated
Comment thread wolfhsm/wh_server_cert_cache.h Outdated
Comment thread src/wh_server_cert.c
Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #353

Scan targets checked: wolfhsm-core-bugs, wolfhsm-src

Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread src/wh_server_cert.c Outdated
Comment thread src/wh_server_cert.c
Comment thread src/wh_server_cert.c
Comment thread src/wh_server_cert.c Outdated
Comment thread src/wh_server_cert.c
Comment thread src/wh_server_cert.c
Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #353

Scan targets checked: wolfhsm-core-bugs, wolfhsm-src

No new issues found in the changed files. ✅

bigbrett added 11 commits May 6, 2026 14:23
The trusted cert verify cache was designed against single-root verify;
the multi-root verify that landed on main has no single anchoring root
to bind cache entries to. This commit unifies the two so multi-root
callers can still benefit from the cache without introducing
false-positive verifies.

- _verifyChainAgainstCmStore now takes the array of trusted root IDs
  and dispatches between bound mode (numRoots == 1) and unbound mode
  (numRoots > 1).
- New wh_Server_CertVerifyCache_LookupAnyRoot OR's lookups across the
  supplied roots; multi-root callers use this so a hit means the cert
  was previously verified under a root they currently trust.
- Multi-root verifies do not insert into the cache. The anchoring root
  cannot be identified post-verify, and inserting under any
  non-anchoring root from the supplied set could be matched by a
  future single-root verify under that wrong root.
- Only CA certs are cached. Caching a leaf would let a future
  "leaf alone" verify falsely succeed via cache hit, because the cache
  hit short-circuits the wolfSSL signature check that would otherwise
  fail (the leaf's issuer is not in the cert manager for an isolated
  verify). CA caching is sound because the chain walk loads each
  verified CA into the cert manager before the next cert is processed.

Tests updated: the verify-callback tests previously expected zero
callback invocations on a cache-hit re-verify; with leaves no longer
cached they assert the count drops below the cold path but stays
above zero.
@bigbrett bigbrett force-pushed the trusted-cert-cache branch from fe5cdfe to 5d341c4 Compare May 8, 2026 16:08
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.

3 participants