What Actually Happens When an SSL Certificate Expires (and How to Automate Renewal)
Most certificate outages are boring. Nobody attacked anything and nothing was misconfigured in the usual sense. A date passed, and a file that was valid yesterday stopped being valid today. Still, the effects are loud, s
Most certificate outages are boring. Nobody attacked anything and nothing was misconfigured in the usual sense. A date passed, and a file that was valid yesterday stopped being valid today. Still, the effects are loud, so it helps to know exactly what breaks, how to see it coming, and how to make renewal something you never think about.
What actually happens when a certificate expires
A TLS certificate carries a "not after" timestamp. During the handshake, the client checks that the current time falls inside the validity window, along with the chain of trust and the hostname. When the time is past "not after", the handshake itself can still complete, but the client treats the certificate as invalid and decides what to do next.
For browsers, that means a full-page warning such as NET::ERR_CERT_DATE_INVALID. Users can usually click through, but most will not, and you cannot assume they should. Search crawlers and link previews generally give up too.
For everything that is not a browser, it is worse, because there is no click-through at all:
-
curlfails withSSL certificate problem: certificate has expiredand a non-zero exit code. - Node.js throws
CERT_HAS_EXPIRED, Python'srequestsraisesSSLError, and Go returnsx509: certificate has expired or is not yet valid. - Webhooks from payment providers or Git hosts quietly stop being delivered, because the sender refuses to talk to your endpoint.
Notice that one expired certificate on an API hostname can break far more than the website. The marketing site may be fine while checkout, login, and every integration are down.
Why it keeps happening
Certificates used to last years, so renewal was a rare manual job that lived in one person's calendar. Public certificates now have much shorter lifetimes. Let's Encrypt issues 90-day certificates, and the wider industry has been moving toward shorter validity periods. The short lifetime is deliberate: it limits the damage from a leaked key and pushes everyone to automate.
The catch is that automation fails silently. A cron job runs as the wrong user, a DNS record changes so the challenge fails, a firewall rule blocks port 80, or the renewal works but the web server never reloads and keeps serving the old certificate from memory. That last one is the classic. The file on disk is new, and the process is still using the old one.
Step 1: Check what you are actually serving
Do not trust the file on disk. Ask the server what it presents:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -subject -issuer -dates
The -servername flag matters. Without it, a server hosting several sites may hand back its default certificate and you will check the wrong one. The output shows notBefore and notAfter, so you can see the real expiry date and compute days left in whatever tooling you use.
Step 2: Alert well before the deadline
A check that only fires on the day of expiry is useless. Pick thresholds that match how fast your team can react. A reasonable pattern with 90-day certificates is a warning at 21 days and a page at 7 days. If automatic renewal normally happens at around 30 days left, then anything under 21 days means renewal has already failed at least once, and you have time to fix it calmly.
Some options for running the check:
- A scheduled CI job that runs the script above against every public hostname and fails when
daysdrops below your threshold. - Prometheus with the blackbox exporter, which exposes
probe_ssl_earliest_cert_expirythat you can alert on. - A hosted uptime monitor that includes certificate expiry checks.
Whatever you pick, make the list of hostnames come from somewhere real, such as your DNS zone or your load balancer config. The certificates that expire are rarely the ones on the main site. They are on staging., api-old., mail., and the hostname a partner integration uses that nobody remembers.
Step 3: Automate renewal properly
If you run your own servers, an ACME client is the standard answer. Certbot, acme.sh, Caddy, and Traefik all speak the same protocol. Caddy and Traefik handle issuance and renewal themselves. With Certbot on a typical Linux box:
sudo certbot certonly --webroot -w /var/www/html -d example.com -d www.example.com
sudo certbot renew --dry-run
The dry run is the important part. It exercises the entire renewal path against the staging environment, so you find broken challenges today instead of in 60 days. Most distributions install a systemd timer or cron entry for certbot renew, but check that it exists with systemctl list-timers | grep certbot.
Then deal with the reload problem. Renewal that does not restart the server is not renewal. Use a deploy hook:
sudo certbot renew --deploy-hook "systemctl reload nginx"
A reload is enough for nginx and Apache, and it does not drop connections. Put the hook in your renewal config so it runs every time, not only when you remember it.
A few other things that regularly break automation:
- HTTP-01 challenges need port 80 reachable from the internet. A new firewall rule or a blanket HTTP-to-HTTPS redirect at the wrong layer can block it.
- Wildcard certificates require the DNS-01 challenge, which means your DNS provider needs an API and a token with limited permissions. Token rotation is a common cause of failed renewals.
Step 4: Have a recovery plan
Even with all of that, plan for the day it fails anyway. Write down, in the repository, the exact commands to issue and install a certificate by hand for each critical hostname. Know where the private keys live and who can restart the service. The worst time to learn that only one person has the DNS credentials is during an outage.
If you need a certificate quickly and do not want to set up a client first, a browser-based generator can get you a valid Let's Encrypt certificate to install manually. For example, tryfreessl.com walks through the domain validation and hands you the files. That is a stopgap for emergencies and small sites, not a replacement for automated renewal on anything that matters.
Expired certificates are one of the few outages that are completely predictable. The date is printed on the certificate. If you check it, alert on it, and test your renewal before you need it, the day it expires will pass without anyone noticing, which is exactly what you want.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.