TwiceToldby Develoker
ConceptsSystem designLabsCheat sheetsAbout

Develoker makes free tools for learning to build software. TwiceTold explains each idea twice, as an everyday analogy and the real thing; CloudArch lets you design cloud systems and put load on them.

About ยท Labs ยท Cheat sheets ยท Learning paths

All concepts ยท web ยท security ยท cryptography

TLS & HTTPS

How the web keeps traffic private and genuine. TLS encrypts and authenticates every byte after a short handshake, and certificates signed by trusted authorities prove you're talking to the real site.

12 min3 animations

๐Ÿ“š Builds on๐Ÿ“ฎ HTTP

๐Ÿ–จ๏ธ Cheat sheet

Postcards

Sending a plain HTTP request is like sending a postcard. Every sorting office on the way can read it, and a dishonest one could even change what it says before passing it on.

HTTPS puts every letter in a locked box. The sorting offices still carry it, but they only see the outside, and if anyone forces the box open, you can tell.

What TLS gives you

HTTPS is ordinary HTTP sent inside a TLS connection (Transport Layer Security, formerly SSL). TLS gives three guarantees:

  • Confidentiality: traffic is encrypted, so the network sees only ciphertext.
  • Integrity: every record is authenticated, so modified data is detected and rejected.
  • Authentication: the server proves its identity with a certificate.

Observers can still see which server you're talking to (its IP address, and usually its name), and roughly how much data flows, but not the URLs, headers, cookies or bodies.

Postcards and locked boxes4 steps
๐Ÿง’You๐Ÿ•ต๏ธNosy sorting office๐ŸชThe shop
Press play and watch it happen!

Agreeing on a lock

How can two strangers agree on a secret when everything they send can be read? Each of you mixes your own secret ingredient with a shared one and posts the mixture. Then each of you adds your secret ingredient to the other's mixture. You both end up with the same final mix, and nobody watching can make it from what was posted.

The handshake

TLS 1.3 needs one round trip before data flows:

  1. ClientHello: supported cipher suites plus the client's key share, an ephemeral (Elliptic Curve) Diffie-Hellman public key.
  2. ServerHello: the chosen suite and the server's key share, followed (already encrypted) by its certificate, a signature proving it holds the certificate's private key, and Finished.
  3. Both sides derive the same session keys from the two key shares. The keys themselves never cross the wire.
  4. The client checks the certificate, sends Finished, and HTTP requests follow, encrypted with a fast symmetric cipher such as AES-GCM or ChaCha20-Poly1305.

Because the keys are ephemeral, recording traffic today and stealing the server's private key later still doesn't decrypt it. That property is called forward secrecy.

The TLS 1.3 handshake4 steps
๐Ÿง’You๐ŸชThe shop
Press play and watch it happen!

The notary's stamp

A locked box doesn't help if you agreed on the lock with the wrong person. So the shop shows an ID card stamped by a notary, someone your browser already trusts. A pretend shop can make its own card, but it can't get a real notary's stamp for a name that isn't theirs.

Certificates and the chain of trust

A certificate binds a domain name to a public key and is signed by a certificate authority (CA). The CA only signs after the site proves it controls the domain, for example by serving a token over HTTP or adding a DNS record (that's what Let's Encrypt automates).

Browsers ship a root store of trusted CAs. The server sends its certificate plus any intermediate certificates, and the browser checks that:

  • each signature chains up to a trusted root,
  • the name matches the site,
  • it hasn't expired or been revoked.

If any check fails, the browser stops before sending a single byte of the request.

Who signed this ID card?4 steps
๐Ÿง’You๐Ÿง‘โ€โš–๏ธNotary๐ŸชThe real shop
Press play and watch it happen!
๐Ÿ”ง Going deeper

HSTS: a Strict-Transport-Security header tells the browser to use HTTPS for this site from now on, so a later http:// link can't be downgraded by an attacker.

Mutual TLS: servers can ask clients for certificates too. Service meshes use this between internal services.

Inspect it: openssl s_client -connect shop.com:443 -servername shop.com prints the certificate chain and the negotiated protocol.

๐Ÿงฉ Quick quiz

Quick quiz! 3 questions about TLS & HTTPS, told the same way as the story.
  1. Why is plain HTTP like a postcard?
  2. How do two strangers agree on a secret when everything they post can be read?
  3. Why does the shop show an ID card stamped by a notary?
Answer every question to check.Passing marks TLS & HTTPS as done.
Got the hang of TLS & HTTPS? Mark it as done, and your paths show how far youโ€™ve got.

Saved in this browser.

๐ŸŒ How the web talksStep 3 of 5

โ† Previous on the path๐Ÿ“ฎ HTTPNext on the path โ†’๐Ÿšง CORS