Pointer Walk

HTTPS and the TLS Handshake

Hello, certificate, key exchange, and then everything after is unreadable to the network.

SecurityIntermediate10 min read

Everything you send passes through strangers

When you log in to a website from a café, your password travels through the café's Wi-Fi router, the café's internet provider, several backbone networks, and the website's hosting company. Any of those machines can read whatever passes through them.

With plain http://, they see everything exactly as you typed it.

https:// puts TLS (Transport Layer Security) between you and the site. It gives three guarantees:

  • Privacy. Nobody in between can read the data.
  • Integrity. Nobody in between can change it without being detected.
  • Identity. You really are talking to the site named in the address bar.

The puzzle

Encryption needs a secret key that both sides know. But you have never communicated with this server before, and everything you say to each other crosses the open network.

How do two strangers agree on a secret while someone is listening to every word?

How HTTPS sets up a private channelInteractive
Your browser
Anyone listening
saw: nothing yet
The website

You open a login page. Watch the middle column: it shows what someone tapping the connection can see.

Step 1: Hello

The browser opens with the encryption methods it supports and a key share. The server replies with its choice, its own key share, and its certificate.

All of this is sent in the clear. The listener sees it.

Step 2: The certificate, or "who are you really?"

Encrypting a conversation is worthless if you are encrypting it to the wrong party. An attacker could sit in the middle and pretend to be your bank.

The certificate prevents that. It is a small document saying "this public key belongs to example.com", and it carries a digital signature from a certificate authority: an organisation whose job is to check who owns a domain before signing.

Your browser and operating system ship with a list of authorities they trust. The browser checks:

  • Is the signature genuine, and from an authority on my list?
  • Is the certificate for the name in the address bar?
  • Is it still in date, and not revoked?

The server also proves it holds the private key that matches the certificate. An impostor can copy the certificate, which is public, but not that key.

Step 3: The key exchange

This is the clever part, and it resolves the puzzle.

Example

Mixing paint

Imagine colours that are easy to mix and impossible to un-mix.

You and the server agree, in public, on a starting colour: yellow.

You each pick a secret colour and tell nobody. You mix yours into the yellow and send the result. The server does the same. The listener sees both mixtures.

Now you add your secret colour to the mixture the server sent. The server adds its secret colour to the mixture you sent. Both of you end up with yellow + your secret + its secret: exactly the same final colour.

The listener has yellow and the two mixtures. Without one of the secret colours, there is no way to produce the final one.

Real TLS does this with numbers in place of paint, using mathematics where combining is easy and reversing is not feasible. The "key shares" in the animation are the mixtures.

The result: both sides hold the same key, and the key itself was never sent.

Step 4: Everything after is unreadable

With a shared key in place, both sides switch to fast symmetric encryption. Every request and response from here on is scrambled, and tagged so that tampering is detected.

Your password is in the very first encrypted message.

What someone listening can still see

HTTPS hides contents, not the existence of the conversation.

VisibleHidden
That you connected, and whenThe page address after the domain
The IP address of the serverEverything you send: passwords, forms, cookies
Usually the site's domain nameEverything you receive
Roughly how much data moved

What the padlock does not mean

The padlock means the connection is private and the site holds a valid certificate for that name. It does not mean the site is honest.

A scam site at examp1e-login.com can have a perfectly valid certificate for examp1e-login.com. HTTPS guarantees you are talking privately to the name in the address bar. Reading that name is still your job.

Key takeaways

  • HTTPS is HTTP sent through TLS, which gives privacy, integrity and proof of the server's identity.
  • A certificate, signed by a trusted authority, ties a public key to a domain name.
  • The key exchange lets both sides compute the same secret key without ever sending it.
  • After the handshake, everything is encrypted with that shared key.
  • The padlock means a private connection to that domain name. It says nothing about whether the site is trustworthy.

Your progress

Check your progress

0%

  1. Read the page50% of this page

    When you have gone through the page and its animations, tick it off.

  2. Take the quiz50% of this page

    8 questions, from easy to hard. Take it as often as you like: the questions change, and only your best score counts.

Saved on this device only. See all your progress