Skip to content

Fix CN fallback handling in name constraints checking - #3108

Merged
samuel40791765 merged 1 commit into
aws:fips-2025-09-12from
samuel40791765:fix-nm-constraints-fips-4
Mar 19, 2026
Merged

samuel40791765 merged 1 commit into
aws:fips-2025-09-12from
samuel40791765:fix-nm-constraints-fips-4

Conversation

@samuel40791765

Copy link
Copy Markdown
Contributor

Description of changes:

This change fixes two issues in name constraints enforcement:

  1. cn2dnsid now recognizes wildcard CNs (leading *.) as DNS identifiers by skipping the prefix during DNS syntax validation. The full wildcard string is returned so nc_dns can perform suffix matching against permitted/excluded subtrees.

  2. nc_dns now handles wildcard DNS names against excluded subtrees. An exclusion of foo.example.com correctly matches *.example.com by comparing parent domains when the DNS name starts with *. This is based on upstream commit: google/boringssl@5774eca

Call-outs:

This change makes name constraints enforcement stricter. Certificates that were previously accepted (due to wildcard CNs being skipped) will now be checked against their CA's name constraints. Only certificates that were already in violation of their CA's constraints will be newly rejected.

Testing:

  • Expanded NameConstraints in x509_test.cc to test both permitted and excluded subtrees. Also taken from upstream commit referenced above.
  • Added wildcard CN test cases to CommonNameToDNS in x509_compat_test.cc.
  • Added NameConstraintsWildcardCN in x509_test.cc to test the end-to-end CN fallback path with wildcard CNs against both permitted and excluded subtrees.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@github-actions github-actions Bot 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.

clang-tidy made some suggestions

Comment thread crypto/x509/v3_ncons.c

// Normalize absolute DNS names by removing the trailing dot, if any.
if (ends_with_byte(&dns_cbs, '.')) {
uint8_t unused;

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.

warning: variable 'unused' is not initialized [cppcoreguidelines-init-variables]

Suggested change
uint8_t unused;
= 0

Comment thread crypto/x509/v3_ncons.c
CBS_get_last_u8(&dns_cbs, &unused);
}
if (ends_with_byte(&base_cbs, '.')) {
uint8_t unused;

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.

warning: variable 'unused' is not initialized [cppcoreguidelines-init-variables]

Suggested change
uint8_t unused;
= 0

@samuel40791765
samuel40791765 merged commit 35bfa43 into aws:fips-2025-09-12 Mar 19, 2026
123 of 156 checks passed
@samuel40791765
samuel40791765 deleted the fix-nm-constraints-fips-4 branch March 19, 2026 16:00
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.75%. Comparing base (3417d9e) to head (00e6181).
⚠️ Report is 2 commits behind head on fips-2025-09-12.

Files with missing lines Patch % Lines
crypto/x509/x509_test.cc 80.64% 7 Missing and 5 partials ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           fips-2025-09-12    #3108      +/-   ##
===================================================
+ Coverage            78.73%   78.75%   +0.02%     
===================================================
  Files                  667      667              
  Lines               113124   113213      +89     
  Branches             16057    16072      +15     
===================================================
+ Hits                 89072    89165      +93     
+ Misses               23277    23265      -12     
- Partials               775      783       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

abelianbee added a commit to abelianbee/aws-lc that referenced this pull request Oct 1, 2026
…only

check_name_constraints() ran NAME_CONSTRAINTS_check_CN() on every
certificate in the chain that has no dNSName SAN, including intermediate
CAs. The CN fallback exists because X509_check_host() may match a leaf's
commonName as a hostname when there is no SAN; a CA's commonName is never
used that way. OpenSSL 1.1.1, which this code was reintroduced from in
aws#2376, restricts the check to the leaf (i == 0).

Since aws#3108 made a multi-label CN with spaces an error instead of a
non-DNS name, the extra check rejects chains through ordinary
intermediates such as "CN=ACME Corp. Issuing CA G2" under a
name-constrained root with X509_V_ERR_UNSUPPORTED_NAME_SYNTAX at depth 1,
where OpenSSL verifies them. Restore the leaf-only condition. The leaf
behavior from aws#3108 is unchanged.
justsmth pushed a commit to abelianbee/aws-lc that referenced this pull request Oct 14, 2026
…only

check_name_constraints() ran NAME_CONSTRAINTS_check_CN() on every
certificate in the chain that has no dNSName SAN, including intermediate
CAs. The CN fallback exists because X509_check_host() may match a leaf's
commonName as a hostname when there is no SAN; a CA's commonName is never
used that way. OpenSSL 1.1.1, which this code was reintroduced from in
aws#2376, restricts the check to the leaf (i == 0).

Since aws#3108 made a multi-label CN with spaces an error instead of a
non-DNS name, the extra check rejects chains through ordinary
intermediates such as "CN=ACME Corp. Issuing CA G2" under a
name-constrained root with X509_V_ERR_UNSUPPORTED_NAME_SYNTAX at depth 1,
where OpenSSL verifies them. Restore the leaf-only condition. The leaf
behavior from aws#3108 is unchanged.
justsmth pushed a commit to abelianbee/aws-lc that referenced this pull request Oct 28, 2026
…only

check_name_constraints() ran NAME_CONSTRAINTS_check_CN() on every
certificate in the chain that has no dNSName SAN, including intermediate
CAs. The CN fallback exists because X509_check_host() may match a leaf's
commonName as a hostname when there is no SAN; a CA's commonName is never
used that way. OpenSSL 1.1.1, which this code was reintroduced from in
aws#2376, restricts the check to the leaf (i == 0).

Since aws#3108 made a multi-label CN with spaces an error instead of a
non-DNS name, the extra check rejects chains through ordinary
intermediates such as "CN=ACME Corp. Issuing CA G2" under a
name-constrained root with X509_V_ERR_UNSUPPORTED_NAME_SYNTAX at depth 1,
where OpenSSL verifies them. Restore the leaf-only condition. The leaf
behavior from aws#3108 is unchanged.
justsmth pushed a commit that referenced this pull request Nov 2, 2026
…only (#3603)

### Related issues

Addresses #3521

### Context and motivation

`check_name_constraints()` runs `NAME_CONSTRAINTS_check_CN()` on every
chain certificate without a dNSName SAN, intermediates included. The
fallback exists because `X509_check_host()` may match a leaf's
commonName as a hostname when there is no SAN. A CA's commonName is
never used that way, and OpenSSL 1.1.1, which #2376 reintroduced this
code from, applies it to the leaf only (`i == 0`).

That was harmless until #3108: a CN like `ACME Corp. Issuing CA G2` has
spaces, so `cn2dnsid()` skipped it as a non-DNS name. #3108 made a
multi-label CN containing a space an error instead, so a chain through
an intermediate with an ordinary organization name under a
name-constrained root now fails with
`X509_V_ERR_UNSUPPORTED_NAME_SYNTAX` at depth 1. OpenSSL verifies the
same chain.

### Description of changes

Restore `i == 0` so the fallback applies to the end-entity certificate
only. That drops the CN check on every intermediate, including ones
whose CN does parse as a DNS name: an intermediate with
`CN=issuing.evil.com` under a root permitting only `.example.com` used
to fail with `X509_V_ERR_PERMITTED_VIOLATION` and now verifies.
Intermediate CNs are never matched as hostnames, so a name constraint on
them has nothing to protect, and OpenSSL and pre-#2376 AWS-LC behave the
same way.

`NAME_CONSTRAINTS_check()` still runs against every certificate, so
directoryName and SAN constraints on intermediates are unaffected, and
the leaf behavior from #3108 is unchanged.

This does not decide whether a space should make a leaf CN an error or a
non-DNS name, which is the other half of #3521.

### Testing

- `X509Test.NameConstraintsIntermediateCN`: name-constrained root,
intermediate with `CN=ACME Corp. Issuing CA G2` and no SAN, three
leaves. One inside the permitted subtree verifies, one outside still
gets `X509_V_ERR_PERMITTED_VIOLATION`, one with `CN=foo .evil.com` still
gets `X509_V_ERR_UNSUPPORTED_NAME_SYNTAX`. On main the first two fail
with error 53 at the intermediate. A fourth leaf goes through an
intermediate with `CN=issuing.evil.com`, which fails with error 47 on
main.
- Reproduced #3521 with an OpenSSL CLI chain and a verifier linked
against this tree and against OpenSSL 3.6.4: `verify=0 err=53 depth=1`
before, `ok` on OpenSSL, both `ok` after.
- Full `crypto_test` passes on macOS arm64.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.

This branch was successfully deployed

No deployments
auto-approve — 00e61818 Deployed Mar 19, 2026 by samuel40791765 via android-debug-shared #524
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