What TLS does, and the handshake
TLSTLSTransport Layer Security: the protocol that encrypts and authenticates connections, as in HTTPS.Open in glossary → gives a connection three guarantees:
- Confidentiality: the data is encrypted; anyone in between sees random-looking bytes.
- Integrity: if someone changes even one bit on the way, the receiver notices and drops the connection.
- Authentication: the client knows it’s really talking to
shop.example, not to a fake server on the café Wi‑Fi. The server proves this with a certificate.
The last one is easy to forget and the most important. Encryption alone is useless if you’ve encrypted your password for an attacker.
Setting up these guarantees is the TLS handshake. In TLS 1.3, the current version, it takes one round trip:
client server
| -- ClientHello: TLS versions, ciphers, |
| hostname (SNI), my key share --------------> |
| |
| <-- ServerHello: chosen cipher, its key share, |
| certificate, signature proving it has the |
| private key, Finished ------------------------ |
| |
| -- Finished, then the HTTP request (encrypted) --> |The clever part is the key shares. Each side makes a temporary key pair and sends only the public half. From their own private half and the other’s public half, both sides calculate the same secret, which never travels over the network. Someone watching sees both public halves and still can’t compute it. That secret becomes the symmetric key that encrypts the rest of the connection.
The certificate and signature answer the other question: is the server whose key share I got really shop.example? Only the real server has the private key that matches the certificate, so only it can produce a valid signature over the handshake.
- TLS 1.3 (2018): 1-RTT handshake, 0-RTT resumption (replayable), only AEAD ciphers (AES-GCM, ChaCha20-Poly1305), only ephemeral (EC)DHE key exchange, so forward secrecy is mandatory; encrypted certificate; removed RSA key transport, CBC modes, compression and renegotiation. TLS 1.2 still needs 2 RTT and safe configuration; 1.0 and 1.1 are deprecated (RFC 8996).
- Key exchange: X25519 is the common default; browsers and Cloudflare now use the hybrid post-quantum X25519MLKEM768 by default, protecting today’s traffic from later decryption by quantum computers (“harvest now, decrypt later”). Larger key shares can push the ClientHello over one packet, which exposed broken middleboxes.
- Visible to observers: IP addresses and ports, the SNI hostname in the ClientHello (unless Encrypted Client Hello is used, still limited), DNS queries unless DoH/DoT, packet sizes and timing (enough to fingerprint pages or apps). Not visible: path, query string, headers, cookies, bodies.
- ALPN in the same handshake negotiates
h2orhttp/1.1; QUIC carries TLS 1.3 inside its own handshake. - Session resumption with tickets skips the certificate and signature on reconnects, saving CPU and bytes; ticket keys must rotate, or a stolen ticket key undermines forward secrecy for resumed sessions.
- Costs: handshake CPU (signatures, mostly ECDSA now) is small on modern hardware; the real cost is the round trip, which connection reuse removes.
Predict the output
A user on public café Wi-Fi opens the URL below over HTTPS. What can the café's network owner see?
https://shop.example/account/reset?token=8f2c91d4e7TLS encrypts everything inside the HTTP request: method, path, query string, headers and body, so the token in the query is protected on the wire. The IP address is in every packet, the hostname travels in plain text in the TLS ClientHello (SNI) and usually in the DNS lookup, and traffic patterns can reveal a lot. Tokens in URLs are still a bad idea for another reason: URLs end up in server logs, browser history and Referer headers.
# the handshake result: version, cipher, certificate chain, verification
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| grep -E 'Protocol|Cipher is|^ [0-9] s:|Verify return'
# 0 s:CN=example.com
# 1 s:C=US, O=SSL Corporation, CN=Cloudflare TLS Issuing ECC CA 3
# ...
# New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
# Verify return code: 0 (ok)
# how long the TLS handshake took, after the TCP connect
curl -s -o /dev/null -w 'tcp %{time_connect} tls done %{time_appconnect}\n' https://example.com/
# is TLS 1.0 still accepted? (it shouldn't be)
openssl s_client -connect shop.example:443 -tls1 </dev/nullWorked example: a TLS 1.3 handshake, step by step
The app connects to https://api.shop.example. The TCP connection is already open.
- ClientHello. The app sends the TLS versions and ciphers it supports, the name
api.shop.example(so a server hosting many sites knows which certificate to use), and the public half of a fresh temporary key pair. - ServerHello. The server picks TLS 1.3 and a cipher, and sends the public half of its own temporary key pair. From this moment both sides can compute the shared secret, so everything after this is encrypted.
- Certificate. The server sends its certificate: “this public key belongs to
api.shop.example”, signed by a certificate authority, plus the intermediate certificates that connect it to an authority the phone trusts. - CertificateVerify. The server signs a summary of the whole handshake so far with its private key. Only the real owner of the certificate can do this, and the signature also proves that nobody tampered with the earlier messages.
- Checks on the phone. Is the certificate valid today? Is it for
api.shop.example? Does the chain lead to a trusted root? Does the signature match? If any answer is no, the connection is closed with an error. - Finished. Both sides send a short message confirming they computed the same keys. The app sends
GET /orders, encrypted. One round trip after the TCP connection, data is flowing.
Deep diveForward secrecy: what a stolen private key revealsInterview favorite
“An attacker stole our server’s private key. Can they decrypt traffic they recorded last year?” With modern TLS, no, and the reason is a design change worth explaining.
In old TLS with RSA key transport, the client picked the session secret, encrypted it with the server’s public RSA key and sent it. Anyone holding the private key could decrypt that message from a recording and, with it, the whole session. Every past session recorded by an attacker became readable the day the key leaked.
With ephemeral Diffie-Hellman (ECDHE), each connection uses fresh temporary key pairs, discarded after the handshake. The server’s long-term private key only signs the handshake; it never protects the session secret. A stolen key lets the attacker impersonate the server from now on (until the certificate is revoked and replaced), but it can’t unlock recordings. That’s forward secrecy, and TLS 1.3 makes it mandatory.
Caveats a senior should add: session ticket keys that are never rotated recreate the problem for resumed sessions; 0-RTT early data has weaker guarantees; and a TLS-terminating proxy or a logging system that stores decrypted traffic is a bigger exposure than the key. After a key compromise: revoke the certificate, issue a new key (not just a new certificate), rotate ticket keys, and check what the attacker could reach while impersonating you.
- TLS = confidentiality, integrity, authentication. 1.3: 1 RTT, AEAD only, ECDHE only (forward secrecy), 0-RTT replayable; 1.0/1.1 deprecated.
- Key shares give both sides a secret that never travels; the certificate signature authenticates the server.
- Visible: IPs, SNI hostname (unless ECH), DNS unless encrypted, sizes and timing. Hidden: path, query, headers, body.
- Hybrid post-quantum key exchange (X25519MLKEM768) is the browser default; rotate session ticket keys.
echo | openssl s_client -connect host:443 -servername host 2>/dev/null | grep -E 'Protocol|Cipher is|Verify'
curl -s -o /dev/null -w 'tcp %{time_connect} tls %{time_appconnect}\n' https://host/Check this part
Which TLS guarantee stops a fake server on public Wi-Fi from pretending to be your bank?
How many round trips does a TLS 1.3 handshake add?
An attacker gets the server's private key. With TLS 1.3, can they decrypt recorded past sessions?
Which of these is visible to a network observer of an HTTPS request without ECH?