TLS verification basics
Local practice: Node.js 22.16.0 on Linux x64; proposed 26.13.1 baseline remains untested. Save each example separately as main.mjs in a disposable directory. No packages or external services required. HTTP examples bind only to loopback and shut down after a finite scenario. Static Node.js code, not verified ByteMind execution.
Match a synthetic DNS name
import { checkServerIdentity } from 'node:tls';const cert={subjectaltname:'DNS:catalog.example.test'};console.log(checkServerIdentity('catalog.example.test',cert)===undefined);Run:
node main.mjsExpected stdout:
trueExit status: 0. Expected stderr: empty.
How it works
Certificate validation checks whether the presented chain is trusted, is valid for the relevant time and satisfies applicable policy. Hostname checks compare the requested name with certificate identifiers. The examples use synthetic certificate-shaped objects to demonstrate only the hostname-checking function. They do not validate a signature, establish trust, or run a TLS handshake. In a real deployment, diagnose clock, trust roots, certificate chain and name configuration before changing anything. Use an approved CA for a private lab.
Reject an unrelated DNS name
import { checkServerIdentity } from 'node:tls';const cert={subjectaltname:'DNS:catalog.example.test'};console.log(checkServerIdentity('billing.example.test',cert).code);Run:
node main.mjsExpected stdout:
ERR_TLS_CERT_ALTNAME_INVALIDExit status: 0. Expected stderr: empty.
Common mistake
Never disable certificate verification to make a connection succeed. A matching hostname alone does not establish a trusted certificate or authorize an application user.
Practice
Predict what happens if a certificate lists DNS:catalog.example.test but the client requests billing.example.test. Explain what this check cannot establish.
Further reading: Authoritative source 1. Internal reference routes remain proposed until repository discovery.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
TLS verification basics — knowledge check
Apply the concepts and predict the behavior taught in this lesson.
What does the synthetic hostname check prove?
What is the safe response to a certificate error?
Does successful TLS replace application authorization?