guest@websec: ~/websec/s04-how-ssl-works — zsh — 100×40 by SaKKo YouTube ENTH

guest@websec ~ % man s04-how-ssl-works

How SSL / TLS Works

The mental model behind HTTPS — certificates, public & private keys, Certificate Authorities, and the TLS handshake — explained with everyday lock-and-seal analogies and zero math.

HTTPS solves three separate threats on an untrusted network: privacy (nobody can read your packets), integrity (nobody can alter a byte in transit), and identity (you are really talking to example.com, not an impostor). It uses asymmetric keys + a CA certificate once at connection startup to verify the server and invent a shared secret, then switches to a fast, disposable symmetric session key for every HTTP request and response.
Why do people say "SSL" when Nginx configs say TLSv1.3? Netscape's original SSL (1.0–3.0) was retired years ago and replaced by TLS (1.2 and 1.3 today). Everyone still calls it an "SSL certificate" out of habit — they mean TLS. Ready to request a real one on Ubuntu? Jump to lesson s03 · Let's Encrypt SSL Certificates.

1 · Three problems on the wire (encryption alone is not enough)

Between a user's browser and your Ubuntu server sit café Wi-Fi routers, corporate proxies, ISPs, and undersea cables. Plain http:// sends every header, session cookie, and JSON field like a postcard anyone along the path can read or rewrite.

Most people think HTTPS just means "encrypted". In reality, TLS must guarantee all three properties at once, or an attacker still wins:

guaranteeplain-English jobwhat happens without it
1. Privacy
Encryption
Turns traffic into unreadable noise for anyone watching the Wi-Fi or router.Passive snoopers copy passwords, API keys, and Cookie: headers right off the air.
2. Integrity
Tamper seal
Attaches an unforgeable seal to every chunk of data so even a 1-bit edit is caught immediately.A router or ISP injects ads/malware into HTML, or flips recipient names in flight.
3. Identity
Certificate check
Proves the party on the other end of the encrypted tunnel is genuinely api.example.com.Encrypted to an impostor! You build a "secure" encrypted tunnel straight into the attacker's laptop.
lab: Wi-Fi sniffer & impostor simulatortest all 3 guarantees

Pick a connection mode and an attacker action on café Wi-Fi, or edit the JSON request body:

mode:
attacker:

outcome

what the Wi-Fi attacker sees on the wire

2 · Two kinds of locks: Symmetric vs Asymmetric

To understand how two strangers (a browser in Tokyo and your Ubuntu server in Singapore) set up a private tunnel over a public internet where everyone is listening, you only need to picture two kinds of locks:

1. Symmetric Key (House Key)

One identical secret key both locks and unlocks the box.

  • Superpower: Blazingly fast — modern CPUs encrypt gigabits per second without breaking a sweat.
  • Catch: How do you hand a copy of your house key to a new visitor across a crowded room without Snoopers copying it?

2. Asymmetric Keys (Open Padlock + Key)

Created as a matched pair — a Public Key and a Private Key:

  • Public Key (fullchain.pem): Handed out freely to everyone, like an open padlock or a locked mailbox slot.
  • Private Key (privkey.pem): Never leaves your server. Only it can sign as your server (and Public Keys verify that signature).

TLS gets the best of both worlds: it uses asymmetric keys once at the start of a connection (the handshake) to verify who the server is and agree on a brand-new, one-time symmetric session key — then uses that fast symmetric key for all your HTML, API JSON, and uploads.

Bonus superpower: Forward Secrecy (throwaway session keys)

In modern TLS 1.3, the server's privkey.pem is only used to sign its identity during the handshake — never to encrypt the session key itself. Browser and server invent a fresh temporary secret for each connection and erase it from RAM when the tab closes. Even if an attacker records your encrypted Wi-Fi traffic today and steals privkey.pem off your server next year, today's recorded traffic stays unreadable forever.

explorer: which key works at each moment?step through 4 stages

Browser

Across the Network

Ubuntu Server

3 · Certificates & the Chain of Trust

Wait — anyone can generate a Public/Private key pair in half a second, including an attacker! When a server sends a Public Key claiming "Hi, I'm api.example.com", why should your browser believe it?

That is the entire job of an SSL/TLS Certificate. Think of a certificate as a government passport for a domain:

  • Who it's for (SAN): api.example.com (or example.com + *.example.com).
  • Their Public Key: The exact public key belonging to that server.
  • Valid dates: Issue date and expiry date (90 days for Let's Encrypt).
  • Issuer's digital stamp: An unforgeable signature from a trusted Certificate Authority (CA) such as Let's Encrypt, DigiCert, or Cloudflare, who verified domain ownership first (via HTTP-01 or DNS-01 in lesson s03).

Why is it a 3-link chain instead of 1 signature?

Your operating system and browser ship from the factory with ~150 trusted Root CA public keys (for Let's Encrypt, that's ISRG Root X1). Because a compromised Root key would break trust across the entire internet, Root private keys are locked offline inside air-gapped hardware vaults. Instead, the Root signs an Intermediate CA key, and the Intermediate signs your server's Leaf certificate:

inspector: test 6 real-world certificate scenariossee why browsers show padlock vs red warning

certificate chain presented

browser verification checklist

4 · Putting it all together: the TLS 1.3 Handshake

Every time you visit an https:// URL for the first time, the whole dance above finishes in one network round-trip (tens of milliseconds) before a single byte of your HTTP request leaves the browser:

5 · What HTTPS hides vs what the network still sees

HTTPS protects the contents of your conversation, not the fact that you talked to a given server. Knowing the boundary prevents surprises:

completely hidden inside TLSstill visible to Wi-Fi / ISP / firewall
Full URL path & query string (/patients/42?diagnosis=…)Destination IP address & port (203.0.113.10:443)
All HTTP headers, Authorization tokens, and Cookie valuesThe domain name (api.example.com) via DNS lookups and TLS SNI (unless Encrypted Client Hello is enabled)
Request & response bodies (JSON, HTML, passwords, file uploads)Connection timing and approximate payload sizes (e.g. a 50 MB download vs a 200-byte ping)
Takeaway for API design: URL paths and query strings are encrypted on the wire, not visible to Wi-Fi snoopers — we still keep tokens and passwords out of query strings because URLs end up saved in browser history, Nginx access logs, and Referer headers!

Check yourself

Why does TLS use both asymmetric keys and a symmetric session key instead of just using asymmetric keys for the entire connection?

Asymmetric cryptography establishes trust and agrees on a fresh shared secret; symmetric cryptography then handles megabytes of traffic at wire speed.

In Ruby or Node backend code, a developer sets verify_mode = OpenSSL::SSL::VERIFY_NONE (or NODE_TLS_REJECT_UNAUTHORIZED=0) to get past a certificate error. Is the connection still safe because it's "encrypted"?

Encryption without authentication protects against passive snoopers only; any active man-in-the-middle can hand you their own public key and read everything.

An attacker records encrypted HTTPS (TLS 1.3) packets outside your office today. Six months later, they break into an old backup and steal your server's privkey.pem. Can they decrypt today's recorded packets?

TLS 1.3 mandates ephemeral key exchange (Forward Secrecy): each session derives an independent temporary key that is never stored on disk.