Skip to content

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

Closed

Description

@wfurt

Traditionally, one can put IP address to CN and have that validated agains actual IP address.
However, when SubjectAlternativeName is present it should take precedence:

https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.6

The behavior is Linux specific and it works as expected when same validation runs on Windows.

Activity

  1. added
    os-linux
    on Aug 3, 2026
  2. added
    untriaged
    on Aug 3, 2026
  3. dotnet-policy-service commented on Aug 3, 2026

    @dotnet-policy-service
    Contributor

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

  4. changed the title [-]X509Chain process IP literals in CN on Linux when SAN is also present[/-] [+]Linux CheckX509IpAddress processes IP literals in CN on Linux when SAN is also present[/+] on Aug 14, 2026
  5. removed
    untriaged
    on Aug 14, 2026
  6. added this to the 12.0.0 milestone on Aug 14, 2026
  7. makazeu commented on Oct 10, 2026

    @makazeu
    Contributor

    IP address matching with CN and SAN on Windows and Linux

    I ran the same 45-case certificate/target-IP matrix through actual SslStream TLS connections on both platforms. The main difference is how DNS SANs affect IP-name validation: Windows suppresses CN fallback in the tested DNS-SAN cases, while Linux can still match the IP literal in CN. Both platforms also exhibit legacy CN fallback when SAN contains only conflicting IP addresses.

    Observed rules

    The 12 rows with different Windows/Linux results fall into three scenarios:

    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: Mismatch; Linux: Match through CN fallback. This occurs with both IPv4 and IPv6, including a DNS SAN plus a conflicting IP SAN (rows 5-6, 19-20, 22-23 and 43).
    # CN SAN contents Target IP Windows Linux
    5 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: Mismatch; Linux: Match. The control cases support CN fallback, not wildcard-based IP matching (rows 14 and 26).
    # CN SAN contents Target IP Windows Linux
    14 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 matching IP SAN. Windows: Match; Linux: Mismatch. This occurs with both IPv4 and IPv6 (rows 13, 17 and 44).
    # CN SAN contents Target IP Windows Linux
    13 other.test DNS:192.0.2.1 192.0.2.1 Match ⚠️ Mismatch

    Windows CN × SAN matrix

    Windows name-matching results when the client's TargetHost is an IP literal and no IP SAN matches that address. “Matching CN” means the same IP text; “Nonmatching CN” means an unrelated name or a different IP.

    ✅ Match · ❌ Mismatch · — Not tested

    SAN contents Matching CN Nonmatching CN Key observation
    IP SAN(s), none matching; no DNS SAN ✅ ❌ A nonmatching IP SAN does not prevent CN fallback.
    DNS SAN with an unrelated name or a different IP text ❌ — A nonmatching DNS SAN does prevent CN fallback.
    DNS SAN with exactly the target IP text; no IP SAN ✅ ✅ An IP literal can match a DNS SAN, even with an unrelated CN.
    DNS SAN with a wildcard; no IP SAN ❌ ❌ The tested wildcards neither match the IP nor allow CN fallback.

    The wildcard cases are IPv4-only. The last three combinations account for the Windows/Linux differences described above.

    Three distinct CN / DNS SAN / IP SAN addresses

    As requested in the PR review, fix CN=192.168.2.1 and SAN=DNS:192.168.2.2, IP:192.168.2.3, then try all three target addresses. The results below were measured on installed .NET 10.0.14 runtimes, not the PR-built runtime.

    TargetHost Windows Linux before fix
    192.168.2.1 Mismatch Match
    192.168.2.2 Match Mismatch
    192.168.2.3 Match Match

    Windows matches both SAN entries independently, while the DNS SAN suppresses CN fallback. The reproduction harness now includes these as rows 43-45, and the PR theory includes the three Windows-compatible expectations (false, true, true).

    Environment and method

    Reproduction code: IP address certificate-matching test harness.

    Platform Environment
    Windows OS 10.0.26300; .NET runtime 10.0.14
    Linux Ubuntu 26.04.1 LTS (ARM64) in WSL2; .NET runtime 10.0.14; OpenSSL 3.5.5

    These are installed runtimes, not locally built runtime binaries. The harness was built for net10.0; the same managed DLL ran on both platforms.

    Each case used a self-signed certificate and a loopback TLS 1.2 connection with the listed target IP as TargetHost. Match means no RemoteCertificateNameMismatch; Mismatch means it was reported. The diagnostic callback allowed certificate errors, so these results do not indicate default certificate acceptance. Absent means no CN.

    All 90 TLS handshakes and payload checks completed, with zero harness assertion failures.

    TLS name-validation results

    ⚠️ in the Linux column marks a result that differs from Windows

    # CN SAN contents Target IP Windows Linux
    1 192.0.2.1 None 192.0.2.1 Match Match
    2 192.0.2.1 IP:192.0.2.2 192.0.2.1 Match Match
    3 192.0.2.1 IP:192.0.2.2 192.0.2.2 Match Match
    4 192.0.2.1 IP:192.0.2.2 192.0.2.3 Mismatch Mismatch
    5 192.0.2.1 DNS:example.test 192.0.2.1 Mismatch ⚠️ Match
    6 192.0.2.1 DNS:example.test; IP:192.0.2.2 192.0.2.1 Mismatch ⚠️ Match
    7 192.0.2.1 DNS:example.test; IP:192.0.2.2 192.0.2.2 Match Match
    8 192.0.2.1 None 192.0.2.2 Mismatch Mismatch
    9 2001:db8::1 None 2001:db8::1 Match Match
    10 2001:db8::1 IP:2001:db8::2 2001:db8::1 Match Match
    11 2001:db8::1 IP:2001:db8::2 2001:db8::2 Match Match
    12 192.0.2.1 DNS:192.0.2.1 192.0.2.1 Match Match
    13 other.test DNS:192.0.2.1 192.0.2.1 Match ⚠️ Mismatch
    14 192.0.2.1 DNS:*.0.2.1 192.0.2.1 Mismatch ⚠️ Match
    15 *.0.2.1 None 192.0.2.1 Mismatch Mismatch
    16 2001:db8::1 DNS:2001:db8::1 2001:db8::1 Match Match
    17 other.test DNS:2001:db8::1 2001:db8::1 Match ⚠️ Mismatch
    18 2001:db8::1 None 2001:db8::2 Mismatch Mismatch
    19 2001:db8::1 DNS:example.test 2001:db8::1 Mismatch ⚠️ Match
    20 2001:db8::1 DNS:example.test; IP:2001:db8::2 2001:db8::1 Mismatch ⚠️ Match
    21 2001:db8::1 DNS:example.test; IP:2001:db8::2 2001:db8::2 Match Match
    22 192.0.2.1 DNS:192.0.2.2 192.0.2.1 Mismatch ⚠️ Match
    23 2001:db8::1 DNS:2001:db8::2 2001:db8::1 Mismatch ⚠️ Match
    24 other.test DNS:*.0.2.1 192.0.2.1 Mismatch Mismatch
    25 other.test DNS:*.2.1 192.0.2.1 Mismatch Mismatch
    26 192.0.2.1 DNS:*.2.1 192.0.2.1 Mismatch ⚠️ Match
    27 *.2.1 None 192.0.2.1 Mismatch Mismatch
    28 other.test IP:192.0.2.1; IP:192.0.2.2 192.0.2.1 Match Match
    29 other.test IP:192.0.2.2; IP:192.0.2.1 192.0.2.1 Match Match
    30 other.test IP:2001:db8::2; IP:192.0.2.1 192.0.2.1 Match Match
    31 other.test IP:192.0.2.2; IP:2001:db8::1 2001:db8::1 Match Match
    32 other.test IP:192.0.2.2; IP:2001:db8::2 192.0.2.1 Mismatch Mismatch
    33 other.test DNS:2001:0db8:0:0:0:0:0:1 2001:db8::1 Mismatch Mismatch
    34 other.test DNS:2001:db8::1 2001:0db8:0:0:0:0:0:1 Mismatch Mismatch
    35 2001:0db8:0:0:0:0:0:1 None 2001:db8::1 Mismatch Mismatch
    36 2001:db8::1 None 2001:0db8:0:0:0:0:0:1 Mismatch Mismatch
    37 2001:DB8::1 None 2001:db8::1 Match Match
    38 other.test IP:2001:db8::1 2001:0db8:0:0:0:0:0:1 Match Match
    39 192.0.2.1 URI:https://example.test/ 192.0.2.1 Match Match
    40 192.0.2.1 EMAIL:[email protected] 192.0.2.1 Match Match
    41 Absent IP:192.0.2.1 192.0.2.1 Match Match
    42 Absent IP:192.0.2.2 192.0.2.1 Mismatch Mismatch
    43 192.168.2.1 DNS:192.168.2.2; IP:192.168.2.3 192.168.2.1 Mismatch ⚠️ Match
    44 192.168.2.1 DNS:192.168.2.2; IP:192.168.2.3 192.168.2.2 Match ⚠️ Mismatch
    45 192.168.2.1 DNS:192.168.2.2; IP:192.168.2.3 192.168.2.3 Match Match

    Rows 33-34 test a numeric IPv6 DNS SAN against a different textual representation of the same address, in both directions. Both platforms report a name mismatch. Unlike an iPAddress SAN, the tested numeric DNS SAN does not match merely because the IPv6 address bytes are equal.

    Windows reported 22 name mismatches; Linux reported 16. Platform differences occurred in 12 rows: 5, 6, 13, 14, 17, 19, 20, 22, 23, 26, 43, 44.

    Note

    This report and its test harness were generated with GitHub Copilot. The results were obtained by executing all 45 cases on Windows and Ubuntu WSL2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Securityos-linux

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions