Sub topic 1
How TLS and Certificates Protect HTTPS
Prerequisites
This chapter assumes that you can use a Linux shell, understand basic DNS and HTTP, and know that a web server such as nginx listens for network connections. You should also know that sudo runs a command with administrator privileges.
What HTTPS Adds to HTTP
HTTP sends requests and responses between a browser and a web server. By itself, HTTP does not protect those messages. Someone who can observe the network might read passwords, session cookies, or page contents. Someone on the path might also change a response.
HTTPS is HTTP carried inside a TLS connection. TLS, which originally meant Transport Layer Security, provides three important properties:
- Confidentiality: Network observers cannot read the protected data.
- Integrity: Changes to the data are detected.
- Authentication: The browser can check that it is connected to the server named in the address.
TLS uses a combination of cryptographic methods. During the handshake, the browser and server agree on algorithms and create temporary session keys. Those keys protect the application data after the handshake. The server also presents a certificate to identify itself.
What a Certificate Contains
A TLS certificate is a digitally signed document. It normally contains:
- The domain names for which the certificate is valid.
- The certificate's issuer.
- Its validity period.
- The server's public key.
- A digital signature from the issuer.
A public key is information that can be shared. The matching private key must remain secret on the server. The certificate does not contain the private key. The server uses its private key during the handshake to prove that it controls the public key in the certificate.
A certificate for example.com does not automatically cover www.example.com. Both names must appear in the certificate, usually as separate Subject Alternative Names.
The Chain of Trust
Browsers do not usually trust every server certificate directly. They trust a list of root certificate authorities, or root CAs, that comes with the operating system or browser. A certificate authority is an organization that verifies domain control and signs certificates.
The server commonly sends a chain:
- The server certificate identifies the domain.
- An intermediate certificate links that certificate to a trusted root.
- The browser already has the root certificate in its trust store.
The browser checks the signatures, names, dates, and key usage across this chain. It also checks that the certificate has not been rejected by relevant revocation mechanisms. If these checks fail, the browser displays a certificate warning.
A Certificate Does Not Encrypt Everything Alone
The certificate mainly supports identity and key exchange. After the handshake, TLS normally uses fast symmetric encryption with session keys. The certificate's private key is not used to encrypt every request. Keeping that private key secret is still essential because an attacker who obtains it may impersonate the domain in some situations.
The certificate also has an expiry date. A valid certificate that is correctly configured today can become invalid later if it expires or if the server stops sending the required intermediate certificate.
Exercise
A browser connects to https://example.com, but the server presents a valid certificate only for www.example.com. Which HTTPS property fails?
Show answer
Server authentication fails because the requested hostname does not match a name in the certificate, so the browser should warn the user.