Lesson 9 of 9 · 26m
Debugging TLS Failures Without Guesswork
A repeatable triage method for handshake failures: reproduce with controlled tools, capture the exact error, isolate layers, and test chain, names, time, protocol, and client trust separately.
TLS errors are written for machines and then shown to humans as if they were helpful. certificate unknown, handshake failure, EOF, and bad certificate hide more than they reveal. The correct response is not to toggle verification off. It is to narrow the failing layer.
First rule: do not disable verification
curl -k, NODE_TLS_REJECT_UNAUTHORIZED=0, and InsecureSkipVerify: true are diagnostic traps. They can tell you whether the application works when identity validation disappears, but they must never become the fix.
Build the failure ladder
Test in order: DNS resolves to the intended IP, TCP connects, TLS starts with correct SNI, the server presents the expected chain, the chain validates in the client's trust store, hostname matches SAN, protocol and cipher overlap exists, mTLS requirements are satisfied, and only then application protocol behavior.
Do not jump to the application because its log says connection reset.
Use controlled clients
openssl s_client -connect api.internal:443 -servername api.internal -CAfile internal-root.pem -verify_hostname api.internal -briefThe output often tells you where validation stopped. curl is useful when you need HTTP behavior:
curl -v --cacert internal-root.pem https://api.internal/healthCompare runtimes deliberately. If Go fails and openssl succeeds, suspect trust-store or policy differences. If Java fails alone, suspect a Java keystore or constraints. If everything fails intermittently, suspect multiple backends behind a load balancer serving different certificates.
Decode common errors
certificate has expired or is not yet valid means the dates do not validate, but the clock may be wrong on either side. unable to get local issuer certificate usually means a missing intermediate or wrong CA bundle. Hostname errors mean validation reached a trusted chain but the SAN is wrong. Bare handshake failure often means no protocol overlap, the wrong certificate/key pair, or middlebox interference. In mTLS, bad certificate often means the server rejected the client certificate; server logs are usually more specific.
Look on the wire when abstraction lies
tcpdump -i eth0 -n host 10.20.3.14 and tcp port 443 -w tls.pcapYou do not need to decrypt traffic for most handshake failures. The ClientHello shows SNI and supported versions. The ServerHello, Certificate message, and TLS alerts show where negotiation stopped.
A virtual IP can hide ten backends with one stale certificate. Probe through the service as clients do, then probe individual backends when behavior is intermittent. In Kubernetes or a mesh, check sidecar or gateway certificates separately from application certificates.
Capture the exact client output, served chain, dates and serials, runtime version, trust-store mechanism, backend IP, and UTC timestamps. Most retrospectives fail because the evidence was replaced by the fix.
Field notes
- Always include
-servernamewhen testing shared TLS listeners. - IPv4 and IPv6 can route to different stacks with different certificates.
- Verify where TLS termination actually occurs; proxies are often invisible in diagrams.
- The fix is complete only when the original unmodified client succeeds, not when
curl -ksucceeds.
Was this lesson helpful?