How SSL/TLS Works: The Handshake Explained
When you see the green lock icon, your data is safe. But how? We break down the SSL Handshake, Public/Private Keys, and Certificates.
Abstract AlgorithmsTLDR: SSL (now TLS) secures data between your browser and a server. It uses Asymmetric Encryption (Public/Private keys) once โ to safely exchange a fast Symmetric Session Key. Everything after the handshake is encrypted with the session key.
๐ The Locked Box Trick: Why Two Encryption Systems?
Alice wants to send Bob a secret letter, but Eve is intercepting all mail.
- Symmetric encryption: Same key locks and unlocks. Fast โ but how do Alice and Bob share the key without Eve intercepting it?
- Asymmetric encryption: Bob publishes an Open Padlock (public key) and keeps the only Key (private key). Alice locks her letter with Bob's padlock. Eve sees the locked box but can't open it. Only Bob can.
| Type | Speed | Key distribution problem? |
| Symmetric (AES) | Very fast | Yes โ how to share the key safely? |
| Asymmetric (RSA/ECDH) | Slow | No โ public key can be shared openly |
TLS Strategy: Use asymmetric encryption once (during the handshake) to securely exchange a symmetric session key. Then use the fast session key for everything else.
๐ข The TLS 1.3 Handshake: Step by Step
This happens in milliseconds every time you visit https://google.com.
sequenceDiagram
participant B as Browser (Client)
participant S as Server (google.com)
B->>S: ClientHello (TLS version, cipher suites, random nonce)
S->>B: ServerHello (chosen cipher, random nonce)
S->>B: Certificate (server's public key, signed by CA)
S->>B: Key Share (ECDH public value)
Note over B: Verify certificate against trusted CAs
B->>S: Key Share (browser's ECDH public value)
Note over B,S: Both derive the same Session Key independently
B->>S: Finished (encrypted with session key)
S->>B: Finished (encrypted with session key)
Note over B,S: Handshake complete โ all further data encrypted
TLS 1.3 improvement over TLS 1.2: The handshake completes in 1 RTT (round trip) instead of 2. Resumed sessions can use 0-RTT for even lower latency.
What the Certificate Tells the Browser
The server certificate contains:
- Subject:
CN=google.comโ who owns this key. - Public Key: The server's asymmetric key.
- Issuer:
CN=DigiCert Global CAโ who vouches for it. - Validity Period: Not before / not after dates.
- Signature: The CA's digital signature over all of the above.
โ๏ธ Certificates and the Chain of Trust
Your browser doesn't know every website. It knows a small set of Root CAs (DigiCert, Let's Encrypt, GlobalSign) pre-installed in your OS/browser trust store.
flowchart TD
Root["Root CA\n(Self-Signed โ in your OS trust store)"]
Intermediate["Intermediate CA\n(Signed by Root)"]
Leaf["Leaf Certificate\ngoogle.com\n(Signed by Intermediate)"]
Root --> Intermediate --> Leaf
Validation chain:
Browser checks Leaf โ Intermediate โ Root โ Root is in trust store โ Valid.
If any link in the chain is missing or expired, the browser shows the red "Not Secure" warning.
Why not sign leaf certs with the Root directly?
Root private keys are stored offline in HSMs. Exposing them for every leaf cert would be a catastrophic security risk. Intermediate CAs handle day-to-day signing; if an Intermediate is compromised, only it needs to be revoked.
๐ง Session Keys, Forward Secrecy, and Performance
ECDH and Perfect Forward Secrecy (PFS)
In TLS 1.3, the session key is derived via ECDHE (Elliptic Curve Diffie-Hellman Ephemeral). "Ephemeral" means a fresh key pair is generated for every session and discarded after.
Perfect Forward Secrecy: Even if an attacker records encrypted traffic today and steals the server's private key tomorrow, they cannot decrypt past sessions โ because the ephemeral ECDH keys are long gone.
TLS 1.2 without PFS (RSA key exchange): steal the private key โ decrypt all stored traffic. This is why PFS is critical.
TLS Performance Cost
| Stage | Cost |
| Full handshake | ~1โ2 ms additional latency |
| Session resumption (TLS 1.3) | ~0.5 ms (1-RTT) |
| 0-RTT resumption | ~0 ms extra, but has replay attack risk |
| Symmetric encryption (AES-GCM) | Negligible โ hardware-accelerated on modern CPUs |
The performance cost is dominated by the handshake. Session caching and TLS 1.3's 1-RTT largely eliminate this concern in production.
โ๏ธ Common Misconfigurations and mTLS
| Misconfiguration | Risk | Fix |
| Expired certificate | Users see security warning; browsers block | Automate renewal (Let's Encrypt + certbot) |
| TLS 1.0/1.1 enabled | Vulnerable to BEAST, POODLE attacks | Disable; enforce TLS 1.2 minimum, prefer 1.3 |
| Weak cipher suites (RC4, 3DES) | Decryptable with modern hardware | Restrict to ECDHE + AES-256-GCM |
| Missing HSTS header | Allows SSL-stripping downgrade attacks | Set Strict-Transport-Security: max-age=31536000 |
mTLS (Mutual TLS): In standard TLS, only the server presents a certificate. In mTLS, both client and server present certificates โ each verifies the other. Used in zero-trust networks, service meshes (Istio), and B2B APIs where you need cryptographic proof of client identity.
๐ Summary
- Two-phase encryption: Asymmetric (RSA/ECDH) for key exchange; Symmetric (AES-GCM) for data.
- TLS 1.3 handshake: 1 RTT, ECDHE key exchange, mutual Finished verification.
- Chain of Trust: Root CA โ Intermediate CA โ Leaf Certificate. Browser validates all links.
- Perfect Forward Secrecy: Ephemeral ECDH keys mean past sessions stay safe even if the server key is later compromised.
- mTLS: Both sides authenticate โ used in zero-trust and service mesh architectures.
๐ Practice Quiz
Why does TLS use two types of encryption (asymmetric + symmetric) instead of just one?
- A) Symmetric encryption is illegal in some countries.
- B) Asymmetric is too slow for bulk data; it's used only to exchange the fast symmetric session key.
- C) Symmetric encryption doesn't support certificates.
Answer: B
What is Perfect Forward Secrecy?
- A) Certificates that never expire.
- B) Using ephemeral key pairs per session so past sessions can't be decrypted even if the server's private key is stolen later.
- C) Encrypting traffic twice with different keys.
Answer: B
Your API needs to verify that a calling microservice is exactly who it claims to be (not just any valid user). Which TLS feature do you use?
- A) SNI (Server Name Indication).
- B) mTLS (Mutual TLS) โ the client presents a certificate the server validates.
- C) HSTS (HTTP Strict Transport Security).
Answer: B

Written by
Abstract Algorithms
@abstractalgorithms
More Posts
SFT for LLMs: A Practical Guide to Supervised Fine-Tuning
TLDR: Supervised fine-tuning (SFT) is the stage where a pretrained model learns task-specific response behavior from curated input-output examples. It is usually the first alignment step after pretraining and often the foundation for later RLHF. Good...
RLHF in Practice: From Human Preferences to Better LLM Policies
TLDR: Reinforcement Learning from Human Feedback (RLHF) helps align language models with human preferences after pretraining and SFT. The typical pipeline is: collect preference comparisons, train a reward model, then optimize a policy (often with KL...
PEFT, LoRA, and QLoRA: A Practical Guide to Efficient LLM Fine-Tuning
TLDR: Full fine-tuning updates every model weight, which is expensive in memory, compute, and storage. PEFT methods update only a small trainable slice. LoRA learns low-rank adapters on top of frozen base weights. QLoRA pushes efficiency further by q...
LLM Model Naming Conventions: How to Read Names and Why They Matter
TLDR: LLM names encode practical decisions: model family, size, training stage, context window, format, and quantization level. If you can decode naming conventions, you can avoid costly deployment mistakes and choose the right checkpoint faster. ๏ฟฝ...
