---
title: "TLS hostname mismatch calling a dependency: which name is wrong? | Proofline"
description: "A hostname mismatch means the name your client used is not among the certificate's subject alternative names."
url: https://proofline.sh/learn/tls-hostname-mismatch/
---

[Learning center](/learn/)

# TLS hostname mismatch calling a dependency: which name is wrong?

A hostname mismatch means the name your client used is not among the certificate's subject alternative names. Print the SAN list and compare it with the exact name or address in your client's configuration. Most cases are a connection by IP address, a call through an alias whose certificate covers another name, a wildcard one label too shallow, or the wrong certificate served.

Network outages The Proofline team November 23, 2026 5 min read

## How the error appears

Each client words it differently. OpenSSL defines `X509_V_ERR_HOSTNAME_MISMATCH` (`hostname mismatch`) and `X509_V_ERR_IP_ADDRESS_MISMATCH`. curl prints `SSL: no alternative certificate subject name matches target hostname` followed by the name. Python reports `Hostname mismatch, certificate is not valid for` the name. Node.js raises `ERR_TLS_CERT_ALTNAME_INVALID` with `Hostname/IP does not match certificate's altnames`, and its reason lists the names it found. Go prints `x509: certificate is valid for` the names it found, `not` the name it wanted, or `cannot validate certificate for` an address `because it doesn't contain any IP SANs`. [OpenSSL verify error codes](https://docs.openssl.org/3.0/man3/X509_STORE_CTX_get_error/) · [curl OpenSSL backend](https://github.com/curl/curl/blob/master/lib/vtls/openssl.c) · [CPython ssl module source](https://github.com/python/cpython/blob/main/Modules/_ssl.c) · [Node.js tls.checkServerIdentity](https://github.com/nodejs/node/blob/main/lib/tls.js) · [Go x509 verify](https://go.dev/src/crypto/x509/verify.go)

The certificate itself is usually fine and current. The mismatch is between it and the name you asked for.

## The rules the client applies

The client compares the name it used to open the connection with the certificate's subject alternative names. RFC 9525, which replaced RFC 6125 in 2023, says server identity is expressed only in the subject alternative name extension; matching the subject Common Name is no longer valid. Go returns `x509: certificate relies on legacy Common Name field, use SANs instead` for such a certificate. [RFC 9525 changes from RFC 6125](https://www.rfc-editor.org/rfc/rfc9525#appendix-A) · [Go x509 verify](https://go.dev/src/crypto/x509/verify.go)

Three rules cause most surprises:

-   **IP addresses match only IP entries.** An address reference must exactly match an `iPAddress` entry in the SAN list. A certificate with only DNS names cannot validate a connection made to `10.0.4.17`. [RFC 9525 IP address matching](https://www.rfc-editor.org/rfc/rfc9525#section-6.4)
-   **A wildcard matches one label.** The wildcard must be the whole left-most label, and it matches exactly one label. `*.example.com` covers `orders.example.com` but not `eu.orders.example.com`, and not `example.com` itself. [RFC 9525 wildcard rules](https://www.rfc-editor.org/rfc/rfc9525#section-6.3)
-   **Aliases are not followed.** The client checks the name it used to open the connection. RFC 9525 builds the reference identifier from the client's inputs or its configuration, and the older rule quoted in RFC 6125's prior-art appendix says it plainly: CNAME canonicalization is not done. A CNAME from `orders.example.internal` to a load balancer's own name still needs `orders.example.internal` in the certificate. [RFC 9525 reference identifiers](https://www.rfc-editor.org/rfc/rfc9525#section-6.1) · [RFC 6125 Appendix B.1](https://www.rfc-editor.org/rfc/rfc6125#appendix-B.1)

## See which name and which certificate

First find the exact name the client uses: the host part of the URL or connection string in the service's configuration, after any environment substitution. Then resolve it the way the service does, and see whether it is an alias. [dig](https://bind9.readthedocs.io/en/latest/manpages.html#dig-dns-lookup-utility)

```
dig +short orders.example.internal
dig +short CNAME orders.example.internal
```

Fetch the certificate the server presents for that name and print its SAN list. Set `-servername` to the same name, so the server picks the certificate it would pick for your client. `-checkhost` tests one name against the certificate and prints whether it matches. [openssl s\_client](https://docs.openssl.org/3.0/man1/openssl-s_client/) · [openssl x509 -ext and -checkhost](https://docs.openssl.org/3.0/man1/openssl-x509/)

```
openssl s_client -connect orders.example.internal:443 -servername orders.example.internal \
  </dev/null 2>/dev/null > served.txt
openssl x509 -in served.txt -noout -subject -ext subjectAltName
openssl x509 -in served.txt -noout -checkhost orders.example.internal
```

`openssl x509` reads the first certificate in `served.txt`, which is the leaf. If the client connects by address, use `-checkip 10.0.4.17` in place of `-checkhost`.

curl shows the same comparison in one step. With `-v` it prints `subjectAltName:` lines that say which entry matched, or `subjectAltName does not match` before the error. [curl OpenSSL backend](https://github.com/curl/curl/blob/master/lib/vtls/openssl.c)

```
curl -v -o /dev/null https://orders.example.internal/ 2>&1 | grep -E 'subject:|subjectAltName|no alternative'
```

If the SAN list on the served certificate looks like another service's, the server may have returned its default certificate. Repeat the s\_client call with and without `-servername` and compare: [SNI and the default certificate](/learn/tls-sni-default-certificate/).

## Read the result

| Client uses | SAN list shows | Points to |
| --- | --- | --- |
| An IP address | DNS names only | Connect by a name in the SAN list |
| An alias (CNAME) | Only the target's name | Alias missing from the certificate |
| `a.b.example.com` | `*.example.com` | Wildcard covers one label |
| The right name | Another service's names | Default or wrong certificate served |
| The right name | The right name | Client checks a different name; read its config |

The last row happens when a library or proxy sets the verify name separately from the connect address, for example a client that connects to an address from service discovery and verifies against a configured name.

## A worked example with two outcomes

This example is illustrative. After a configuration change, `checkout` fails every call to the orders API.

In the first outcome, the new configuration sets `ORDERS_URL=https://10.0.4.17/`, an address copied from a dashboard. The certificate's SAN list is `DNS:orders.example.internal`. Go prints `x509: cannot validate certificate for 10.0.4.17 because it doesn't contain any IP SANs`. Restoring the name fixes it; the certificate is correct.

In the second outcome, the configuration says `https://eu.orders.example.internal/`, a new regional name that is a CNAME to the same load balancer. The certificate covers `orders.example.internal` and `*.example.internal`. The wildcard covers one label, so `eu.orders.example.internal` is not covered. The orders team adds the regional name to the certificate, or `checkout` keeps the name the certificate covers.

## Limits

The s\_client check uses your resolver and network path. A service that resolves the name differently, through a split-horizon zone or a stale cache, may reach a different endpoint with a different certificate; check the address the service actually connected to. [Split-horizon DNS answers](/learn/split-horizon-dns-wrong-answer/)

Some clients let configuration override the name used for verification, and some proxies re-originate TLS with their own name. A clean check from the host does not prove what the service sent. A chain the client cannot complete fails with another message: [unable to get local issuer certificate](/learn/tls-unable-to-get-local-issuer/). For other layers, see the [hub for runtime dependency failures](/learn/runtime-dependency-failures/).

## Questions

### Does a certificate for example.com also cover [www.example.com](http://www.example.com)?

Only if `www.example.com` or `*.example.com` is in its SAN list. A name and its subdomains are separate identities, and the wildcard does not cover the bare domain.

### Can I put an IP address in a certificate?

Yes, as an `iPAddress` entry in the subject alternative name extension, and the address must match exactly, with no network-level matching. Calling by name is easier to keep working when addresses change.

### Why does the browser show a different certificate than my service gets?

The browser may send a different SNI name, reach a different endpoint through its own DNS, or go through a proxy. Compare the subject and SAN list from the service's network position with the one the browser shows.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Why does my client get the wrong certificate from a shared endpoint?](/learn/tls-sni-default-certificate/)
    
    Network outages The Proofline team November 23, 2026 5 min read
    
-   ### [Unable to get local issuer certificate: server chain or client trust?](/learn/tls-unable-to-get-local-issuer/)
    
    Network outages The Proofline team November 23, 2026 5 min read
