· security / network
TLS Certificate SAN Mismatch: Why CNAME Is Not Enough
The Problem
You set up a DNS CNAME record pointing service-a.example.com → host-b.example.com. You visit https://service-a.example.com/ and the browser shows:
SEC_E_WRONG_PRINCIPAL(Windows) orNET::ERR_CERT_COMMON_NAME_INVALID
But https://host-b.example.com/ works fine. The DNS resolves correctly — nslookup service-a.example.com returns the same IP as host-b.example.com. What went wrong?
DNS CNAME Only Affects Routing, Not TLS
A CNAME record tells the DNS resolver: “look up this other name instead.” The client’s browser resolves service-a.example.com → host-b.example.com → 10.0.0.1, then opens a TCP connection to 10.0.0.1:443 and starts a TLS handshake.
At this point DNS is done. The server at 10.0.0.1 presents its TLS certificate. The browser checks:
- Is the certificate signed by a trusted CA?
- Is the certificate still valid (not expired, not revoked)?
- Does the certificate cover the hostname I typed in the address bar?
Step 3 is where CNAME-based setups fail. The browser compares the address bar hostname (service-a.example.com) against the Subject Alternative Name (SAN) extension in the certificate. If service-a.example.com is not listed, the browser rejects the connection — regardless of DNS.
Verify Certificate SANs
OpenSSL
openssl s_client -connect host-b.example.com:443 -servername host-b.example.com \
</dev/null 2>/dev/null | openssl x509 -noout -text | grep -A1 "Subject Alternative Name"
PowerShell (.NET)
$url = 'https://host-b.example.com/'
$req = [Net.HttpWebRequest]::Create($url)
try { $req.GetResponse() | Out-Null } catch {}
$cert = [Security.Cryptography.X509Certificates.X509Certificate2]::new($req.ServicePoint.Certificate)
$cert.Extensions | Where-Object { $_.Oid.FriendlyName -eq 'Subject Alternative Name' } |
ForEach-Object { $_.Format($true) }
curl
curl -vI https://host-b.example.com/ 2>&1 | Select-String "subject|issuer|SSL certificate"
Two Common Scenarios
| Scenario | Certificate type | SAN list | Result |
|---|---|---|---|
| Dev cert (mkcert) | Self-signed local CA | host-b.example.com, localhost, 127.0.0.1 |
❌ service-a.example.com not in SAN → browser error |
| Production cert (corporate CA) | Signed by enterprise CA | service-a.example.com, host-b.example.com |
✅ Both names covered → no error |
The difference is not the CA type — it is whether the SAN list includes every DNS name that clients will use to reach the service.
How CNAME and SAN Interact
Client types: https://service-a.example.com/
│
▼ DNS resolution
CNAME: service-a.example.com → host-b.example.com
│
▼ A record
host-b.example.com → 10.0.0.1
│
▼ TLS handshake
Server presents certificate
│
▼ SAN check
Is "service-a.example.com" in the SAN list?
│
┌───────┴───────┐
✅ Yes ❌ No
│ │
Allowed SEC_E_WRONG_PRINCIPAL
The Fix
Reissue the certificate with all expected DNS names included in the SAN extension.
mkcert
mkcert host-b.example.com service-a.example.com localhost 127.0.0.1
OpenSSL (manual CSR)
Create a config file with the subjectAltName entry:
[v3_req]
keyUsage = keyEncipherment, digitalSignature
extendedKeyUsage = serverAuth
subjectAltName = @san_list
[san_list]
DNS.1 = host-b.example.com
DNS.2 = service-a.example.com
Then sign with -extensions v3_req -extfile openssl.cnf.
Production CA request
When submitting a CSR to a corporate or public CA, explicitly list every DNS name in the SAN field. Most CA portals have a “Subject Alternative Names” or “DNS Names” section — do not rely on the Common Name (CN) alone.
Key Takeaways
- CNAME is DNS-level routing only. It does not affect TLS certificate validation.
- TLS verifies the hostname in the address bar against the SAN extension. If the name is missing from SAN, the connection fails.
- Always include all CNAME aliases in the certificate SAN. A certificate for
host-b.example.comdoes not automatically coverservice-a.example.com. - The Common Name (CN) is a legacy field. RFC 9525 specifies that TLS identity must be checked against SAN, not CN. Modern clients ignore CN for hostname verification.
- Verify before deploying. Run
openssl s_clientor the PowerShell snippet above against the CNAME URL, not just the canonical hostname.