How HTTP Works

Glossary Term

TLS Handshake

The TLS handshake negotiates keys and authenticates the server before HTTP data flows. See the TLS 1.3 round trip, ALPN, session resumption and 0-RTT risks.

Reviewed 2 min readintermediate3 sourcesMarkdown
On this page

TL;DR: The TLS handshake is the exchange before any HTTP bytes flow: agree on parameters, verify the server certificate, and derive shared keys. TLS 1.3 does it in one round trip.

The TLS handshake is the opening exchange in which a client and server negotiate a protocol version and cipher suite, authenticate the server with an X.509 certificate, and derive the symmetric keys that protect the rest of the connection. For HTTPS, it runs after the TCP handshake and before the first HTTP request.

What the messages carry (TLS 1.3)

  1. ClientHello: supported versions and ciphers, a key share, the server name (see SNI) and ALPN protocols such as h2 and http/1.1.
  2. ServerHello and the rest of the server flight: chosen parameters and key share; everything after this is encrypted, including the certificate and a Finished message.
  3. Client Finished: the client can now send HTTP in the same flight.

Abridged curl -v output (wording differs between curl and TLS library versions):

* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* ALPN: server accepted h2

Non-obvious facts

  • TCP plus TLS 1.3 is two round trips before the request. One for TCP, one for TLS. TLS 1.2 made it three. This is why connection reuse (keep-alive) matters so much for latency.
  • Resumption skips most of the work. A returning client can present a session ticket and resume without a full key exchange.
  • 0-RTT (early data) can be replayed. The server cannot tell a replayed early request from the original. RFC 8470 lets a server reply 425 Too Early; in practice only idempotent requests belong in early data.
  • ALPN decides HTTP version. If the server does not offer h2, the connection falls back to HTTP/1.1; there is no separate upgrade step.
  • Handshake failures appear as TLS alerts, not HTTP statuses. There is no HTTP response yet, which is why browsers show ERR_SSL_PROTOCOL_ERROR or a certificate error page rather than a status code. Behind Cloudflare, you may instead see a 525 when the CDN-to-origin handshake fails.

Go deeper

Frequently asked questions

What happens in a TLS handshake?

The client and server agree on a TLS version and cipher suite, exchange key shares, the server proves its identity with a certificate, and both derive symmetric keys. Then encrypted HTTP can begin.

How many round trips does a TLS 1.3 handshake take?

One, on top of the TCP handshake. TLS 1.2 needed two. HTTP/3 over QUIC combines the transport and TLS handshakes.

What is ALPN?

Application-Layer Protocol Negotiation is a TLS extension in which the client lists protocols such as h2 and http/1.1 and the server picks one, so HTTP/2 is selected without an extra round trip.

Is 0-RTT safe?

Not for requests with side effects. Early data can be replayed by an attacker, so servers should only accept idempotent requests in it and otherwise answer 425 Too Early.

Sources

  1. MDN Web Docs: TLSdeveloper.mozilla.org
  2. RFC 8446: TLS 1.3rfc-editor.org
  3. RFC 8470: Using Early Data in HTTPrfc-editor.org

Keep going

Browse /search