How HTTPS and TLS Really Work: A Practical Guide
You've probably seen the padlock icon in your browser and assumed it means a site is secure. But what actually happens when you type https:// and hit enter? Understanding the TLS handshake and certificate validation helps you debug connection issues, avoid misconfigurations, and explain security to your team. This guide breaks down the real mechanics without the fluff.
The Problem: Why HTTPS Is More Than a Padlock
Many developers treat HTTPS as a checkbox: install a certificate, enable a redirect, done. But misconfigured TLS leads to expired certificates, weak cipher suites, and broken API clients. When a connection fails, you need to know where it failed—during the handshake, certificate verification, or data transfer. This article walks through the TLS 1.3 handshake step by step, explains what certificates actually prove, and shows how to inspect and debug HTTPS connections in practice.
What HTTPS Adds to HTTP
HTTPS is simply HTTP layered over TLS (Transport Layer Security). TLS provides three guarantees:
- Confidentiality: Data is encrypted so eavesdroppers can't read it.
- Integrity: Tampering is detected via message authentication codes.
- Authentication: The server proves its identity using a certificate signed by a trusted authority.
Without TLS, anyone on the network path—Wi-Fi operators, ISPs, or attackers—can read or modify traffic. With TLS, they can only see the domain you're connecting to (via SNI) and the timing of packets.
The TLS 1.3 Handshake in Plain English
TLS 1.3 simplified the handshake compared to older versions. Here's what happens in a typical browser-to-server connection:
- Client Hello: The browser sends a list of supported cipher suites, a key share (its ephemeral public key), and the server name (SNI).
- Server Hello: The server picks a cipher suite, sends its own key share, and includes its certificate chain.
- Key Derivation: Both sides compute the same shared secret using Diffie-Hellman. This secret never travels over the network.
- Finished: Both parties send a MAC over the handshake transcript to confirm nothing was tampered with.
- Application Data: HTTP requests and responses are encrypted with symmetric keys derived from the shared secret.
Notice that the certificate is sent in the clear during the handshake—it's public information. The client validates it before sending any sensitive data.
Why Forward Secrecy Matters
TLS 1.3 mandates ephemeral Diffie-Hellman (ECDHE), which provides forward secrecy. Even if the server's private key is later compromised, past sessions cannot be decrypted because the session keys were never stored. This is a key reason to prefer TLS 1.3 over TLS 1.2 with static RSA key exchange.
How Certificate Validation Works
A certificate binds a public key to a domain name and is signed by a Certificate Authority (CA). When your browser receives the certificate chain, it checks:
- Trust chain: Does the chain lead to a root CA in the browser's trust store?
- Domain match: Does the certificate's Subject Alternative Name (SAN) include the hostname you requested?
- Validity period: Is the certificate within its not-before and not-after dates?
- Revocation: Has the certificate been revoked? (Browsers use OCSP or CRL, though OCSP stapling is common.)
If any check fails, the browser shows a warning. For API clients like curl or Python's requests, the connection is aborted unless you explicitly disable verification (which you should never do in production).
Common TLS Misconfigurations and How to Spot Them
| Symptom | Likely Cause | Fix |
|---|---|---|
| Browser shows "certificate expired" | Certificate not renewed | Automate renewal with Let's Encrypt or your CA. |
| API client fails with SSL error | Missing intermediate certificate | Include the full chain in your server config. |
| Mixed content warnings | Page loads HTTP resources | Update asset URLs to HTTPS or use relative URLs. |
| Handshake fails for old clients | TLS 1.0/1.1 disabled | Upgrade clients or enable TLS 1.2 as a fallback. |
Inspecting a TLS Connection in Practice
You can examine the handshake using command-line tools. For example, openssl s_client shows the certificate chain and negotiated cipher:
openssl s_client -connect example.com:443 -servername example.com -showcerts
Look for Verify return code: 0 (ok) and the protocol version (e.g., TLSv1.3). If the chain is incomplete, you'll see errors about unable to get local issuer certificate.
For a quick check of certificate expiration and SANs, use:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates -subject -ext subjectAltName
In Node.js, you can log the TLS details of an HTTPS request:
const https = require('https');
https.get('https://example.com', (res) => {
const socket = res.socket;
console.log('Protocol:', socket.getProtocol());
console.log('Cipher:', socket.getCipher());
console.log('Certificate:', socket.getPeerCertificate().subject);
});
Configuring TLS on Your Server
For Nginx, a modern TLS configuration focuses on TLS 1.2 and 1.3, strong ciphers, and OCSP stapling. A minimal server block might look like:
server {
listen 443 ssl http2;
server_name example.com;
ssl_certificate /etc/ssl/certs/example.com.fullchain.pem;
ssl_certificate_key /etc/ssl/private/example.com.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256';
ssl_prefer_server_ciphers off;
ssl_stapling on;
ssl_stapling_verify on;
# ...
}
Always include the full chain (server certificate plus intermediates) in ssl_certificate. Missing intermediates are a common cause of mobile and API client failures.
Debugging HTTPS Issues: A Checklist
- Check certificate expiration with
openssl x509 -enddate. - Verify the chain using
openssl verify -CAfile /etc/ssl/certs/ca-certificates.crt cert.pem. - Test from multiple clients (browser, curl, mobile) to isolate client-specific trust store issues.
- Look for mixed content in browser dev tools; update all resource URLs to HTTPS.
- Ensure SNI is configured if you host multiple domains on one IP.
When analyzing server logs for TLS errors, tools like the Nginx Log Analyzer can help you spot handshake failures and slow TLS negotiations by parsing access logs.
FAQ
What's the difference between TLS and SSL?
SSL is the predecessor to TLS. Modern systems use TLS 1.2 or 1.3; SSL versions are deprecated and insecure. People often say "SSL certificate" out of habit, but the protocol is TLS.
Does HTTPS hide the domain I'm visiting?
No. The domain name is visible in the TLS handshake via SNI (unless Encrypted Client Hello is used, which is not yet universally deployed). HTTPS encrypts the content, not the destination hostname.
How often should I renew certificates?
Most CAs issue certificates valid for 90 days to 1 year. Automate renewal with tools like Let's Encrypt's certbot and set up monitoring to alert you before expiration.
Ready to debug your server's TLS performance? Use the Nginx Log Analyzer to parse access logs and identify handshake errors quickly.