HTTPS & TLS
How TLS secures connections — the goals, the TLS 1.3 handshake, certificates and chains of trust, key exchange, cipher suites, session resumption, mTLS and common pitfalls.
HTTPS is HTTP over TLS (Transport Layer Security, successor of SSL). TLS gives a connection three guarantees:
| Goal | Meaning | Mechanism |
|---|---|---|
| Confidentiality | Eavesdroppers can't read the data | Symmetric encryption (AES-GCM, ChaCha20-Poly1305) |
| Integrity | Data can't be modified undetected | Authenticated encryption (AEAD) |
| Authentication | You're really talking to bank.com | Certificates signed by trusted certificate authorities |
Over 95% of web traffic now uses HTTPS. Browsers mark plain HTTP as "Not secure", and HTTP/2 and HTTP/3 require TLS in practice.
The TLS 1.3 handshake
- Key exchange — client and server each send an ephemeral Diffie–Hellman public key (usually X25519). Each combines its private key with the other's public key and both arrive at the same shared secret, which never crosses the wire.
- Key derivation — HKDF turns the shared secret into symmetric session keys.
- Authentication — the server proves it owns the certificate's private key by signing the handshake transcript (CertificateVerify). The client checks the certificate chain and that the name matches.
- Finished — both sides send a MAC over the whole handshake, so any tampering (like a downgrade attack) is detected.
TLS 1.2 needed two round trips; TLS 1.3 needs one, and 0-RTT resumption lets returning clients send data in their first flight (with replay risks, so only for idempotent requests).
Certificates and the chain of trust
A certificate (X.509) binds a public key to a name (example.com), signed by a certificate authority (CA).
The client verifies:
- Each signature in the chain, up to a root in its trust store.
- The certificate is within its validity period (now at most ~398 days, moving to 47 days by 2029).
- The hostname matches a Subject Alternative Name (
example.com,*.example.com). - It hasn't been revoked (OCSP/CRLs — in practice, mostly via browser-pushed revocation lists).
Let's Encrypt issues free, automatically renewed certificates using the ACME protocol, proving domain control via an HTTP file or a DNS TXT record. Certificate Transparency logs record every issued certificate publicly, so misissuance gets caught.
Cipher suites
A TLS 1.3 cipher suite names the AEAD and the hash, e.g. TLS_AES_128_GCM_SHA256 or TLS_CHACHA20_POLY1305_SHA256 (faster on devices without AES hardware). TLS 1.3 removed everything weak: RC4, CBC modes, SHA-1, static RSA key exchange, and compression.
Session resumption
After a full handshake the server hands the client a session ticket. Next time, the client presents it and the two derive new keys from the old secret plus fresh key shares — skipping certificate verification and saving CPU and time.
SNI and ECH
The Server Name Indication extension tells the server which hostname the client wants, so one IP can host many certificates. SNI is sent in plain text, so observers can see which site you visit. Encrypted Client Hello (ECH) encrypts it.
Mutual TLS (mTLS)
Normally only the server presents a certificate. In mTLS, the client presents one too. It's used for service-to-service authentication in zero-trust networks and service meshes (Istio and Linkerd issue and rotate certificates automatically), and for IoT devices and B2B APIs.
Where TLS is terminated
- At a load balancer or CDN, which decrypts and forwards to backends (often re-encrypting). It's simple to manage certificates centrally.
- End to end at the application, for stronger guarantees.
- TLS passthrough at a layer 4 balancer, routing by SNI without decrypting.
Common pitfalls
| Symptom | Likely cause |
|---|---|
| "Certificate has expired" outage | No automated renewal or monitoring |
| Works in browsers, fails in curl/Java | The server isn't sending the intermediate certificate (browsers sometimes fill the gap) |
| "Hostname mismatch" | Name isn't in the SAN list, or connecting by IP |
| Corporate network breaks some apps | TLS-inspecting proxy with its own root CA; pinned apps refuse it |
| Disabling verification "to make it work" | verify=False / rejectUnauthorized: false — opens you to man-in-the-middle attacks; never ship it |
openssl s_client -connect example.com:443 -servername example.com # chain, cipher, version
curl -vI https://example.com # handshake details- TLS provides confidentiality, integrity and authentication.
- TLS 1.3: ephemeral ECDHE key exchange + certificate signature + AEAD, in one round trip.
- Certificates chain from the leaf through intermediates to a trusted root; check the hostname and dates.
- Forward secrecy protects past sessions if the server key leaks.
- Automate certificates (ACME), send the full chain, and never disable verification.
QHow does HTTPS prevent a man-in-the-middle attack?medium
The attacker can intercept the connection but can't present a valid certificate for the real domain: they don't have its private key, and no trusted CA will sign a certificate for a domain they don't control. The client verifies the chain, the hostname and the server's signature over the handshake, so impersonation fails. The key exchange itself can't be read or altered without detection.
QWhy use asymmetric crypto for the handshake but symmetric crypto for data?easy
Asymmetric operations solve key distribution and authentication but are thousands of times slower. Symmetric AEAD ciphers like AES-GCM are extremely fast (often hardware-accelerated), so the handshake establishes a shared key and bulk data uses symmetric encryption.