Skip to content
Loopedin Labs

TLS certificates

When HTTPS breaks, openssl tells you why. Learn to read it.

Mini Rush · practice

Three questions before you read

Guessing first makes the answers stick. No sign-in.

Almost every TLS failure is one failed check. openssl tells you which one.

What a client checks

During the handshake, the client accepts the server's certificate only if all of these hold:

  1. Chain: the leaf is signed by an intermediate, which chains up to a root in the client's trust store. The server must send the intermediates; the root is optional.
  2. Validity: the current time is between notBefore and notAfter. A client with a wrong clock fails this check too.
  3. Hostname: the name in the URL matches a subjectAltName entry. A wildcard covers one label only.
  4. Key: the server proves it holds the private key that matches the certificate.

When many sites share one IP, the server uses SNI, the hostname the client sends in its ClientHello, to choose which certificate to return.

The one command

openssl s_client -connect api.example.in:443 -servername api.example.in \
  -showcerts </dev/null

Look at the certificate chain list at the top, and at Verify return code near the bottom:

CodeMeaning
0 (ok)chain and validity are fine
10certificate has expired
20unable to get local issuer certificate: intermediate missing, or the root isn't trusted
21unable to verify the first certificate: usually only the leaf was sent

The hostname is checked only if you ask for it, by adding -verify_hostname api.example.in.

Inspect the leaf:

openssl s_client -connect api.example.in:443 -servername api.example.in </dev/null 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates -ext subjectAltName

Check whether a certificate and key belong together:

openssl x509 -noout -pubkey -in cert.pem | sha256sum
openssl pkey -pubout -in key.pem | sha256sum   # hashes must match

nginx specifics

ssl_certificate     /etc/letsencrypt/live/api.example.in/fullchain.pem;  # leaf first, then intermediates
ssl_certificate_key /etc/letsencrypt/live/api.example.in/privkey.pem;

If the intermediate comes first in the file, nginx fails to start with key values mismatch. After you change a certificate, run nginx -t && systemctl reload nginx.

Expiry

  • Since 15 March 2026, publicly trusted certificates can be valid for at most 200 days. The limit drops to 100 days in 2027 and 47 days in 2029, so manual renewal won't keep up.
  • Automate issuance (certbot, cert-manager), and also monitor the certificate the endpoint actually serves, for example a daily openssl x509 -checkend 1209600 check that alerts 14 days before expiry.
  • Kubernetes has its own certificates: kubeadm control-plane certificates last a year. Check them with kubeadm certs check-expiration.

Common wrong fix

Adding curl -k, verify=False or InsecureSkipVerify: true to get past a chain or hostname error. The error goes away, but so does the protection against man-in-the-middle attacks, and the flag usually stays in the code for good. Fix the server's chain or the certificate's SAN instead. If an internal CA is involved, add its root to the client's trust store with --cacert, or update-ca-certificates on the host.