Opscraft
How SSL/TLS works · Lesson 3 of 8 · 4 min read

The TLS handshake step by step

TLS 1.2 (two round trips)

Enlarge diagramClientServerRound trip 1ClientHello: versions, ciphers, random, SNIServerHello, Certificate chain,ServerKeyExchange (signed), DoneRound trip 2ClientKeyExchange, ChangeCipherSpec, FinishedChangeCipherSpec, Finishedencrypted application data
Figure 1. The TLS 1.2 handshake takes two round trips before any application data can be sent.
Swipe sideways to see all of it, or tap to open it full screen.

Total before the first HTTP request on a fresh connection: 1 RTT for TCP + 2 RTTs for TLS 1.2 = 3 RTTs. Between Chennai and a US-East server (~230 ms RTT) that's ~700 ms before the request even leaves.

TLS 1.3 (one round trip)

Enlarge diagramClientServerRound trip 1ClientHello + key share, SNIServerHello + key share, then encrypted:Certificate, CertificateVerify, Finishedencrypted: Finished + the HTTP request
Figure 2. TLS 1.3 sends the key share in the very first message, so the handshake needs only one round trip, and most of it is already encrypted.
Swipe sideways to see all of it, or tap to open it full screen.

The client sends its key share in the first message, so keys are ready after one round trip. Improvements over 1.2:

  • 1-RTT handshake; 0-RTT resumption for returning clients (data in the first flight). 0-RTT data can be replayed by an attacker, so only allow it for idempotent requests (GET), which CDNs enforce.
  • Removed weak and legacy options: RSA key exchange, static DH, CBC-mode ciphers, RC4, SHA-1, compression, renegotiation.
  • Always forward secret; only five AEAD cipher suites (e.g. TLS_AES_128_GCM_SHA256, TLS_CHACHA20_POLY1305_SHA256).
  • More of the handshake is encrypted (the certificate is no longer visible to passive observers).

What the client verifies

  1. The chain leads to a trusted root and every signature is valid.
  2. The certificate is within its validity dates (clock skew on the client breaks this!).
  3. The hostname matches a SAN (exact or one-level wildcard).
  4. Key usage permits server authentication; not revoked (where checked).
  5. The server proved possession of the private key (CertificateVerify / signed key exchange).
Enlarge diagramChainleads to atrusted root;signatures validDatesnot expired, not"not yet valid"(clocks!)Namehostnamematches a SANUsageallowed forservers; notrevokedKey proofserver signed thehandshake withits private key12345
Figure 3. The five checks a client makes before it trusts a server. A failure in any one is a certificate error.
Swipe sideways to see all of it, or tap to open it full screen.

SNI and ALPN

  • SNI (Server Name Indication) — the client puts the hostname in the ClientHello so a server/load balancer hosting many domains on one IP can choose the right certificate. Clients that don't send SNI (old Java, some openssl commands without -servername) get the default certificate → name mismatch errors. ALBs support multiple certificates per listener selected by SNI.
  • ALPN — negotiates the application protocol (h2 for HTTP/2, http/1.1) inside the handshake.
Enlarge diagrambrowserClientHello · SNI:shop.example.comload balancerone IP, manycertificatesshop.example.compickedapi.example.comadmin.example.com
Figure 4. SNI: the client names the site it wants in the very first message, so one IP address can serve many certificates.
Swipe sideways to see all of it, or tap to open it full screen.

Session resumption

Full handshakes cost CPU (asymmetric crypto) and round trips. Session tickets / PSKs let a returning client resume with abbreviated handshakes — an important optimisation for load balancers handling many short connections. ECDSA certificates are also much cheaper to sign with than RSA 2048/4096, reducing server CPU.