Skip to content

Align Linux IP certificate name matching with Windows - #135573

Merged
bartonjs merged 9 commits into
dotnet:mainfrom
makazeu:fix-linux-ip-cn-san-matching
Nov 6, 2026
Merged

bartonjs merged 9 commits into
dotnet:mainfrom
makazeu:fix-linux-ip-cn-san-matching

Conversation

@makazeu

@makazeu makazeu commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Align Linux certificate-name validation with Windows behavior when SslStream.TargetHost is an IP address (IPv4 or IPv6), not a DNS hostname. The cross-platform tests identified three scenarios where the existing Linux and Windows results differ; this PR makes Linux follow Windows in those scenarios.

cc @wfurt

Observed platform differences

The results below are from installed .NET 10.0.14 runtimes, before this fix.

  1. CN matches the target IP, but SAN contains an unrelated DNS name or a different numeric DNS name, with no matching IP SAN. Windows reports a mismatch; Linux matches through CN fallback. This occurs with both IPv4 and IPv6, including a DNS SAN plus a conflicting IP SAN.
CN SAN contents Target IP Windows Linux before fix
192.0.2.1 DNS:example.test 192.0.2.1 Mismatch Match
  1. CN matches the target IPv4 address, but SAN contains DNS wildcard *.0.2.1 or *.2.1, with no IP SAN. Windows reports a mismatch; Linux matches. The control cases support CN fallback, not wildcard-based IP matching.
CN SAN contents Target IP Windows Linux before fix
192.0.2.1 DNS:*.0.2.1 192.0.2.1 Mismatch Match
  1. CN is unrelated to the target IP, but a numeric DNS SAN exactly matches the target IP string, with no IP SAN. Windows matches; Linux reports a mismatch. This occurs with both IPv4 and IPv6.
CN SAN contents Target IP Windows Linux before fix
other.test DNS:192.0.2.1 192.0.2.1 Match Mismatch

Additional IPv6 boundary checks used CN=other.test and compared DNS SAN 2001:0db8:0:0:0:0:0:1 with target 2001:db8::1, and the reverse. Both platforms reported a name mismatch in both directions: the tested numeric DNS SAN does not match merely because the IPv6 address bytes are equal (report rows 33-34).

For the full cross-platform results, environment details, and reproduction code, see the test report in dotnet/runtime#131734.

Match means no RemoteCertificateNameMismatch; certificate-chain validation is a separate check.

Approach

Keep the existing byte-for-byte IP SAN check as the first and fast path. If it does not match, use OpenSSL’s X509_check_host for DNS SAN/CN text matching, with wildcard expansion disabled for IP targets. This lets OpenSSL apply DNS SAN precedence while retaining the legacy CN fallback observed on Windows when there are no DNS SAN entries, including certificates with only a nonmatching IP SAN.

This change targets Windows compatibility rather than RFC 9525 IP-ID matching, which requires an exact match against an iPAddress SAN (§6.2 and §6.4) and does not permit CN fallback (§2).

Changes

  • Replace the manual CN scan in CryptoNative_CheckX509IpAddress with X509_check_host.
  • Disable wildcard expansion for this IP-target fallback. The previous CN comparison required an exact text match, and Windows TLS tests rejected the wildcard cases tested.
  • Propagate negative native matching results through CertificateValidation.Unix.cs as cryptographic errors for IP targets as well as DNS hostnames.
  • Add 27 IPv4/IPv6 SslStream TLS cases covering CN-only certificates, matching and conflicting IP SANs, DNS SAN precedence, numeric DNS SANs, wildcard names, and equivalent IPv6 addresses with different DNS SAN spellings. Each case has a descriptive scenario name and named inputs; comments explain the certificate-validation setup.

Validation

Built and tested in Docker on Ubuntu 24.04, Linux x64 (Release CoreCLR, Debug libraries). 0 test failures.

Tests Passed Skipped
IP-literal regression theory 27 0
System.Net.Security functional 5,153 8
System.Net.Security unit 144 2
QUIC functional (MsQuic enabled) 449 2

Co-authored-by: Copilot App [email protected]

Resolves #131734

Note

This description was generated with GitHub Copilot.

Use exact DNS SAN and CN matching without wildcards after IP SAN matching. Propagate OpenSSL matching errors and cover IPv4/IPv6 behavior with TLS regression cases.

Fixes dotnet#131734

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 157c8032-dde4-46fd-aacd-8aa770fdfe74
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 10, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

@makazeu
makazeu marked this pull request as ready for review October 10, 2026 12:49

@rzikm rzikm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

S.N.S portion LGTM, tagging @bartonjs for openssl.c changes

Yifan Zhu🦅 and others added 6 commits November 5, 2026 14:36
Use named scenarios and named arguments for the certificate matching matrix. Preserve the existing coverage and add both equivalent-IPv6-spelling DNS SAN cases. Explain validation isolation and callback behavior in the theory body.

Co-authored-by: Copilot App <[email protected]>
@bartonjs
bartonjs enabled auto-merge (squash) November 6, 2026 00:47
@bartonjs
bartonjs merged commit 533113b into dotnet:main Nov 6, 2026
101 of 103 checks passed
@makazeu
makazeu deleted the fix-linux-ip-cn-san-matching branch November 6, 2026 04:31
@bartonjs bartonjs added the cryptographic-docs-impact Issues impacting cryptographic docs. Cleared and reused after documentation is updated each release. label Nov 6, 2026
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Net.Security community-contribution Indicates that the PR has been added by a community member cryptographic-docs-impact Issues impacting cryptographic docs. Cleared and reused after documentation is updated each release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux CheckX509IpAddress processes IP literals in CN on Linux when SAN is also present

3 participants