TLS and HTTP
What a TLS handshake verifies, why a correct certificate can fail on one client, and what HTTP status codes say about where a failure is.
What TLS proves
TLS gives a client three guarantees: the bytes are encrypted, they are not modified in transit, and the server holds the private key for a certificate that a trusted authority issued for the name the client asked for. To establish the last one, the client checks:
- Chain: the certificate links through intermediates to a root in the client's trust store.
- Name: the requested hostname matches one of the certificate's subject alternative names.
- Validity: the current time is between
notBeforeandnotAfter, according to the client's clock. - Optionally, revocation, through OCSP or CRLs.
Each check fails with its own message, and the message names the part of the system to look at. "Unable to get local issuer certificate" means a missing intermediate or a trust store problem. "Hostname mismatch" means you connected by a different name than the certificate covers. "Expired" or "not yet valid" mean the dates disagree with someone's clock.
The clock is part of the trust decision
Because validity is judged by the client's clock, a client whose clock is wrong by days sees a perfectly good certificate as expired or not yet valid. The giveaway is scope. One site or one class of device fails, everyone else succeeds, and the certificate's dates are fine when checked from a correct machine. Look at timedatectl or the device's NTP configuration, not at the certificate. The same skew breaks other time-based security too: Kerberos tickets, signed URLs, and one-time codes.
Looking at a handshake
openssl s_client -connect 10.0.4.12:443 -servername tracking.northstar.example -showcerts </dev/null
openssl s_client -connect ... </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltName
curl -v --resolve tracking.northstar.example:443:10.0.4.12 https://tracking.northstar.example/health
-servername sends SNI, without which a server hosting several names may return a default certificate and mislead you. curl --resolve pins the address while keeping the right name, which is the clean way to test one backend.
Latency is a protocol property
HPBN's central lesson for operators is that round trips are expensive. TCP's handshake costs one round trip, and a full TLS 1.2 handshake adds two more (TLS 1.3 adds one, or none on resumption). A proxy that does not reuse upstream connections, or clients that never resume sessions, pay this on every request. When latency is high but servers are idle, count handshakes before tuning code.
Reading HTTP status codes as locations
Status codes are produced by whichever component answered:
- 2xx/3xx: the request reached something that handled it.
- 4xx: the server judged the request wrong, for example 404, 401/403, or 429 (rate limiting).
- 500: the application itself failed.
- 502 Bad Gateway: a proxy got no valid response from its upstream (connection refused, reset, or garbage).
- 503 Service Unavailable: overload, maintenance, or a proxy with no healthy backends.
- 504 Gateway Timeout: a proxy waited for its upstream and gave up.
A 502 or 504 tells you the request crossed the proxy successfully. The fault is behind it. That one fact halves the search, and the notes on proxies build on it.
Key terms
- Certificate chain
- The server certificate plus intermediates, leading to a root the client already trusts.
- SNI
- Server Name Indication. The client sends the hostname in the handshake so one IP address can serve several certificates.
- Validity period
- The
notBeforeandnotAfterdates. Clients compare them with their own clock. - 502 / 504
- Status codes generated by a proxy or gateway: 502 means the upstream gave an invalid response or none, and 504 means the upstream did not answer in time.
Read further
- High Performance Browser Networking, Ch. 4, "Transport Layer Security (TLS)" (Free to read online)
The handshake and its round trips, the chain of trust and certificate authorities, SNI, session resumption, and OCSP and revocation. Note exactly what the client checks. - High Performance Browser Networking, Ch. 9, "Brief History of HTTP", and Ch. 11, "HTTP/1.X" (Free to read online)
The request/response model, keep-alive, and why one connection per request is costly. Skim the browser optimisation advice. - TCP/IP Illustrated, Volume 1, 2nd edition, Ch. 18, "Security — EAP, IPsec, TLS, DNSSEC, and DNS Security" (Purchase)
The TLS section, for certificate structure and the handshake at the protocol level.