Mobile system design, from a packet to an app · Puzzle 4 · 5 of 11
What HTTPS adds
Every request your app makes is encrypted. That adds three promises on top of TCP, and one more step before the first byte. Here's what you get and what it costs, without the cryptography.
The problem
Puzzle 0 said TLS "encrypts the stream" and moved on. On the café's Wi-Fi, every router between the phone and your server sees your packets. What exactly stops them from reading or changing a request, or from pretending to be your server? And what does that protection cost?
See it
HTTPS is HTTP through TLS. Routers on the way see only scrambled bytes: encryption.
Step 1 of 4If one changes a byte, TLS notices and rejects the data: integrity.
Step 2 of 4The server shows a certificate, signed by an authority your phone trusts: authentication. Predict: what does setting this up cost?
Step 3 of 4A handshake when the connection opens: one round trip in TLS 1.3, on top of TCP's.
Step 4 of 4
The building block
HTTPS is ordinary HTTP sent through TLS, Transport Layer Security, which sits between HTTP and TCP. TLS gives three promises:
- Encryption: anyone on the way sees only scrambled bytes.
- Integrity: a changed byte is detected, and the data is rejected.
- Authentication: you're talking to the server you named, not an impostor. The server proves it with a certificate: a document, signed by an authority your phone already trusts, that says "this key belongs to api.example.com".
To set this up, client and server run a handshake when the connection opens: they agree on keys and the server shows its certificate. In TLS 1.3, the current version, that takes one round trip, on top of TCP's own.
You don't write any of it: OkHttp and Android do it for you. What you need to know is that it happens once per new connection, and that it costs a round trip, which is why the next puzzle cares so much about reusing connections. (How the keys are agreed in public, and how a certificate can be trusted, is the Encryption course.)
The analogy
A sealed envelope (encryption), with a wax seal that breaks if anyone opens it (integrity), sent to an office that shows an ID card issued by an authority you trust (authentication). Agreeing on the envelope and checking the ID takes one exchange before the first real letter.
Check yourself
Sources
- High Performance Browser Networking: Transport Layer Security ("The TLS protocol is designed to provide three essential services to all applications running above it: encryption, authentication, and data integrity"; "As part of the TLS handshake, the protocol also allows both peers to authenticate their identity")
- RFC 8446, TLS 1.3 (the full handshake is the "1-RTT handshake")
What you now know
HTTPS is HTTP sent through TLS. TLS gives three promises: encryption (nobody on the way can read it), integrity (nobody can change it unnoticed) and authentication (you're really talking to the server you named, proven by its certificate). To set that up, client and server run a TLS handshake when the connection opens; in TLS 1.3 it costs one round trip, on top of TCP's.
Answer every question above correctly to unlock the next puzzle.
Something wrong or unclear on this page? Tell me: a puzzle that didn't click is a bug in the puzzle.