HTTPS
HTTP over TLS
HTTP inside a TLS tunnel.
System design›Protocols
Basics
What the protocol is for, and the ideas it is built on.
1.1What it does
The protocol in plain words, before any bytes.
HTTPS is not a new protocol. It is ordinary HTTP carried inside a TLS connection. First TCP connects, then TLS handshakes, then the browser sends the same requests you saw in the HTTP lesson, but encrypted.
An observer on the network can see the destination address, roughly how much data moves and (unless ECH is used) the server name. They cannot see the path, headers, cookies or body.
1.2Key ideas
The handful of ideas everything else follows from.
Round trips add up
TCP + TLS 1.3 costs two round trips before the first request. HTTP/3 over QUIC folds this into one.
HSTS
A header that tells browsers to use HTTPS only for a site, preventing downgrade attacks.
What is visible
IP addresses, timing, size and SNI. Not URLs, headers or content.
Mixed content
An HTTPS page that loads a script over HTTP lets an attacker modify the page. Browsers block it.
Question
What this lesson prepares you to answer. Keep these in mind while you watch the packets.
2.1Target questions
- Can your ISP see which pages you visit on HTTPS?
- Why is HTTPS slower to start than HTTP?
The answers are in part 4.
Detailed answer
Watch a real exchange step by step, then take each message apart field by field.
3.1Follow the packets
Step through the exchange between the two sides.
SYN, SYN-ACK, ACK: one round trip.
3.2Decode it byte by byte
Click any byte or row. Each colour is one field.
After the handshake, HTTP is sent inside TLS application-data records. On the wire this is all an observer sees. Bytes are illustrative.
23 = Application data. TLS 1.3 always uses this outer type, even for encrypted handshake messages.
| Field | Offset | Bytes | Hex | |
|---|---|---|---|---|
| Record type | 0 | 1 | 17 | |
| Record version | 1 | 2 | 03 03 | |
| Record length | 3 | 2 | 00 24 | |
| Ciphertext | 5 | 20 | 13 5c a5 ee 37 80 c9 12 … | |
| Authentication tag | 25 | 16 | 63 8c b5 de 07 30 59 82 … |
3.3Decode it in code
A small decoder, tested against the exact bytes shown above.
What an observer sees in HTTPS
An encrypted record has a small visible header, then opaque bytes.
1/** Outside the tunnel an observer sees this much, and nothing more. */2export function parseRecord(b: Uint8Array) {3 const view = new DataView(b.buffer, b.byteOffset, b.byteLength);4 const length = view.getUint16(3);5 const body = b.subarray(5, 5 + length);6 return {7 type: b[0], // 23 means application data8 length,9 ciphertext: body.subarray(0, -16),10 tag: body.subarray(-16), // the AEAD tag proves nobody changed the data11 };12}13 14/** TLS 1.3: each record's nonce is the fixed IV XOR its sequence number. A nonce never repeats. */15export function recordNonce(iv: Uint8Array, seq: bigint): Uint8Array {16 const nonce = iv.slice();17 for (let i = 0; i < 8; i++) nonce[nonce.length - 1 - i] ^= Number((seq >> BigInt(8 * i)) & 0xffn);18 return nonce;19}body.subarray(-16)- The AEAD tag. A changed byte makes decryption fail.
recordNonce- XORs a counter into the IV, so a nonce never repeats. Reusing one would break the encryption.
Tested by npm run test:modules.
Q&A
Check your understanding. Answer out loud, then open.
4.1Check yourself
Can your ISP see which pages you visit on HTTPS?
Why is HTTPS slower to start than HTTP?
Extra depth
The mistakes people make with this protocol in real systems.
5.1Watch out for
- A padlock means the connection is private, not that the site is trustworthy.
- Certificates expire. Automate renewal.
- Corporate proxies that inspect HTTPS install their own root certificate.