An Untrusted Root
A client trusts the certificates it was given, not the names on them. A look-alike root with the same subject name but another key is not the root the chain ends in, so the client refuses with alert 48, unknown_ca.
The question
A client checks that the chain the server sends ends in a certificate it trusts. What does it trust, a name or a key? To find out, give the client a root that carries the same name as the real one and see whether it is accepted.
Both ends are test endpoints in this tab's memory, made with ssl.tls_pair. The server holds the test leaf, the test intermediate and the test key. The client is given its trusted root with add_ca. The look-alike root is a test certificate made for this lesson, with the same subject name as the real test root and another key.
Work it by hand
The chain the server sends is a leaf signed by an intermediate, and the intermediate is signed by the test root. The client must end the chain in a certificate it was given. The certificate it holds names the same issuer that the intermediate names, but whether it is the same issuer depends on the key: the intermediate's signature was made with the key of the real root, and the look-alike has another key (stated here from the notes of the test material, not run by the page).
So the chain does not end in anything trusted. The client refuses and sends an alert. RFC 9846 section 6.2 describes unknown_ca as "A valid certificate chain or partial chain was received, but the certificate was not accepted because the CA certificate could not be located or could not be matched with a known trust anchor." That is alert 48, and this build sends it here.
Run it
Lines 1 to 5 build the pair as in the first lesson, with root_pem as the only trusted root. The loop of lines 7 to 11 lets the ends take turns and keeps the last flight with bytes; lines 12 to 14 read the alert number from it if it is a 7-byte alert.
Lines 15 and 16 return the subject of the root you gave and the issuer named by the intermediate. Lines 17 and 18 return the alert bytes and verify_result(). Line 19 returns the name the server saw and the alert number.

Public test material, generated for this lesson. Never use it for anything real.
let server = ssl.server_ctx(ssl.parse_cert(leaf_pem), ssl.parse_key(leaf_key));
server.chain(ssl.parse_cert(int_pem)); server.groups("X25519");
let client = ssl.client_ctx(); client.add_ca(ssl.parse_cert(root_pem));
client.groups("X25519");
let pair = ssl.tls_pair(client, server, host);
let turns = 0; let flights = 0; let last = "";
while (!pair.done() && pair.error() == "" && turns < 10) {
let flight = pair.step(); turns = turns + 1;
if (str_len(flight) > 0) { flights = flights + 1; }
if (str_len(flight) > 0) { last = str_hex_encode(flight); }
}
let code = 0 - 1; let alert = "";
let plain = hex_len(last) == 7 && hex_u8(last, 0) == 21;
if (plain) { code = hex_u8(last, 6); alert = last; }
lmcode_return_put("trusted_subject", ssl.parse_cert(root_pem).subject());
lmcode_return_put("issuer_wanted", ssl.parse_cert(int_pem).issuer());
lmcode_return_put("alert", alert);
lmcode_return_put("verify_result", pair.verify_result());
let answer = pair.server_name() + " " + str(code);
{
"answer": "www.example.test 48",
"trusted_subject": "O=Example Test Lab,CN=Example Test TLS Root CA",
"issuer_wanted": "O=Example Test Lab,CN=Example Test TLS Root CA",
"alert": "15030300020230",
"verify_result": "unable to get local issuer certificate"
}With the look-alike root and www.example.test the answer is www.example.test 48. The two names are the same text, O=Example Test Lab,CN=Example Test TLS Root CA, and the handshake still fails. What this OpenSSL build says: verify_result() is unable to get local issuer certificate, and the alert bytes are 15030300020230. These come from this run.
You can change host and root_pem. With the look-alike root the handshake is refused for any name that the certificate lists or does not list, and for www.example.testx too. When the name is also wrong, as with shop.example.test, the answer is still 48 and verify_result() still says unable to get local issuer certificate: in this build the root is checked before the name.
A name such as x, www.example.test. or one with a space stops line 5 with "Line 5: Ssl.tls_pair: set host to verify". A root text that is cut short stops line 3 with "Line 3: Ssl.parse_cert: not a PEM certificate: error:04800066:PEM routines::bad end line", and an empty one with "Line 3: Ssl.parse_cert: not a PEM certificate: error:0480006C:PEM routines::no start line".
Your turn
The program below should return the client's verdict as one of four words, from verify_result() after the handshake is done or has failed: ok, no trusted root for unable to get local issuer certificate, chain incomplete for unable to get issuer certificate, and wrong name for hostname mismatch. Decide whether it does, and find the candidates that do. Check runs each candidate on the data shown and on six others.

Public test material, generated for this lesson. Never use it for anything real.
let server = ssl.server_ctx(ssl.parse_cert(leaf_pem), ssl.parse_key(leaf_key));
server.chain(ssl.parse_cert(int_pem)); server.groups("X25519");
let client = ssl.client_ctx(); client.add_ca(ssl.parse_cert(root_pem));
client.groups("X25519");
let pair = ssl.tls_pair(client, server, host);
let turns = 0;
while (pair.error() == "" && turns < 2) {
let flight = pair.step(); turns = turns + 1;
}
let said = pair.verify_result(); let answer = "ok";
if (str_contains(said, "local issuer")) { answer = "no trusted root"; }
if (str_contains(said, "get issuer")) { answer = "chain incomplete"; }
if (said == "hostname mismatch") { answer = "wrong name"; }
lmcode_return_put("turns", turns);
{
"answer": "ok",
"turns": 2
}A client asks for the name host and trusts root_pem; the server holds leaf_pem, int_pem and leaf_key. Both ends are test endpoints in this tab's memory. Run the handshake, taking turns while it is not done and has no error, at most ten times. Then return one word from the client's verify_result(): ok when it says ok, no trusted root for unable to get local issuer certificate, chain incomplete for unable to get issuer certificate, and wrong name for hostname mismatch. Check runs each candidate on the data shown and on six others.
Read the result carefully
A real client has a store of roots that it did not choose in the page; here the page chose one certificate, and that is all the client trusts. The key, not the name, ties a chain to a root, and certificates like these are made with a CA's key, which a-small-certificate-authority shows. How a chain is checked is in a-certificate-chain-trusts-a-root.
The texts are what this OpenSSL build says, and another build words them differently. The certificates are valid from 2026-01-01 to 2036-01-01 and the client uses your clock, so the results hold only between those years. All certificates and keys are test material.
Recap
- The client trusts the certificates it was given with
add_ca; a root with the same name but another key is not the root of the chain. - The refusal is alert 48,
unknown_ca(RFC 9846 section 6.2), sent here as a 7-byte plaintext record. verify_result()tells the reasons apart; the alert does not.- The two names in the picture are equal: a name is not an anchor.