Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Networking 3: DNS, HTTP and HTTPS

    HTTPS and TLS

    TLS (Transport Layer Security) is the protocol that encrypts a connection. (Its old name was SSL; people still

    Chapter 11 of 135 min readOften asked in interviews

    The Plain Picture#

    Before a secret conversation you (1) check the other person's passport, (2) agree on a secret code word that nobody listening could figure out, and then (3) speak only in that code.

    The Real Names#

    • TLS (Transport Layer Security) is the protocol that encrypts a connection. (Its old name was SSL; people still say "SSL certificate".)

    • HTTPS = HTTP sent inside a TLS-encrypted connection. Default port 443.

    • TLS gives three guarantees:

      1. Confidentiality — nobody in between can read the data (symmetric encryption, Ch 10.1).

      2. Integrity — nobody can change it without detection.

      3. Authentication — you're really talking to studybuddy.app, not an impostor (certificate, Ch 10.4).

    Under the Hood — the TLS 1.3 handshake#

    After the TCP handshake (Networking 2: TCP, UDP and Ports Ch 5):

      Browser                                                          studybuddy.app
        │                                                                    │
        │ ── ClientHello ──────────────────────────────────────────────────▶ │
        │    "I speak TLS 1.3; these ciphers; my key-exchange share;          │
        │     I want the site studybuddy.app (SNI)"                           │
        │                                                                    │
        │ ◀──────────────────────────────────────────────────── ServerHello ─ │
        │    "Cipher chosen; my key-exchange share"                           │
        │    [from here on, encrypted]                                       │
        │    Certificate chain + signature proving it holds the private key  │
        │    Finished                                                        │
        │                                                                    │
        │  Browser: 1. check the certificate chain up to a trusted root CA   │
        │           2. check it's for studybuddy.app and not expired         │
        │           3. both sides compute the same symmetric key (Ch 10.2)   │
        │                                                                    │
        │ ── Finished + first HTTP request (encrypted with AES) ───────────▶ │
    • One round trip for TLS 1.3 (TLS 1.2 needed two). Repeat visits can even send data in the first flight ("0-RTT"), with a replay risk, so it's only used for safe requests.

    • SNI (Server Name Indication) — the client names the site it wants in the ClientHello, so one IP can serve many HTTPS sites (the TLS version of the Host header, Ch 3).

    • Forward secrecy: because each connection's key comes from fresh Diffie–Hellman values, stealing the server's private key later does not let anyone decrypt connections recorded in the past.

    What an eavesdropper on café Wi-Fi can still see#

    VisibleHidden
    your IP and the server's IP (Networking 1: Addresses and Routing Ch 4)the URL path and query (/notes/priya?page=2)
    the port (443)all headers, including cookies and Authorization
    usually the site name (SNI, and your DNS lookup)the body — passwords, notes, everything
    how much data and when

    Gotchas

    • Certificate expiry is one of the most common causes of outages at big companies. Automate renewal and alert weeks before expiry.

    • "The padlock" means the connection is encrypted to that domain — not that the site is honest. Phishing sites have valid certificates too.

    • HSTS (Strict-Transport-Security header) tells browsers "only ever use HTTPS for this site", so a first visit can't be silently downgraded to plain HTTP.

    • TLS termination: usually the load balancer or reverse proxy does the TLS work and talks to your app over plain HTTP inside the private network (Ch 12). That's why your FastAPI app often never deals with certificates.

    Check yourself

    5 questions
    1

    What three guarantees does TLS provide?

    Show answer

    Confidentiality, integrity, authentication.

    2

    How many round trips does a TLS 1.3 handshake add?

    Show answer

    One (zero on some repeat connections).

    3

    What does the browser check about the certificate?

    Show answer

    That it chains up to a trusted root CA, that it's for the right domain, and that it hasn't expired (and the server proved it holds the private key).

    4

    On café Wi-Fi with HTTPS, can an attacker see which page on StudyBuddy you're reading? Your password?

    Show answer

    No and no — the path and body are encrypted. They can see you're talking to StudyBuddy's server (IP and usually the name).

    5

    What is forward secrecy?

    Show answer

    Each connection uses fresh key-exchange values, so a later stolen private key can't decrypt earlier recorded traffic.