How an HTTPS (TLS) handshake works
Two strangers agree on a secret key in public, the server proves who it is with a certificate, and then everything is encrypted. Tiny numbers here, same idea as the real thing.
Tweak it
Break it
Normal run: Eve can watch every packet, but only sees public numbers and then ciphertext.
What to notice
- Diffie–Hellman: each side sends
g^secret mod p. Both compute the same shared keyS, yet a watcher who only sees the public numbers can't easily get it. Here p = 23, g = 5: toy sizes, real ones are enormous. - Change the browser's or server's secret: the public numbers change but both sides still land on the same S.
- Slide TLS from 1.2 to 1.3: the handshake drops from two round trips to one, so the first byte arrives a full round trip sooner.
- The certificate check is what stops a man-in-the-middle: key exchange alone can't tell you who you agreed a key with.
- Break it: the browser and the server end up with different keys, and Mallory holds both, so she reads the password and re-encrypts it for the server.
- The cipher drawn here is a toy XOR stream, for illustration only.