The SAN Names the Host
A certificate names the hosts it is for in its Subject Alternative Name; a name matches label by label without regard to case, a wildcard is a whole left-most label that stands for exactly one label, and this OpenSSL also falls back to the Common Name when there is no SAN.
The question
A browser or a program that opens a connection to shop.example.test has to decide whether the certificate it is shown is for that host. Where in the certificate does it look, how does it compare the names, and what does a * stand for?
The certificates of this book are test material, made for the lessons with 512-bit RSA keys, a toy size far too small to use. The hosts end in .test or .example.
Work it by hand
The host names are in the Subject Alternative Name extension as entries of type dNSName. RFC 9525, section 6.3, says that the names are compared label by label, with a case-insensitive ASCII comparison, so WWW.Example.Test and www.example.test match. A label is the text between two dots.
The same section says that a wildcard * is allowed only as the complete content of the left-most label, with only one wildcard in the name. A wildcard in a presented identifier can only match one label. So *.example.test is for a.example.test, which has one label in front of example.test, but not for a.b.example.test, which has two, and not for example.test, which has none. An identifier such as w*.example.test does not meet the requirements and MUST be ignored.
Run it
The demo is one command (line 3): x509 -in in/cert.txt -noout -ext subjectAltName -checkhost a.example.test prints the SAN of the test certificate wild and then says whether the host a.example.test matches. Its output has three lines: the extension name, DNS:*.example.test, DNS:shop.example.test, and Hostname a.example.test does match certificate.
You can change the host name or the certificate. A host that does not match makes the command end with exit status 1: measured, a.b.example.test gives Hostname a.b.example.test does NOT match certificate, and the page then shows a failure.

Public test material, generated for this lesson. Never use it for anything real.
# Prints the SAN of the certificate and checks a host name against it.
# Check runs it with other certificates in in/cert.txt.
x509 -in in/cert.txt -noout -ext subjectAltName -checkhost a.example.test
{
"answer": "X509v3 Subject Alternative Name: \n DNS:*.example.test, DNS:shop.example.test\nHostname a.example.test does match certificate"
}Your turn
The program below should decide, by the rules of RFC 9525 section 6.3 as described above, whether host is named by one of the entries of san, a list of dNSName entries separated by commas, with optional spaces around the entries. It returns true or false. An empty san names no host. Judge it, and find the candidates that are right for every input. Check runs each candidate on the data shown and on sixteen others.

Public test material, generated for this lesson. Never use it for anything real.
let want = host;
let entries = str_split(san, ",");
let answer = false;
let labels = str_split(want, ".");
for (i in range(0, entries.len())) {
let p = str_split(str_trim(entries.at(i)), ".");
if (p.len() == labels.len()) {
let same = true;
for (k in range(0, p.len())) {
let star = k == 0 && p.at(0) == "*";
if (p.at(k) != labels.at(k) && !star) { same = false; }
}
if (same) { answer = true; }
}
}
{
"answer": false
}san is a list of dNSName entries separated by commas, with optional spaces around each. host is a host name. Return true if one entry names the host: the entry equals the host label by label, ignoring letter case, or the entry starts with a label that is only * and the other labels equal the host's labels, the host having exactly as many labels as the entry. An entry that has * anywhere else is ignored. Return false otherwise, also for an empty san.
Read the result carefully
RFC 9525, section 2, says the Common Name MUST NOT be used to identify a service. This build of OpenSSL does something else when a certificate has no SAN: measured with openssl verify -attime 1790000000 -verify_hostname on the test certificate cnonly, which has a Common Name and no SAN, the name cn-only.example.test is accepted and another name fails with error 62 ... hostname mismatch; the engine's own host check gives the same two answers.
This page reports what this build does and what the RFC says, and does not call either one the rule of TLS.
A second difference, measured with x509 -checkhost and with the engine's host check on scratch test certificates that are not part of this book: both accept an entry with letters before the * for a host that fits it, while RFC 9525, section 6.3, says such an identifier is invalid and MUST be ignored. The exercise follows the RFC, so it cannot predict this build there.
The exercise follows the RFC rules for the SAN only. It handles ASCII names, not internationalized ones, IP addresses or a trailing dot.
Recap
- A certificate names its hosts in the SAN, as dNSName entries; names match label by label, ignoring case (RFC 9525, section 6.3).
- A wildcard is the whole left-most label and matches exactly one label: one, not none and not several.
- A wildcard anywhere else in the name makes the identifier invalid, and it is ignored.
- RFC 9525, section 2, says not to use the Common Name; this OpenSSL still uses it when there is no SAN.