TLS and HTTPS Basics
TLS is the protocol that encrypts traffic between two programs and lets the client check who it is talking to. HTTPS is HTTP carried inside a TLS connection.
What TLS provides
- Confidentiality: others cannot read the data in transit.
- Integrity: tampering is detected.
- Authentication: the client can verify that the server really is the site it claims to be.
TLS replaced the older SSL, but people still say “SSL certificate”. It protects data in transit only. Data stored on the server (at rest) needs separate protection.
Certificates
A server proves its identity with a certificate. It contains the server’s public key, the domain names it is valid for, the validity period and a signature from the issuer, a certificate authority (CA). Clients trust a set of root CAs built into the operating system or browser. A server normally sends a chain: its own certificate plus intermediate certificates leading to a trusted root. The matching private key stays on the server and must be protected like any secret.
In the handshake at the start of a connection, the server presents its certificate and both sides agree on keys for the rest of the traffic. Certificates expire and must be renewed, so automation is common.
Typical errors
| Error | Usual cause |
|---|---|
| Certificate expired | Renewal was missed |
| Name mismatch | The certificate does not list the hostname you used (for example an IP address, or a different subdomain) |
| Untrusted issuer or self-signed | A development certificate, a private CA that your machine does not trust, or a company proxy that inspects traffic |
| Incomplete chain | The server forgot to send an intermediate certificate |
| Not yet valid | The client’s clock is wrong |
Handling them safely
Do not fix a certificate error by disabling verification (curl -k, or “ignore SSL errors” options in libraries). That removes the authentication, and such flags tend to leak into production. Find the cause, install the proper CA certificate, or use a locally trusted development certificate.
To look at a certificate, click the padlock in the browser, run curl -v https://example.com, or use openssl s_client -connect example.com:443 -servername example.com. See also HTTP Fundamentals.
Try it
Open a site you use daily, view its certificate in the browser, and note the issuer, the validity dates and the list of names. Then run curl -v against the same site and find the same details in the output.
Common mistakes
- Disabling verification (curl -k, ignore SSL errors) to get past a certificate error.
- Assuming TLS protects data stored on the server.
- Missing a certificate renewal because it is not automated.
- Leaving out an intermediate certificate, so the chain is incomplete.
Check yourself
- What three things does TLS provide?
- A name mismatch error appears. What is the likely cause?
- Why is curl -k a bad fix for a certificate error?