Sub topic 1
How TLS and certificates protect HTTPS
Prerequisites
This chapter assumes you can use a Linux shell with sudo, run nginx, and read basic DNS records and HTTP requests. You also need a domain name whose DNS records you can edit.
How TLS and certificates protect HTTPS
Transport Layer Security (TLS) encrypts traffic between a browser and a server. HTTPS is HTTP carried over TLS. During the handshake, the server presents an X.509 certificate that binds a public key to one or more domain names and carries a signature from a certificate authority (CA). The browser checks the name, the validity dates, and the signature. The matching private key never leaves the server, and the handshake proves the server holds it.
Certificate authorities and the chain of trust
Browsers trust a set of root CAs. A root rarely signs site certificates directly. It signs intermediate CA certificates, which sign leaf certificates for websites. The server sends the leaf and its intermediates together. The browser verifies each signature up to a trusted root, and it rejects the connection if a link is missing or expired.
How Let's Encrypt and ACME issue certificates
Let's Encrypt is a free CA. The Automatic Certificate Management Environment (ACME) protocol is the API a client uses to request certificates. The client creates an account, orders a certificate for named domains, and completes a challenge for each name. After validation succeeds, the CA issues the certificate.
Proving domain control: HTTP-01, DNS-01 and TLS-ALPN-01
- HTTP-01: The CA fetches a token from
http://<domain>/.well-known/acme-challenge/. Port 80 must be reachable. - DNS-01: The client publishes a TXT record at
_acme-challenge.<domain>. It works without open web ports and is required for wildcards. - TLS-ALPN-01: The CA connects on port 443 and checks a special certificate that uses the
acme-tls/1protocol. Port 443 must be reachable, and the client must support this method.
This chapter uses HTTP-01 for single names.
Preparing DNS records, ports 80 and 443, and the firewall
Create A records (and AAAA records for IPv6) for example.com and www.example.com that point to your server. Validation queries public DNS, so a wrong record causes a failure. Then open ports 80 and 443. On Ubuntu with ufw:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw statusKeep port 80 open after issuance, because renewal uses it.
Installing Certbot
Install Certbot and its nginx plugin from the distribution repositories, then confirm the version:
sudo apt update
sudo apt install certbot python3-certbot-nginx
certbot --versionExercise
Why does a wildcard certificate require DNS-01 instead of HTTP-01?
Show answer
Let's Encrypt requires DNS-01 for wildcard names such as *.example.com. A web-path token only proves control of one host, but a wildcard covers every subdomain. A DNS TXT record under _acme-challenge proves control of the zone, so it can validate the wildcard.