Lesson 148 taught you to make a certificate. This lesson is how you check one, yours or anyone else's. Five commands read the whole story: the chain, the name, the dates, the revocation pointers, and the cipher. You will run them against your lab certificates and against a live site, and you will see what each kind of bad certificate looks like: expired, wrong name, self-signed, and unknown CA. By the end you will have a renewal check you can run on a schedule, so no certificate ever surprises you again.
Difficulty: Master · Know this first: Lesson 148 - Certificates and Keys: Who You Are, and Who Says So
Every hop charges rent in milliseconds. The bar below is a worked example for this lesson's scenario — not a measurement from a live system — but the shape is honest: on a cache hit the trip is almost free, on a miss the kitchen eats the budget. Step through the lesson or switch the scenario and watch the bar change.
Extra diagram · from scratch to master
Start with a connection. Add one check at a time until the certificate is proven, or the dates refuse it.
The budget bar above shows three fixed stories. This simulator lets you write your own. Move a slider and watch the chain, the dates, and the renewal change in the budget bar, in the hop timings, and in the total. The numbers are a teaching example, not live measurements. The shape is the lesson: a short life and a long chain mean a long validation, and the renewal is what keeps it short.
How many days until the certificate ends. At 30 days the renewal starts. At 7 days someone is paged. At 0 it has already ended.
Leaf plus intermediates. A leaf and one intermediate is the common case. Each extra link is another fetch and another check.
How many certificates the deploy validates before it ships. One check per service is the minimum. Every service you own adds one.
Try this: (1) Set days left to 1, chain to 4, checks to 10. The chain is about 8 min, the dates about 31 min, the renewal about 10 min, and the total is about 53 min. (2) Set days left to 90, chain to 1, checks to 1. The chain is about 2 min, the dates about 1 min, the renewal about 1 min, and the total is about 8 min. Same deploy. Only the dates, the chain, and the checks changed.
Three questions. No score is saved anywhere — this is just you against the material.
Here is the one command that reads the whole verdict, ready to edit. Change it, then run the check. The check looks for the five parts a validation command needs: the tool, the address, the server name, the CA to trust, and the brief output.
Try breaking it on purpose: delete the -CAfile part, or change -brief to -showcerts. Run the check and watch it fail. Then press Reset and try a change that keeps it passing, like adding -tls1_2 to force the older version.
Expected output when it passes: The command connects, checks the chain, the name, and the dates, and prints one screen. The Verification line says OK, the Protocol line says TLSv1.3, and the Ciphersuite line names the cipher.
I take the same trip four times here. First I learn the padlock. Then I learn the five commands. Then I learn the chains and the codes. Last I run it for the world.
Definition: A certificate is checked four ways, and the browser does all four on every page. The chain: was it signed by a CA the browser trusts. The name: does it name the site in the address bar. The dates: is today inside its life. The revocation: was it cancelled early. If any one fails, the page does not load, and the browser says why.
Types:
Uses: I use this every time a page refuses to load. I click the padlock and read which check failed, instead of guessing. Try it now: open a site you use every day, click the padlock, and read the dates. Then practice the four checks in the TLS labs.
Dimensions: At low traffic everything is nearly free. What breaks first is the date: a certificate ends quietly, and nobody is watching. It costs one -checkend command on a schedule, which is the renewal check in step 7.
Try it: Basic
A page refuses to load. How many checks could have failed?
Now do it: Open a site you use every day, click the padlock, and read the dates, then run the -checkend command from step 7 on a schedule.
Definition: Five commands read the whole story. s_client -brief gives the one-screen verdict. s_client -showcerts shows the chain. x509 -subject -issuer -dates reads the document. x509 -checkend asks how many days are left. curl --cacert proves the trust from the client side. Each command answers one question, and together they answer all of them.
Types:
Uses: I use these five whenever a deploy changes a certificate, or a page stops loading. I run them in order: connect, chain, name, dates, cipher. Try it now: run all five against your lab server and write down the verdict of each. Then practice the five in the TLS labs.
Dimensions: As the service grows, the checks grow, and the manual run stops scaling. What breaks is the certificate nobody checked, because the check was a human with a terminal. It costs a script that runs the five on a schedule and pages on a failure.
Try it: Intermediate
I want the one-screen verdict on a certificate. Which command gives it?
Now do it: Run all five against your lab server in order and write down the verdict of each: connect, chain, name, dates, cipher.
Definition: A chain has three kinds of links. The leaf is the certificate for the service. The intermediates are the CAs between the leaf and the root. The root is the CA in the trust store. The server sends the leaf and the intermediates, never the root. The return codes name the breaks: 0 is the pass, 18 is self-signed, 20 is a missing issuer, 21 is an unknown CA, 62 is a wrong name. Each code points at a different fix, and guessing the fix without the code wastes the morning.
Types:
Uses: I use this when a chain fails in one place and passes in another. A chain that passes on one machine and fails on another is a missing intermediate, because the passing machine had it cached. Try it now: run s_client against your lab server with and without -CAfile, and write down the two return codes. Then practice the codes in the TLS labs.
Dimensions: At ten times the services, the chain is the inventory. What breaks is the intermediate that changed when the CA renewed, while the servers still send the old one. It costs serving the chain from one place, and a check that reads it back after every deploy.
Try it: Advanced
My verify run returns code 20. What is broken?
Now do it: Run s_client against your lab server with and without -CAfile, and write down the two return codes.
Definition: At this level the certificate stops being checked by hand and becomes a watched date. The renewal runs on a schedule, the checkend command runs every day, and the alerts fire at 30, 14, and 7 days. HSTS tells the browser to refuse plain HTTP for the whole site, so a downgrade is impossible. OCSP stapling puts the revocation answer in the handshake, so the client never has to ask. And mTLS goes one step further: the client shows a certificate too, so the server checks the client the same way the client checks the server, and a service that cannot prove itself gets no answer at all.
Types:
Uses: I use this when more than one service depends on the same certificates, or when an expired certificate can take down a service other teams depend on. It is also how I review a setup I did not build: I ask where the renewal runs, who gets the 14 day alert, and what happens when the CA itself renews. Try it now: find the HSTS header on a site you own with curl -s -I, and say whether the site sends one.
Dimensions: At a hundred times the certificates, the expiry date is not the bottleneck, the blast radius is. What breaks is the single CA every service depends on, or the renewal that only one person knows how to run. It costs automation, a second CA, and a rehearsed rotation, which is the follow-up lesson this track leaves for next: TLS in production, with termination, mTLS, and rotation.
Try it: Master
I review a setup I did not build. What do I ask about the 14 day alert?
Now do it: Find the HSTS header on a site you own with curl -s -I, and say whether the site sends one.
Everything above is the hand-run path. I make the key, I sign the request, I install the certificate, and I watch the date. That path works. It also stops scaling the day the count of certificates passes the count of people watching them. The managed path hands the renewal to the cloud. I still have to prove I own the domain, and I still have to bind the certificate to something that serves traffic. The cloud does the rest.
Four words first, because Lesson 172 builds on them. A listener is the front door of a load balancer: a port, a protocol, and a certificate. Port 443 with HTTPS is the usual one. ACM is AWS Certificate Manager. It asks a public CA for certificates, holds the private key, and renews the certificate before it ends. DNS validation is the proof: ACM gives you a record to put in DNS, and when the CA can read it back, the domain is yours. SNI is the name in the first TLS message. The client sends the hostname before the server picks a certificate, so one listener can serve many names.
Do this: ask for a certificate. This needs your own AWS account. I did not run this call here, because this machine has no AWS account and no credentials. The command is:
aws acm request-certificate --domain-name app.example.com --validation-method DNS
Expected output, the shape of it:
{"CertificateArn": "arn:aws:acm:us-east-1:123456789012:certificate/00000000-0000-0000-0000-000000000000"}
Save that ARN. It is the name of the certificate from here on. The flags: --domain-name is the name on the certificate. --validation-method DNS picks the DNS proof instead of the email proof. I use DNS, because it renews without a human clicking a link in an inbox.
Do this: read the validation record back. Run:
aws acm describe-certificate --certificate-arn arn:aws:acm:us-east-1:123456789012:certificate/00000000-0000-0000-0000-000000000000 --query 'Certificate.DomainValidationOptions[0].ResourceRecord'
Expected output, the shape of it: a record with a Name like _a1b2c3d4e5f6.app.example.com, Type CNAME, and a Value ending in acm-validations.aws. Put that exact CNAME in your DNS. Then check DNS itself:
dig +short CNAME _a1b2c3d4e5f6.app.example.com
Expected output: the same acm-validations.aws value. I ran dig here against a real domain to check the syntax works, and it does. The record itself only exists in your own DNS, so only you can see this answer. If dig shows nothing, wait. DNS answers from cache, and a fresh record takes minutes to show up everywhere.
Do this: check the status. Run:
aws acm describe-certificate --certificate-arn arn:aws:acm:us-east-1:123456789012:certificate/00000000-0000-0000-0000-000000000000 --query 'Certificate.Status'
Expected output: "PENDING_VALIDATION" before the CA reads the record, and "ISSUED" after. PENDING_VALIDATION is not an error. It is the CA waiting on DNS.
Do this: bind the certificate to a listener. Run:
aws elbv2 create-listener --load-balancer-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/demo/0000000000000000 --protocol HTTPS --port 443 --certificates CertificateArn=arn:aws:acm:us-east-1:123456789012:certificate/00000000-0000-0000-0000-000000000000 --default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/demo/0000000000000000
Expected output, the shape of it: a Listeners list with one entry, carrying a ListenerArn and the certificate you named. The flags: --load-balancer-arn names the balancer. --protocol HTTPS and --port 443 name the front door. --certificates names the default certificate, by ARN. --default-actions Type=forward names where the traffic goes after TLS ends. The listener terminates TLS here, then forwards plain HTTP to the targets. That is the same termination Lesson 172 walks through, hop by hop.
Do this: give the same listener a second name. Run:
aws elbv2 add-listener-certificates --listener-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:listener/app/demo/0000000000000000/0000000000000000 --certificates CertificateArn=arn:aws:acm:us-east-1:123456789012:certificate/11111111-1111-1111-1111-111111111111
Expected output, the shape of it: a Certificates list with the certificate you just added. The listener keeps the first certificate as the default. When a client asks for the second name, SNI carries that name in the first TLS message, and the listener serves the second certificate instead of the default. One listener, one port, many names.
Do this in the lab, with no cloud account: prove SNI to yourself. I ran this here. Make two lab certificates, one per name:
openssl req -x509 -newkey rsa:2048 -keyout app-key.pem -out app.pem -days 90 -nodes -subj "/CN=app.local" -addext "subjectAltName=DNS:app.local"
openssl req -x509 -newkey rsa:2048 -keyout api-key.pem -out api.pem -days 90 -nodes -subj "/CN=api.local" -addext "subjectAltName=DNS:api.local"
Then save this as sni_lab.py in the same folder, and run it with python3 sni_lab.py:
import http.server, ssl
CERTS = {"app.local": ("app.pem", "app-key.pem"),
"api.local": ("api.pem", "api-key.pem")}
def make_context(certfile, keyfile):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.load_cert_chain(certfile, keyfile)
return ctx
CONTEXTS = {name: make_context(*pair) for name, pair in CERTS.items()}
def pick(conn, hostname, _initial_ctx):
# SNI: the client names the host in ClientHello, before any cert is sent.
conn.context = CONTEXTS.get(hostname, CONTEXTS["app.local"])
base = CONTEXTS["app.local"]
base.sni_callback = pick
srv = http.server.HTTPServer(("127.0.0.1", 8443), http.server.SimpleHTTPRequestHandler)
srv.socket = base.wrap_socket(srv.socket, server_side=True)
srv.serve_forever()
Then ask for each name, in another shell. Expected output, exactly as I saw it here:
echo | openssl s_client -connect 127.0.0.1:8443 -servername app.local 2>/dev/null | grep subject=
subject=CN = app.local
echo | openssl s_client -connect 127.0.0.1:8443 -servername api.local 2>/dev/null | grep subject=
subject=CN = api.local
echo | openssl s_client -connect 127.0.0.1:8443 2>/dev/null | grep subject=
subject=CN = app.local
Same port, same server, different certificate per name. With no -servername the server falls back to the default, app.local. The return code on each of those is 18, self-signed, because these are lab certificates. That is expected here. The subject line is the proof that SNI picked the certificate.
Try it once more, with curl. First put a page in the folder with echo "hello from the sni lab" > index.html, then run:
curl -s --noproxy '*' --cacert app.pem --resolve app.local:8443:127.0.0.1 https://app.local:8443/index.html
hello from the sni lab
curl -s --noproxy '*' --cacert app.pem --resolve api.local:8443:127.0.0.1 https://api.local:8443/index.html; echo $?
60
The first call works: the name, the certificate, and the CA file agree. The second exits 60, because app.pem is not the CA for api.local. The --noproxy flag skips any proxy on the machine so curl talks to the lab server direct. I hit an empty reply without it here, and the flag fixed it. The --resolve flag points the name at 127.0.0.1 without touching DNS.
Renewal, and what breaks it. ACM renews a public certificate 60 days before it ends, with no human in the loop. A public ACM certificate lives 13 months, so the first renewal comes about 11 months after issue. It breaks three ways. The validation record was deleted from DNS, so the CA cannot prove the domain again. The CA is unreachable when renewal runs. Or the certificate is not attached to anything anymore, and ACM only renews certificates that are in use. Any of the three ends the same way: the certificate reaches its date and stops working, and nothing pages you about the renewal itself, because there is no renewal to page about. So I keep one check that reads the served certificate, not the ACM status. The check is the same s_client command from this lesson, pointed at the load balancer DNS name.
When expiry breaks traffic through a load balancer, the outage hides its cause. The health check still passes, because it hits the backends over plain HTTP and never does TLS. The backends are fine. The targets are fine. The users see a full page warning instead of the service, and the first signal is a user reporting it. I check it with:
echo | openssl s_client -connect app-lb-0000000000.us-east-1.elb.amazonaws.com:443 -servername app.example.com -brief | grep 'Verify return code'
Verify return code: 10 (certificate has expired)
Return code 10 is the expired certificate, the same code the gallery in Go deeper lists for the hand-run path. I checked the code here by verifying a lab certificate against a time past its end, and 10 is what it prints. The fix is the same in both paths: a new certificate on the listener, and a check that reads the served certificate after every renewal. The incident in this lesson happened because the check ran on a machine that was turned off. The managed version of that incident is the validation record someone deleted in a DNS cleanup. Same shape. Same fix: watch the served certificate, not the process that was supposed to renew it.
One limit to know: the private key never leaves ACM. You cannot download it and install the certificate on your own server. A managed certificate only serves from AWS resources, like a load balancer or a distribution. If the service runs on your own machine, the hand-run path from Lesson 148 is still the one to use.
The same idea exists on the other clouds. On Azure, App Service managed certificates are free and auto-renew, but they only work for App Service custom domains. For anything else, store the certificate in Key Vault and let the load balancer or gateway pull it from there, with auto-rotation when the Key Vault certificate renews. On GCP, Certificate Manager issues Google-managed certificates the same way, with DNS authorization proving the domain, and they attach to the HTTPS load balancer and renew themselves.
Extra diagram · from scratch to master
Start with a request. Add one step at a time until the certificate serves traffic, then renews itself.
The validation runbook, all five commands in order. Do this: run them against your lab server, in this order, and write down the verdict of each. Expected output is given after each command.
1. echo | openssl s_client -connect localhost:8443 -servername localhost -CAfile ca.pem -brief
CONNECTION ESTABLISHED, Protocol version: TLSv1.3, Verification: OK
2. echo | openssl s_client -connect localhost:8443 -servername localhost -CAfile ca.pem -showcerts | grep -E 's:|i:|Verify return code'
s: CN = app.local, i: CN = My Test CA, Verify return code: 0 (ok)
3. openssl x509 -in leaf.pem -noout -subject -issuer -dates -ext subjectAltName
subject=CN = app.local, issuer=CN = My Test CA, 90 days, four SAN names
4. openssl x509 -in leaf.pem -noout -checkend 1209600; echo $?
Certificate will not expire, exit code 0
5. curl --cacert ca.pem https://localhost:8443/index.html
hello from the tls lab
curl --cacert, flag by flag. A private CA is not in the system store. This flag tells curl where the trust lives, for this one call only.
--cacert ca.pem names the CA file to trust for this one call. Without it curl uses the system store. A private CA is not in that store, so the check fails even when the certificate is fine.Flags you will meet next: -k skips verification entirely. It makes the error go away and the trust go away with it. I never use it outside a lab.
Try it: run it with --cacert and the right CA file, then without it. With it the request works. Without it curl fails with a certificate error, even though the server certificate is fine.
openssl x509, flag by flag. This is the command that reads a certificate. The flags pick which fields to print, and which to skip.
-in names the certificate to read. Without it openssl reads from stdin, and a pasted certificate is easy to get wrong.-noout prints no certificate. Without it the whole PEM prints after the fields I asked for, and the answer drowns in base64.-subject prints the subject line: who the certificate is for.-issuer prints who signed it. On a self-signed certificate the issuer and the subject are the same name. On a CA-signed one they differ, and the difference is the chain.-dates prints notBefore and notAfter. Those two dates are the whole lifetime of the certificate, and the first thing I check when a TLS call fails.-ext subjectAltName prints only that one extension. Without it I get the whole certificate, and the SAN line hides in the middle of it.-checkend 1209600 exits 0 when the certificate stays valid for 1209600 more seconds, and 1 when it expires sooner. 1209600 seconds is 14 days. I run this in a check, not by eye, because dates are easy to misread and the exit code is not.Flags you will meet next: -text prints the whole decoded certificate, and -fingerprint prints the hash I compare with the one the server shows.
Try it: run -checkend 1209600 against a fresh certificate, then against one made with -days 1. The fresh one exits 0. The one-day one exits 1. The exit code is the check.
openssl s_client with a private CA, flag by flag. Same command, different trust. The CA flags are the difference between a check that passes and a check that fails on a certificate that is actually fine.
s_client opens a TLS connection and prints what the server sends. It is a client I can watch. I use it to see the certificate and the protocol before I blame the app.-connect host:443 names where to connect, host and port together. Without it s_client has nowhere to go.-servername sends the SNI name, the hostname the server should answer for. Without it a server that hosts many names answers with its default certificate, which may not be the one I asked about.-CAfile ca.pem names the CA file to trust for this one check. Without it the check uses the system store. A private CA is not in that store, so the check ends with verify return code 21, unable to verify the first certificate.-brief prints a short summary instead of pages of detail. I use it when I want the verdict, not the whole handshake.-showcerts prints every certificate in the chain, not just the leaf. Without it I see the leaf only, and a broken chain looks fine until a real client checks it.-verify_hostname wrong.local checks the certificate name against the name I give. wrong.local is not on the certificate, so the answer is return code 62, hostname mismatch. The certificate is real. The name is wrong. That distinction matters.echo | pipes an empty line into s_client so it closes the connection after the handshake. Without it s_client waits for my input, and the command never ends.Flags you will meet next: -starttls smtp starts TLS on a plain port, for servers that upgrade instead of listening on 443.
Try it: run it once with -CAfile and once without. With the CA file the answer is Verify return code: 0 (ok). Without it the answer is 21, unable to verify the first certificate. Then run it with -verify_hostname wrong.local and watch it become 62, hostname mismatch.
What the runbook means: each command answers one question, and the answers agree with each other. If the brief output says OK and the chain walk says 0 and curl prints hello, the certificate is good. If any one disagrees, the disagreement names the problem, and you trust the command that failed, not the ones that passed.
The bad certificate gallery, all four kinds, each with its own error. Do this: run each command and read the error line. Expected output is given after each command.
Expired: openssl x509 -in old.pem -noout -dates
notAfter one day after notBefore. A day later, the client refuses it.
Self-signed: openssl verify -CAfile ca.pem cert.pem
error 18 at 0 depth lookup: self-signed certificate
Unknown CA: echo | openssl s_client -connect localhost:8443 -servername localhost | grep 'Verify return code'
Verify return code: 21 (unable to verify the first certificate)
Wrong name: echo | openssl s_client -connect localhost:8443 -servername localhost -CAfile ca.pem -verify_hostname wrong.local | grep 'Verify return code'
Verify return code: 62 (hostname mismatch)
openssl verify, flag by flag. One job: check a certificate against a CA. The answer is one word, and I trust it more than my eyes on the dates.
-CAfile names the CA file to trust. Without it the check uses the system store, and a private CA fails even when it signed the certificate correctly.cert.pem the certificate to check, named last. The answer is one word: OK, or the reason it failed.Flags you will meet next: -partial_chain accepts a chain that ends at an intermediate, and -untrusted adds extra chain files to the check.
Try it: run it with the right CA file, then with no CA file at all. The first prints OK. The second fails, even though the certificate did not change. The trust store is the variable, not the certificate.
What the gallery means: four failures, four numbers, four fixes. Expired needs a renewal. Self-signed needs a chain. Unknown CA needs the right -CAfile. Wrong name needs a new certificate. None of them needs -k, and -k hides all four.
Read curl -v like a handshake log. Do this: run curl -sv --cacert ca.pem https://localhost:8443/index.html -o /dev/null 2>&1 | grep -iE 'TLSv1.3|Certificate|SSL connection'. Expected output: lines that name the handshake steps, Client hello, Server hello, Certificate, Finished, and a line that says SSL connection using TLSv1.3. The Finished line appears twice, once from each side, and after the second one the request is sent. If the handshake fails, the alert line above the failure names the reason, and it is the same alert the server sent.
curl -sv, flag by flag. This is the line I run when TLS fails and I need to see why. The -v output is the whole story.
-sv two flags in one set, so I break them apart. -s hides the progress meter. -v prints the exchange. Together I get the TLS detail without the noise.--cacert ca.pem names the CA file to trust for this one call. Without it curl uses the system store. A private CA is not in that store, so the check fails even when the certificate is fine.-o /dev/null writes the response body to a file instead of stdout. /dev/null throws it away. I use it when only the status line matters, not the page.Flags you will meet next: --cert and --key add a client certificate, for servers that ask the client to prove itself too.
Try it: run it against the local TLS server and read the lines that start with *. Find the TLS version line and the certificate verify line. Those two lines settle most TLS arguments.
Browser checks, for when the terminal is not the client. Do this: open the lab page in a browser with the lab CA installed, click the padlock, and read the panel. Expected output: the certificate details, the issuer, and the dates, the same four facts the commands print. Then open a page whose certificate ended, and read the panel again. Expected output: a full page warning, not a small panel, because the browser treats an expired certificate as a stop, not a note. The browser and the terminal read the same document. They just show it differently.
At 10x the certificates, the shape holds and the numbers grow. At 100x, the design changes: the checks run on a schedule, the renewal runs on its own, and the alerts fire on dates, not on outages. The validation never stops being five commands. It just stops being a human running them. The follow-up lesson this track leaves for next is TLS in production: termination at the edge, mTLS between services, and rotation without downtime.
A certificate expired on a Friday night, and the service went down for everyone. The dates were known. The check existed in a script someone had written months earlier. The script ran on a machine that had been turned off in a cleanup, and nobody noticed, because the script had no alert for its own failure. The service was down for six hours, and the fix took five minutes: a new certificate, installed the way the old one had been installed a year before.
Two things. First, the renewal check runs in the monitoring system, not in a script on one machine, and the check has its own alert, so a dead check pages someone too. Second, the renewal runs on a schedule, so a certificate is replaced before it ends, and a human never has to remember a date. Try it now: find the machine your renewal check runs on, and ask what happens if that machine is turned off. If the answer is nothing, that is the gap to close.
Validate three certificates and find the bad one. One is good, one is expired, one has the wrong name. It passes when you can name each certificate, the check that caught the bad one, and the exact error or code that proves it.
Success looks like this: the good leaf passes all five commands. The one-day certificate fails the dates check with its notAfter in the past and a -checkend exit code of 1. The wrong-name leaf fails with return code 62. The renewal check prints RENEWAL-OK for the good leaf and RENEW-NOW for the other two, and you can say why for each.
If s_client prints Verify return code: 0 (ok) even when the handshake failed, read the error line above it: the code line prints even on failure, and the error line is the truth. If -checkend says will not expire for a certificate you know is old, check the number you passed: it is seconds, not days, so 14 days is 1209600, not 14. If curl fails with exit code 60 on the good leaf, the --cacert file is wrong or missing, so check the CA file, not the leaf.