Lesson 8 of 13 · 24m
TLS in Practice: What the Handshake Buys and Where It Ends
TLS 1.3's ephemeral-exchange-plus-signature construction, what a certificate proves, and where plaintext hops hide in your stack.
Your Node app almost never terminates TLS. There's an Nginx, a load balancer, or a CDN in front speaking plain HTTP/1.1 to your process on a private port — which means the TLS that matters is configured in infrastructure you're not looking at. What that layer does in ~two round trips is the most-deployed cryptographic protocol on earth, and the mental model "TLS encrypts traffic" skips the part that actually protects you.
What a TLS 1.3 handshake actually does
TLS 1.3 (RFC 8446, August 2018) compresses setup into one round trip:
- Client sends
ClientHellowith an ephemeral X25519 public key and the cipher suites it supports. - Server replies with its own ephemeral public key and a certificate, then signs the handshake transcript with its private key.
- Both sides run the ECDH exchange, feed the shared secret through HKDF with the transcript mixed in, and derive the record keys.
- Every subsequent record is AEAD-encrypted under one of the five cipher suites RFC 8446 defines. Three are what every real stack negotiates — AES-128-GCM, AES-256-GCM, ChaCha20-Poly1305. The other two, AES-128-CCM and the short-tag AES-128-CCM_8, exist for constrained devices and almost never appear on the web.
Three primitives you already know, assembled: X25519 for agreement, a signature for authentication, AEAD for the wire. The forward secrecy is the ephemerals — the private key only ever signs; it never decrypts recorded traffic, so stealing it later can't rewind yesterday's captures. TLS 1.2 and earlier allowed RSA key transport that did exactly that; 1.3 deleted it.
What the certificate actually proves
The wrong mental model: "the cert makes it encrypted." The cert does nothing to encryption — it proves identity. A CA (Let's Encrypt, DigiCert, whoever's in your trust store) attested that the holder of this private key controls api.example.com. Without that binding, your client happily completes a secret handshake with whoever answers the socket — an ISP, a captive portal, a MITM. The signature on the transcript is what makes the handshake authenticated key exchange instead of anonymous DH.
A self-signed cert gives you the encryption and none of the proof — a MITM just presents their own. That's fine for service-to-service inside a network you control if you pin or distribute the expected key; it's a hole on the public internet.
Where TLS really terminates in your stack
# The standard shape — TLS ends here, plaintext inside:
server {
listen 443 ssl;
server_name api.example.com;
ssl_certificate /etc/letsencrypt/live/api.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
location / {
proxy_pass http://127.0.0.1:3000; # plain HTTP to the app
}
}The last hop is plaintext on 127.0.0.1 — fine on one box. On a multi-host VPC, that plaintext crosses a network your cloud provider controls; that's why mTLS service meshes exist. mTLS is just the same handshake with a client certificate too — both sides prove identity. Whether it's worth the certificate-lifecycle pain depends on your blast radius; on one host it's complexity for nothing.
The failures that ship
- Old versions left on.
ssl_protocolsstill listing TLS 1.0 or 1.1 for "compatibility" exposes protocol-downgrade and the 1.0-era attack surface — BEAST, POODLE, everything RFC 8996 deprecated in 2021. 1.2 + 1.3 is the sane floor in 2026. - Certificate expiry. Let's Encrypt's 90-day certs exist because operators forgot to renew; ACME automation (
certbot,acme.sh, Caddy doing it in-process) is the fix, not a calendar reminder. - HTTP that never upgrades. Serving 80 → 443 redirect without HSTS leaves the first request — and every future cookie — readable on the wire.
Strict-Transport-Security: max-age=31536000; includeSubDomainsafter you've verified HTTPS everywhere. - Session resumption subtleties. TLS 1.3's 0-RTT resumption trades replay-safety for speed — a replayed early request can be executed twice. Keep 0-RTT off for any endpoint that isn't idempotent.
Field notes
- Check what's actually negotiated:
openssl s_client -connect api.example.com:443 -tls1_3andcurl -vI https://...— read theTLSv1.3and cipher line. - Cert pinning in mobile apps trades operational safety for MITM resistance — a pinned cert you can't rotate locks users out. Pin sparingly, always with a backup pin.
- Certificate Transparency logs (every publicly-trusted cert lands in them —
crt.sh) are the cheapest way to watch for rogue certs issued for your domains. - Debugging your own traffic? Set
SSLKEYLOGFILEand browsers plus OpenSSL write the session keys Wireshark needs to decrypt your TLS — the honest way to see what the handshake actually negotiated. - The padlock means "authenticated and encrypted to whoever holds the cert." It says nothing about whether that site is trustworthy — phishing sites get Let's Encrypt certs too.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Implementing RSA, AES-GCM, and a TLS 1.3 Handshake from Scratch in Python
RSA Is Simple. Deploying RSA Correctly Almost Never Is.
The capstone to our RSA series. The math checks out. Shipping it as written gets you breached. This is the nineteen-year-old attack that proves it, and what belongs in production instead.
Timing Attacks on RSA in Python
In case you haven't read former 2 articles on this topic, below are the links: Side-channel attacks The first 2 articles focused mainly on the idea and implementation of RSA. As such they left out a relevant topic in modern encryption. Side-channel attacks take advantage of data we'd usually…
RSA Part 3: Your Correct Implementation Still Leaks the Key
Key generation works, encryption round-trips, the math is provably right — and an attacker can still recover the private key by timing your decryptions. Here are both defenses, measured, with what they actually cost.