Skip to content

Fix name constraint bypasses for empty dNSName and quoted mailboxes - #11948

Open
embhorn wants to merge 2 commits into
wolfSSL:masterfrom
embhorn:zd22724
Open

embhorn wants to merge 2 commits into
wolfSSL:masterfrom
embhorn:zd22724

Conversation

@embhorn

@embhorn embhorn commented Oct 30, 2026

Copy link
Copy Markdown
Member

Description

Two inputs let a certificate escape an excluded name constraint subtree:

  • Empty excluded dNSName. excluded: DNS: (zero-length), the CA/Browser Forum encoding for a sub-CA that may not issue DNS names, was treated as matching nothing. Per RFC 5280 4.2.1.10 it now matches every DNS name, in the native and OpenSSL compat paths. A lone "." base is treated the same way unless OPENSSL_COMPATIBLE_DEFAULTS is
    defined.
  • Quoted local-part rfc822Name. "x@y"@evil.com escaped excluded: email:evil.com because two '@' characters made the name "invalid". The mailbox is now split at its last '@'. An '@' outside a quoted local-part makes the name uncomparable, and the certificate is rejected on both permitted and excluded subtrees.

The subject CN fallback for DNS constraints now applies only to CNs with host name syntax, so an empty excluded dNSName does not reject S/MIME or client-auth leaves whose CN is a person's name.

Fixes zd22724

Testing

  • New and updated cases in tests/api/test_asn.c, tests/api/test_ossl_x509_ext.c and tests/unit-mcdc/test_asn_ext_whitebox.c.
  • asn and ossl_x509_ext groups and the white-box smoke run pass with --enable-all and with --disable-openssl-compatible-defaults.
  • TLS 1.3 end to end with the example client and server: the bypass chains are now rejected with -198, and the valid quoted-mailbox and person-name-CN chains are still accepted.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@embhorn embhorn self-assigned this Oct 30, 2026
Copilot AI balanced review requested due to automatic review settings October 30, 2026 21:28

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m0plus

  • FLASH: .text +348 B (+0.5%, 71,027 B / 262,144 B, total: 27% used)

gcc-arm-cortex-m3

  • FLASH: .text +544 B (+0.4%, 131,969 B / 262,144 B, total: 50% used)

gcc-arm-cortex-m4

  • FLASH: .text +796 B (+0.4%, 209,228 B / 262,144 B, total: 80% used)

gcc-arm-cortex-m4-baremetal

  • FLASH: .text +384 B (+0.5%, 73,719 B / 262,144 B, total: 28% used)

gcc-arm-cortex-m4-crypto-only

  • FLASH: .text +320 B (+0.2%, 181,907 B / 262,144 B, total: 69% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +1,088 B (+0.6%, 196,184 B / 1,048,576 B, total: 19% used)

gcc-arm-cortex-m4-min-ecc

  • FLASH: .text +320 B (+0.5%, 68,313 B / 262,144 B, total: 26% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .rodata +2,472 B, .text +2,112 B (+0.6%, 801,636 B / 1,048,576 B, total: 76% used)
  • RAM: .bss -12,048 B (-9.0%, 121,772 B / 262,144 B, total: 46% used)

gcc-arm-cortex-m4-pkcs7

  • FLASH: .text +384 B (+0.2%, 223,060 B / 262,144 B, total: 85% used)

gcc-arm-cortex-m4-pq

  • FLASH: .text +1,216 B (+0.4%, 313,040 B / 1,048,576 B, total: 30% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .rodata +8 B, .text +1,216 B (+0.4%, 343,888 B / 1,048,576 B, total: 33% used)
  • RAM: .bss +1,320 B (+7.9%, 17,996 B / 262,144 B, total: 7% used)

gcc-arm-cortex-m4-sp-math

  • FLASH: .text +320 B (+0.5%, 68,313 B / 262,144 B, total: 26% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +576 B (+0.4%, 132,753 B / 262,144 B, total: 51% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +1,024 B (+0.4%, 249,762 B / 262,144 B, total: 95% used)

gcc-arm-cortex-m7

  • FLASH: .text +860 B (+0.4%, 209,292 B / 262,144 B, total: 80% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +1,216 B (+0.4%, 313,872 B / 1,048,576 B, total: 30% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .text +1,024 B (+0.4%, 249,826 B / 262,144 B, total: 95% used)

stm32-sim-stm32h753

  • FLASH: .text -256 B (-0.1%, 204,332 B / 2,097,152 B, total: 10% used)

zephyr-frdm_rw612

  • FLASH: text +8 B (+0.0%, 284,304 B / 67,108,864 B, total: 0% used)

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

@embhorn

embhorn commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Fix confirmed by customer

@embhorn

embhorn commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

retest this please

@embhorn embhorn assigned wolfSSL-Bot and unassigned embhorn Nov 5, 2026
@SparkiDev
SparkiDev requested a balanced review from Copilot November 6, 2026 02:05
@SparkiDev

Copy link
Copy Markdown
Contributor

@claude 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

Unresolved DNS and mailbox validation gaps allow supported single-label hostnames and malformed email names to bypass name constraints, including a critical CN-fallback path that can authenticate localhost outside a CA’s permitted scope.

2 open issues

Review effort: Balanced

Comment thread wolfcrypt/src/asn.c Outdated
return 0;
}

return hasDot;
Comment thread wolfcrypt/src/asn.c
Comment on lines +20036 to +20038
if (!Rfc822LocalPartOk(name, atPos)) {
WOLFSSL_MSG("rfc822Name has an unquoted '@' in its local-part");
return ASN_PARSE_E;
Comment thread wolfcrypt/src/asn.c Outdated
Comment on lines +20808 to +20816
if (c == '.' && cn[i - 1] != '-' && cn[i - 1] != '.' &&
cn[i + 1] != '.') {
hasDot = 1;
continue;
}
return 0;
}

return hasDot;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Leaves under a DNS-constrained CA can now get past permitted/excluded dNSName subtrees with a dotless subject CN such as "localhost" or "intranet". CnIsDnsName returns hasDot, so any single-label CN skips the CN fallback in ConfirmNameConstraints. CheckHostName still matches that CN against the peer hostname. Fix: apply the fallback to every CN that MatchDomainName could match as a host name, including dotless LDH labels and a lone '*', and skip only CNs with non-host-name characters such as spaces.

Why this was flagged

A CA has nameConstraints permitted DNS:example.com or excluded DNS: (empty). It issues a leaf with no dNSName SAN and CN=intranet. ConfirmNameConstraints (asn.c:20855) now calls CnIsDnsName, which returns 0 because the CN has no '.' (asn.c:20816), so the CN is never checked against the DNS subtrees and the chain verifies. During TLS, CheckHostName (src/internal.c:15425-15427) falls back to MatchDomainName on subjectCN and accepts hostname "intranet" or "localhost". On the base branch the CN was checked for every non-CA leaf without a dNSName SAN and was rejected as outside example.com. The PR's goal of skipping person-name CNs like "John Doe" is met by the character check alone. The at-least-one-dot rule, copied from OpenSSL cn2dnsid, also exempts real single-label host names, which reopens a constraint bypass this change set out to close.

Verification: The new CnIsDnsName (wolfcrypt/src/asn.c, around lines 20781-20817) ends with return hasDot;. A dotless label-only CN therefore returns 0. The DNS constraint is never applied and the chain verifies. On the base branch the gate was only cert->subjectCN != NULL && !cert->isCA. So this is a regression.

Comment thread wolfcrypt/src/asn.c Outdated
Comment on lines +20796 to +20813
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') || c == '_' || c == '*') {
continue;
}
/* '-' and '.' may not be first or last. */
if (i == 0 || i == cnLen - 1) {
return 0;
}
if (c == '-') {
continue;
}
/* A '.' may not follow '-' or '.', nor precede '.'. */
if (c == '.' && cn[i - 1] != '-' && cn[i - 1] != '.' &&
cn[i + 1] != '.') {
hasDot = 1;
continue;
}
return 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Name-constrained sub-CAs can now issue no-SAN leaves whose CN is an IPv6 literal, and clients verifying that IP accept them. CnIsDnsName rejects ':', so ConfirmNameConstraints skips the CN fallback. Yet MatchDomainName (src/internal.c:15149) still matches an IPv6 CN through MatchIPv6. Fix: keep every CN the hostname matcher can match under constraints, e.g. treat a CN that parses as an IP address as constrained (reject it when DNS or IP subtrees exist). This differs from the dotless-CN finding: dropping the dot requirement still leaves ':' rejected.

Why this was flagged

Trigger: a CA with nameConstraints permitted DNS:example.com (optionally plus permitted iPAddress subtrees) issues a non-CA leaf with no SAN and subject CN=2001:db8::1. CnIsDnsName (asn.c:20796-20813) returns 0 for the ':' bytes, so the condition at asn.c:20855-20856 skips the CN fallback. No DNS constraint is applied, and iPAddress constraints are never applied to the CN. On the base branch the CN was checked against permitted DNS:example.com and the chain was rejected. After this change ConfirmNameConstraints returns 1. In ProcessPeerCerts (src/internal.c:20494-20500), wolfSSL_check_domain_name("2001:db8::1") with no altNames falls back to MatchDomainName on the CN. MatchDomainName calls MatchIPv6 first (src/internal.c:15147-15150, built with WOLFSSL_IP_ALT_NAME, which OPENSSL_ALL requires), so the handshake succeeds for an IP the CA was never allowed to certify. The isIP skip in CheckHostName (internal.c:15425) does not cover this path.

Verification: CnIsDnsName (asn.c:20781-20816) only accepts letters, digits, '_', '*', '-' and '.'. So the new condition at asn.c:20855-20856 leaves subjectDnsName empty. On the base branch the CN was checked against permitted DNS:example.com and the chain was rejected. MatchDomainName first tries MatchIPv6 (internal.c:15147-15150).

Comment thread wolfcrypt/src/asn.c
Comment on lines 19966 to 19967
return 0;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟣 pre-existing, not blocking: Pre-existing, security-relevant: a sub-CA under excluded: email:evil.com can still issue an accepted cert for the mailbox ".x@ evil.com". The early name[0] == '.' return at asn.c:19965 runs before the RFC822 split, so a leading-dot local-part reports "no match", and an excluded subtree treats that as outside. Fix: apply the leading-dot rejection only to DNS names, and for RFC822 compare the host-part after the last '@' whatever the local-part starts with (as OpenSSL's nc_email does), in both the native and compat paths. The PR closes the quoted-'@' escape but leaves this sibling escape.
A small fix can ride a push you are already making; otherwise a short reply is enough.

Why this was flagged

An intermediate has nameConstraints excluded: email:evil.com. It issues a leaf with SAN rfc822Name .x@ evil.com, or subject emailAddress .x@ evil.com. SetDNSEntry (asn.c:21258) stores the name unvalidated. IsInExcludedList (asn.c:20733) calls wolfssl_local_MatchBaseName(ASN_RFC822_TYPE, ...). That function returns 0 at asn.c:19965-19966 before the '@' split at asn.c:20022 and before the new Rfc822LocalPartOk check, so mRet is 0, not ASN_PARSE_E. ConfirmNameConstraints then accepts the leaf. The OpenSSL-compat wolfSSL_NAME_CONSTRAINTS_check_name hits the same function through MatchNameConstraint (src/x509.c:6107) and also returns 1. The base branch behaves the same way, so this is pre-existing. It is the same "malformed mailbox counts as no match, so it escapes the exclusion" pattern the PR fixes for "x@ y"@ evil.com, and the new negative-result mechanism does not reach it because the early return comes first. A permitted subtree fails closed for the same input, so only excluded subtrees are bypassed.

Verification: Trigger: a CA has an excluded rfc822Name subtree such as email:evil.com and issues a leaf whose rfc822Name starts with '.', for example ".x@ evil.com". In wolfcrypt/src/asn.c, the check at 19965-19967 (if (name[0] == '.') { return 0; }) runs before the last-'@' split. In IsInExcludedList 0 leaves ret = 0. The base already has the same line.

Comment thread wolfcrypt/src/asn.c
Comment on lines +19969 to +19973
/* An empty dNSName base covers all DNS names. Report a match so that an
* excluded empty subtree excludes everything. */
if (type == ASN_DNS_TYPE && DnsBaseIsEmpty(base, baseSz)) {
return 1;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟣 pre-existing, not blocking: pre-existing: In --enable-asn=original builds, a CA whose nameConstraints hold a zero-length dNSName still fails to parse. The new empty-base handling is unreachable there, and that CA's S/MIME and client-auth chains stay rejected. asn_orig.c:4107 treats GetLength() returning 0 as "invalid length" and fails the whole extension with ASN_PARSE_E. Fix: in DecodeSubtree (asn_orig.c), accept a zero length (test < 0) so the empty entry is stored as the template decoder already does at asn.c:22651-22661.
A small fix can ride a push you are already making; otherwise a short reply is enough.

Why this was flagged

In non-template builds (WOLFSSL_ASN_TEMPLATE off, asn_orig.c included at asn.c:41941), DecodeSubtree reads each GeneralName length with if (GetLength(input, &nameIdx, &strLength, sz) <= 0) at asn_orig.c:4107. GetLength_ex returns the parsed length itself (asn.c:2810), which is 0 for the CA/Browser Forum excluded: DNS: encoding. DecodeSubtree returns ASN_PARSE_E, DecodeNameConstraints fails (asn_orig.c:4204-4209), and DecodeExtensionType sets ret = ASN_PARSE_E (asn.c:23649-23651), so the CA certificate does not load. The empty-base code this PR adds in wolfssl_local_MatchBaseName (asn.c:19969-19973) and wolfssl_local_MatchDnsConstraintWildcard (asn.c:20408-20412) never runs in this build. The CnIsDnsName change, meant to keep S/MIME and client-auth leaves under such a CA valid, has no effect either. This fails closed, which is the same as on the base branch. Template builds store the zero-length entry (asn.c:22651-22661) and behave as the PR describes.

Verification: pre-existing. In wolfcrypt/src/asn_orig.c, DecodeSubtree has if (GetLength(input, &nameIdx, &strLength, sz) <= 0) { WOLFSSL_MSG("\tinvalid length"); return ASN_PARSE_E; }. GetLength_ex ends with return (int)length;, so a zero-length GeneralName gives 0 and the subtree decode fails. The diff does not touch asn_orig.c. The result is fail-closed: the whole CA is rejected, not bypassed.

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.

4 participants