13. The TLS Handshake

Every piece snapping together

Every time you see the padlock icon in your browser, TLS (Transport Layer Security) is at work. It combines everything from the previous pages — symmetric ciphers (AES), key exchange (ECDHE), digital signatures (ECDSA), hash functions (SHA-256), certificates — into a single protocol that negotiates a secure connection in milliseconds. This page shows how all the pieces fit together.

What TLS Provides

TLS isn't a single algorithm. It's a framework that orchestrates several cryptographic primitives to deliver four guarantees simultaneously:

  1. Confidentiality

    Encryption — nobody can read the data. After the handshake, all traffic is encrypted with AES (or ChaCha20), so an eavesdropper on the network sees only ciphertext.

  2. Integrity

    MACs — nobody can tamper undetected. Every record includes an authentication tag (via GCM or Poly1305). If a single bit is flipped in transit, the receiver detects it and drops the connection.

  3. Authentication

    Certificates — you know who you're talking to. The server proves its identity with an X.509 certificate signed by a trusted Certificate Authority.

  4. Forward Secrecy

    Ephemeral keys — past sessions stay safe. Each connection uses a fresh ECDHE key pair. Even if the server's long-term private key is later compromised, previously recorded traffic cannot be decrypted.

TLS 1.3 Handshake: Step by Step

This is the core of TLS — the choreography that turns a raw TCP connection into an encrypted channel. Every step builds on concepts from earlier pages.

  1. ClientHello

    The client opens with a single message containing: the supported TLS versions, a list of supported cipher suites (e.g., TLS_AES_256_GCM_SHA384), supported key exchange groups (e.g., x25519, P-256), a random nonce (32 bytes), and — crucially — the client's ECDHE public share via the key_share extension.

    This is the key improvement in TLS 1.3. In TLS 1.2, the client waited for the server to pick a group before sending its key share, adding an entire round trip. TLS 1.3 sends it speculatively in the first message.

  2. ServerHello

    The server picks a cipher suite and key exchange group from the client's offered list, then sends back its own ECDHE public share and a random nonce.

    At this point, both sides have each other's ECDHE public shares. Both can independently compute the shared secret via elliptic curve Diffie-Hellman — the same operation described on the ECC page.

  3. Server Parameters and Authentication

    The server now sends several messages, all encrypted with handshake keys derived from the ECDHE shared secret:

    • EncryptedExtensions — additional server parameters (ALPN, etc.)
    • Certificate — the server's X.509 certificate chain
    • CertificateVerify — a digital signature (ECDSA or Ed25519) over the entire handshake transcript so far, proving the server holds the private key matching the certificate
    • Finished — a MAC over the handshake transcript, confirming nothing was tampered with
  4. Client Verification

    The client verifies the certificate chain (is it signed by a trusted CA?), checks the signature in CertificateVerify (does the server really own this certificate?), then sends its own Finished message — a MAC proving the client saw the same handshake transcript.

  5. Application Data

    The handshake is complete. Both sides derive application traffic keys from the shared secret, and all subsequent data flows encrypted with those keys. The entire handshake took just one round trip.

TLS 1.3 Handshake Flow

  Client                                       Server
    │                                             │
    │─── ClientHello ───────────────────────────> │
    │    (versions, ciphers, key_share, nonce)    │
    │                                             │
    │ <──────────────────────── ServerHello ───── │
    │    (cipher, key_share, nonce)               │
    │ <──────────── {EncryptedExtensions} ─────── │
    │ <──────────── {Certificate} ─────────────── │
    │ <──────────── {CertificateVerify} ───────── │
    │ <──────────── {Finished} ────────────────── │
    │                                             │
    │─── {Finished} ─────────────────────────────>│
    │                                             │
    │ <═══════ Application Data (encrypted) ═════>│
    │                                             │

{ } = encrypted with handshake keys
═══ = encrypted with application keys</code></pre>

The Cipher Suite

Decoding TLS_AES_256_GCM_SHA384

TLS_AES_256_GCM_SHA384
 │    │   │   │
 │    │   │   └── SHA-384: hash used for key derivation (HKDF)
 │    │   └────── GCM: Galois/Counter Mode (authenticated encryption)
 │    └────────── AES-256: symmetric cipher, 256-bit key
 └─────────────── TLS: the protocol

In TLS 1.3, the cipher suite only specifies the symmetric encryption and hash. Key exchange is negotiated separately — and it's always some form of ECDHE (or its post-quantum successors). This is simpler than TLS 1.2, which bundled everything into the cipher suite name, creating hundreds of combinations.

TLS 1.3 supports exactly five cipher suites. No export ciphers, no RC4, no DES, no CBC mode without AEAD. The attack surface shrank dramatically.

Key Derivation: HKDF

The ECDHE shared secret isn't used directly

TLS derives multiple keys using HKDF (HMAC-based Key Derivation Function). From the single ECDHE shared secret, HKDF produces:

  • Handshake traffic keys — used to encrypt the rest of the handshake
  • Application traffic keys — used to encrypt actual data
  • Separate keys for client→server and server→client — so traffic in each direction uses different keys
  • Separate keys for encryption and MAC — so compromising one doesn't compromise the other

This is called key separation. Even though everything stems from one shared secret, each derived key serves a single purpose. If any individual key were somehow leaked, the others would remain safe.

1-RTT: Why TLS 1.3 Is Fast

TLS 1.2: 2 Round Trips

1. ClientHello → ServerHello
2. Client key exchange → Server finished
Then application data begins.

The client couldn't send its key share until the server picked a group. This added a full round trip before any encryption could start.

TLS 1.3: 1 Round Trip

1. ClientHello (with key share) → ServerHello + encrypted messages
Then application data begins.

By sending the ECDHE key share in the first message, TLS 1.3 eliminates the extra round trip. The connection is ready after just one exchange.

0-RTT Resumption

TLS 1.3 also supports 0-RTT (zero round trip) resumption: if the client has connected to this server before, it can send encrypted application data in the very first message, alongside the ClientHello. The server can process it immediately.

The caveat: 0-RTT data is vulnerable to replay attacks. An attacker who records the first message can resend it, and the server may process it again. For this reason, 0-RTT should only be used for idempotent requests (like GET), never for actions that change state (like a bank transfer).

Certificate Verification

When the server sends its certificate, the client doesn't just accept it. It runs a gauntlet of checks:

  1. Chain of Trust

    Is the certificate signed by a trusted Certificate Authority? The client walks up the chain — server cert → intermediate CA → root CA — verifying each signature until it reaches a root certificate in its trust store.

  2. Expiration

    Is the certificate still within its validity period? Certificates have a notBefore and notAfter date. Expired certificates are rejected.

  3. Hostname Match

    Does the certificate's Subject Alternative Name (SAN) match the hostname the client is trying to reach? A valid certificate for example.com won't be accepted when connecting to evil.com.

  4. Revocation

    Has the certificate been revoked? The client checks via OCSP (Online Certificate Status Protocol) or CRL (Certificate Revocation List) to ensure the CA hasn't withdrawn its trust.

If any of these checks fails, the connection is aborted. That's the error you see when your browser warns you about an insecure site.

What an Eavesdropper Sees

Plaintext (visible to anyone on the network)

ClientHello:
  - Supported TLS versions
  - Supported cipher suites
  - Client's ECDHE public share
  - SNI: "www.example.com"   ← the hostname you're visiting

ServerHello:

  • Chosen cipher suite
  • Server's ECDHE public share

Encrypted (invisible to eavesdroppers)

  - Server certificate (which specific certificate)
  - HTTP request headers and body
  - HTTP response headers and body
  - All application data
  - Session tickets

Notice the SNI (Server Name Indication): the client tells the server which hostname it wants in plaintext, because the server may host multiple sites and needs to know which certificate to present — before encryption begins.

This means an eavesdropper can see which site you're connecting to, even if they can't see what you're doing there. This is why ECH (Encrypted Client Hello) is being developed — it encrypts the SNI using a key published in DNS, hiding even the destination hostname.

TLS 1.3 vs TLS 1.2

Feature TLS 1.2 TLS 1.3
Round trips to first data 2-RTT 1-RTT (0-RTT for resumption)
Cipher suites Hundreds (many insecure) 5 (all secure)
Forward secrecy Optional (often skipped) Mandatory (always ECDHE)
RSA key exchange Allowed (no forward secrecy) Removed entirely
0-RTT resumption Not supported Supported (with replay caveats)
Record encryption Various (CBC, RC4, AEAD) AEAD only (GCM, ChaCha20-Poly1305)
Compression Supported (vulnerable to CRIME) Removed
Renegotiation Supported (complex, attack-prone) Removed

The theme is clear: TLS 1.3 removed everything that had ever been a source of vulnerabilities. Fewer options means fewer things to get wrong.

Common TLS Attacks (and How TLS 1.3 Prevents Them)

Attack What it exploited TLS 1.3 mitigation
BEAST Predictable IVs in CBC mode CBC removed — AEAD only
POODLE SSLv3 fallback with CBC padding SSLv3 and all non-AEAD ciphers removed
Heartbleed Implementation bug in OpenSSL's heartbeat extension Not a protocol flaw — fixed in OpenSSL; heartbeat extension removed
DROWN SSLv2 cross-protocol attack on RSA key exchange SSLv2 and RSA key exchange both removed
Downgrade attacks Forcing use of weaker protocol versions Handshake transcript hash prevents tampering; downgrade sentinel in ServerHello random
CRIME / BREACH TLS-level compression leaking plaintext TLS compression removed entirely

TLS in the Real World

TLS isn't just for web browsers. It secures almost every networked communication you rely on:

  • HTTPS — every web page loaded over a secure connection
  • Email — SMTP and IMAP with STARTTLS, ensuring messages are encrypted between mail servers and between your client and server
  • Database connections — PostgreSQL, MySQL, and others support TLS to protect queries and results in transit
  • API calls — REST, gRPC, and GraphQL endpoints almost universally require TLS
  • VPN protocols — OpenVPN runs over TLS; WireGuard uses a similar handshake pattern with Noise protocol
  • Container orchestration — Kubernetes uses mutual TLS (mTLS) between services in a cluster

Try It Yourself — TLS 1.3 Handshake Stepper

Step through a TLS 1.3 handshake message by message. See what each step contains, which cryptographic primitives it uses, and when encryption kicks in. Click any step in the timeline or drag the slider.

Step 1 / 9: ClientHello

Cipher Suite Decoder

TLS 1.3 supports exactly five cipher suites. Pick one to see each component decoded with its role in the protocol.

What an Eavesdropper Sees

An attacker on the network can intercept every packet. Here is exactly what they can and cannot learn from a TLS 1.3 connection.

Key Takeaways

  • TLS combines symmetric encryption, key exchange, digital signatures, and certificates into one protocol
  • The TLS 1.3 handshake completes in a single round trip — the client sends its ECDHE key share immediately
  • HKDF derives multiple independent keys from the shared secret, ensuring key separation
  • Certificate verification checks the chain of trust, expiration, hostname, and revocation status
  • TLS 1.3 removed everything that caused past vulnerabilities: CBC, RSA key exchange, compression, renegotiation
  • Forward secrecy is mandatory — every connection uses ephemeral ECDHE keys
  • The SNI still leaks the destination hostname; ECH is the emerging fix

TLS is where all of cryptography comes together. The symmetric ciphers provide speed, the asymmetric primitives provide trust, and the protocol design ensures they work in concert — securely, efficiently, and without requiring users to understand any of it. The padlock in your browser represents thousands of person-years of cryptographic research, distilled into a handshake that completes before you even notice it happened.