Skip to content

Check CA ExtKeyUsage for issuers from the CertManager - #11873

Open
sameehj wants to merge 2 commits into
wolfSSL:masterfrom
sameehj:fix-ca-ext-key-usage-certmanager
Open

sameehj wants to merge 2 commits into
wolfSSL:masterfrom
sameehj:fix-ca-ext-key-usage-certmanager

Conversation

@sameehj

@sameehj sameehj commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

ProcessPeerCerts() checks the Extended Key Usage of CA certificates against the TLS purpose (serverAuth when verifying a server, clientAuth when verifying a client), but only for CAs the peer sends in its Certificate message. When the peer sends only its leaf and the issuing CA is already loaded in the CertManager, that CA's Extended Key Usage is not checked. The same chain is therefore rejected with EXTKEYUSE_AUTH_E when the intermediate is sent and accepted when it is omitted.

This change makes the result independent of which CAs the peer sends:

  • Signer gains an extExtKeyUsageSet bit, set by FillSigner(), so an absent extension can be told apart from one that grants none of the known purposes.
  • CheckSignerExtKeyUsage() walks from the leaf's issuer up to the self-signed trust anchor and applies the TLS purpose to every CA on the way. The trust anchor stays exempt, as in CheckChainCAExtKeyUsage(). The walk reuses the name constraints ancestor lookup, now exported as wolfssl_local_FindSignerByAkidOrName(), with the same cycle guard and WOLFSSL_MAX_CHAIN_DEPTH limit.
  • The check runs after the leaf's own key usage checks. A verify callback can override it as it can the other leaf errors. It is skipped when a chain verify callback is installed, when verification is disabled, and for a trusted peer certificate (WOLFSSL_TRUST_PEER_CERT), whose chain is not used.
  • With IGNORE_NAME_CONSTRAINTS the Signer has no issuer lookup data, so only the leaf's direct issuer is checked.
  • With Certificate Status Request v2 multi-stapling, the walk also looks up issuers in the pending signer list from TLSX_CSR2_GetPendingSigners(), the same list ProcessPeerCertParse() uses. A pending issuer does not stop the walk before a cached ancestor.
  • When the verify callback accepts EXTKEYUSE_AUTH_E for a CA that the peer sent, the handshake records that chain index in a mask in ProcPeerCertArgs. The walk skips that CA and still checks the ancestors that the peer did not send. The shared Signer is not changed.

This change does not change the persisted cert cache. #11875 rebuilds each CA from its DER, so a restored CA keeps its Extended Key Usage. Merge this change after #11875.

Testing

test_wolfSSL_chain_ca_ext_key_usage gains a leafOnly option, where the peer sends only the leaf and the CAs are loaded into the verifier. New cases:

  • depth 1: codeSigning and clientAuth CA rejected, and serverAuth, no extension and anyExtendedKeyUsage accepted, when verifying a server
  • depth 1: codeSigning and serverAuth CA rejected, and clientAuth and no extension accepted, when verifying a client
  • depth 2, with the restricted CA above an unrestricted one and neither sent, for server and client authentication
  • a verify callback overriding the result for a leaf-only chain, and one that accepts only EXTKEYUSE_AUTH_E, showing that the callback is given that error
  • a self-signed codeSigning trust anchor with a leaf-only chain, which stays accepted
  • a verify callback that accepts the purpose error only at depth 1: the handshake succeeds, and the same callback still rejects a codeSigning CA that the peer did not send

Built and run with the default configure flags plus cert generation, and with each of OPENSSL_EXTRA, OPENSSL_EXTRA + WOLFSSL_CHAIN_VERIFY_CB, IGNORE_NAME_CONSTRAINTS, WOLFSSL_ASN_ORIGINAL, WOLFSSL_ALT_CERT_CHAINS with CRL/OCSP and status request, WOLFSSL_TRUST_PEER_CERT, and NO_SKID. A trusted peer leaf whose issuer name matches a restricted CA in the CertManager still connects with the example client (-E). The new cases fail without the library change. The full --api suite passes in the default and OPENSSL_EXTRA builds.

NO_SKID note: the existing self-issued rollover cases in this test already fail on master with NO_SKID (ASN_SIG_CONFIRM_E); this change does not affect them.

How to reproduce

Build and run the test:

./autogen.sh
./configure --enable-certgen --enable-certext
make tests/unit.test
./tests/unit.test -test_wolfSSL_chain_ca_ext_key_usage

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

To see the bug, keep the new test cases 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/internal.c wolfcrypt/src/asn.c wolfssl/internal.h wolfssl/wolfcrypt/asn.h
make tests/unit.test
./tests/unit.test -test_wolfSSL_chain_ca_ext_key_usage
git checkout HEAD -- src/internal.c wolfcrypt/src/asn.c wolfssl/internal.h wolfssl/wolfcrypt/asn.h

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

ERROR - tests/api/test_ssl_cert.c line 2919 failed with:
    expected: hsRet == tc->expectRet
    result:   0 != -386

The leaf-only handshake with a restricted CA in the CertManager succeeds, but the test expects EXTKEYUSE_AUTH_E (-386).

Tested on macOS arm64 (Apple clang) at 390159a.

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 10:37
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m0plus

  • FLASH: .text -136 B (-0.2%, 72,408 B / 262,144 B, total: 28% used)

gcc-arm-cortex-m3

  • FLASH: .text +1,588 B (+1.2%, 135,822 B / 262,144 B, total: 52% used)

gcc-arm-cortex-m4

  • FLASH: .rodata.CSWTCH.2 +8 B, .rodata.str1.1 +99 B, .text +3,200 B (+1.6%, 214,872 B / 262,144 B, total: 82% used)

gcc-arm-cortex-m4-baremetal

  • FLASH: .text -64 B (-0.1%, 75,252 B / 262,144 B, total: 29% used)

gcc-arm-cortex-m4-crypto-only

  • FLASH: .rodata.CSWTCH.2 +8 B, .rodata.str1.1 +99 B, .text +640 B (+0.4%, 184,891 B / 262,144 B, total: 71% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +2,752 B (+1.4%, 202,276 B / 1,048,576 B, total: 19% used)

gcc-arm-cortex-m4-min-ecc

  • FLASH: .text -64 B (-0.1%, 69,654 B / 262,144 B, total: 27% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .rodata +160 B, .text +3,776 B (+0.5%, 808,104 B / 1,048,576 B, total: 77% used)
  • RAM: .data +4 B (+0.0%, 121,764 B / 262,144 B, total: 46% used)

gcc-arm-cortex-m4-pkcs7

  • FLASH: .rodata.CSWTCH.2 +8 B, .rodata.str1.1 +99 B, .text +1,088 B (+0.5%, 227,196 B / 262,144 B, total: 87% used)

gcc-arm-cortex-m4-pq

  • FLASH: .rodata +112 B, .text +2,368 B (+0.8%, 320,864 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .rodata +112 B, .text +1,728 B (+0.5%, 350,616 B / 1,048,576 B, total: 33% used)

gcc-arm-cortex-m4-sp-math

  • FLASH: .text -64 B (-0.1%, 69,654 B / 262,144 B, total: 27% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +1,600 B (+1.2%, 136,590 B / 262,144 B, total: 52% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .rodata.CSWTCH.2 +8 B, .rodata.str1.1 +99 B, .text +2,496 B (+1.0%, 257,330 B / 262,144 B, total: 98% used)

gcc-arm-cortex-m7

  • FLASH: .rodata.CSWTCH.2 +8 B, .rodata.str1.1 +99 B, .text +3,136 B (+1.5%, 214,872 B / 262,144 B, total: 82% used)

gcc-arm-cortex-m7-pq

  • FLASH: .rodata +112 B, .text +2,432 B (+0.8%, 321,760 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .rodata.CSWTCH.2 +8 B, .rodata.str1.1 +99 B, .text +2,496 B (+1.0%, 257,330 B / 262,144 B, total: 98% used)

stm32-sim-stm32h753

  • FLASH: .text +10,348 B (+4.9%, 220,440 B / 2,097,152 B, total: 11% used)

zephyr-frdm_rw612

  • FLASH: text -104 B (-0.0%, 296,364 B / 67,108,864 B, total: 0% 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

Pending signers and restored caches can bypass issuer EKU checks, and repeated checks can invalidate certificate-specific callback overrides.

3 open issues
What changed in this PR

This PR extends TLS issuer Extended Key Usage checks to CAs loaded in the CertManager, aiming to make validation independent of which intermediates the peer sends.

Changes:

  • Records EKU extension presence on cached signers.
  • Walks issuer ancestors to enforce the TLS purpose while exempting self-signed trust anchors.
  • Adds leaf-only chain tests for server/client authentication, callback overrides and trust-anchor handling.
File Description
wolfssl/​wolfcrypt/​asn.h Adds signer EKU presence state and declares the shared issuer lookup.
wolfcrypt/​src/​asn.c Populates the new state and exposes the existing ancestor lookup.
tests/​api/​test_ssl_cert.c Extends the handshake harness and adds cached-issuer test cases.
src/​internal.c Adds issuer-chain EKU validation during peer certificate processing.

Review effort: Balanced

Comment thread src/internal.c Resolved
Comment thread wolfssl/wolfcrypt/asn.h Resolved
Comment thread src/internal.c Resolved
@sameehj

sameehj commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

retest this please

1 similar comment
@sameehj

sameehj commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

retest this please

@sameehj
sameehj force-pushed the fix-ca-ext-key-usage-certmanager branch from a1cb314 to e3b30a9 Compare November 17, 2026 06:16
@sameehj sameehj assigned wolfSSL-Bot and unassigned sameehj Nov 17, 2026
@sameehj
sameehj force-pushed the fix-ca-ext-key-usage-certmanager branch from e3b30a9 to b8b3171 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 checks passed.

@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 #11873

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 5 of 5 in-scope changed file(s) opened by the reviewer

Findings: 5
5 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 src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread wolfssl/internal.h Resolved
@sameehj
sameehj force-pushed the fix-ca-ext-key-usage-certmanager branch 2 times, most recently from 9d1f092 to 5e3af6e Compare November 24, 2026 09:40
@sameehj

sameehj commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

The tiny TLS compile failure is fixed in 5e3af6e. The branch is one commit, rebased onto 3fd873c.

struct EkuWaivedCa used SIGNER_DIGEST_SIZE and KEYID_SIZE. A build with no certificates does not have those names (tinytls13-psk-p256 and tls13-psk-no-certs). The struct is now under !defined(NO_CERTS) && !defined(IGNORE_KEY_EXTENSIONS). A local --enable-tinytls13=psk,p256,server build compiled src/libwolfssl.la.

The earlier review threads stay answered on the previous commit. The cross-library jobs failed in apt-get update (exit 124). That is the runner, not this change.

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 gaps in deferred issuer-error handling, certificate-specific callback waivers, and cached-chain issuer matching can bypass certificate purpose restrictions.

3 open issues
3 resolved since last review

Review effort: Balanced

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

@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 #11873

Scan targets checked: wolfssl-src, wolfssl-bugs
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs
Coverage: 1 of 3 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_ssl_cert.c, wolfssl/internal.h

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/internal.c Resolved
A CA loaded into the certificate manager can carry an Extended Key Usage
that does not allow it to issue. The issuer walk reports that purpose
error. A verify callback can accept it for that certificate. The waiver
matches the subject name, the subject key id and the public key, so a
different certificate that reuses the key is not waived. The purpose
error stays out of the leaf result until the leaf checks have run, so a
hostname mismatch or a key-size check cannot hide it. A self-signed user
CA stays the trust anchor.

The waiver list is omitted from builds with no certificates. Those builds
do not define SIGNER_DIGEST_SIZE or KEYID_SIZE.
@sameehj
sameehj force-pushed the fix-ca-ext-key-usage-certmanager branch from 5e3af6e to bdefd80 Compare November 27, 2026 07:09
@sameehj

sameehj commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

The four review notes are in bdefd80. The branch is one commit, rebased onto current master.

  • The waiver matches the subject name, the subject key id and the public key. When the signer still holds the certificate, it also matches the DER hash. The decoy regression now reuses the issuer key.
  • With WOLFSSL_ALLOW_AKID_SKID_MATCH the issuer walk keeps the parent that the subject key id selects, which is the same parent ParseCertRelative keeps. A regression covers a parent whose name differs.
  • The issuer purpose error is stored in ekuIssuerRet and is not written into ret. The key-size check and the hostname check still run. A callback that accepts only the hostname mismatch still sees the purpose error.

SparkiDev
SparkiDev previously approved these changes Nov 30, 2026
@SparkiDev
SparkiDev requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 30, 2026 00:51

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 DER retention disabled, the waiver can incorrectly suppress a distinct pinned issuer’s certificate error, and the ancestor-only regression fails when IGNORE_NAME_CONSTRAINTS is enabled.

2 open issues
3 resolved since last review

Review effort: Balanced

Comment thread src/internal.c Resolved
Comment thread tests/api/test_ssl_cert.c Resolved

@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 #11873

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 3 of 4 in-scope changed file(s) opened by the reviewer; not opened: wolfssl/internal.h

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/internal.c Resolved
CA_TYPE parsing leaves selfSigned clear for that root, and the issuer walk was rejecting it. The waiver fingerprint is compared whenever the signer still holds the certificate.
@sameehj sameehj removed their assignment Dec 3, 2026
@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.

🔵 Needs a closer look

Human assessment is needed because trust-anchor recognition under IGNORE_NAME_CONSTRAINTS can incorrectly reject certificates issued directly by trusted roots.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@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 #11873

Scan targets checked: wolfssl-src, wolfssl-bugs
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs
Coverage: 2 of 3 in-scope changed file(s) opened by the reviewer; not opened: wolfssl/internal.h

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/internal.c
return 0;
if (ca->selfSigned)
return 1;
#if !defined(NO_SKID) && !defined(IGNORE_NAME_CONSTRAINTS)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Trust anchor exemption for AKID==SKID roots compiled out under IGNORE_NAME_CONSTRAINTS / NO_SKID · Preprocessor-conditional security bypass

ParseCertRelative leaves selfSigned clear for a CA_TYPE root whose AKID equals its SKID, and the only fallback that marks it as an anchor is compiled out with IGNORE_NAME_CONSTRAINTS or NO_SKID. In those builds, CheckSignerExtKeyUsage checks the root's own Extended Key Usage, so a leaf issued directly by a root whose Extended Key Usage leaves out the TLS purpose now fails with EXTKEYUSE_AUTH_E.

Suggested fix: Give Signer an anchor marker that does not depend on name-constraint fields, or check the self-signature for this case, so the anchor exemption holds in every build configuration.
Basis: RFC 5280 section 6.1.1(d): trust anchor information is an input to path validation, and the trust anchor's own certificate is not itself validated.

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

  • Earlier finding on this pull request: (1) File/function: same function, SignerIsTrustAnchor in src/internal.c, and the same EKU walk in CheckSignerExtKeyUsage. (2) Operation: both are a false EXTKEYUSE_AUTH_E rejection, because the walk applies the purpose check to an AKID==SKID root that has selfSigned=0. (3) Root cause: -7 is the missing anchor exemption itself, which b350882 addressed with a fallback. The candidate says that fallback sits under #if !defined(NO_SKID) && !defined(IGNORE_NAME_CONSTRAINTS), so builds with either

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