El MehdiJOUAN EJUpStream
ENFR Contact

NewsSecurity

Security2026-12-023 min read

TLS certificates: check expiry, chain and name with openssl

Expired, incomplete chain or wrong name: the verification code tells which of the three faults it is, and where to fix it.

El Mehdi Jouan

El Mehdi Jouan · Senior System Administrator & Support Engineer · On-Prem & Cloud

· 3 min read

"Your connection is not private." The message is the same for three different faults: an expired certificate, an incomplete chain, or a name that does not match. Each is fixed in a different place, and openssl tells you which one in a single command, from any server, without a browser.

The tests were done with OpenSSL 3.5.5 on Ubuntu 26.04, against the public test addresses of badssl.com, which reproduce each fault on purpose. The commands are the same on RHEL, Oracle Linux and Debian.

1. Read the certificate a server presents

echo | openssl s_client -connect badssl.com:443 -servername badssl.com 2>/dev/null \
  | openssl x509 -noout -subject -issuer -enddate -ext subjectAltName
subject=CN=*.badssl.com
issuer=C=US, O=Let's Encrypt, CN=YR1
notAfter=Dec 28 20:02:55 2026 GMT
X509v3 Subject Alternative Name:
    DNS:*.badssl.com, DNS:badssl.com

echo | closes the connection as soon as the certificate is received. -servername sends the requested name (SNI): without it, a server hosting several sites may return another certificate, or refuse the connection. In my test, a site without a default certificate answered alert handshake failure as soon as I removed the option.

The four lines answer the real questions: for which name (subjectAltName, which is what browsers check, not subject), signed by whom (issuer), and until when (notAfter).

2. The verification code tells which fault it is

openssl s_client checks the chain and ends with a Verify return code line. On the three test addresses:

expired.badssl.com            Verify return code: 10 (certificate has expired)
incomplete-chain.badssl.com   Verify return code: 21 (unable to verify the first certificate)
wrong.host.badssl.com         Verify return code: 62 (hostname mismatch)
echo | openssl s_client -connect site:443 -servername site -verify_hostname site 2>&1 | grep "Verify return code"

For code 62, add -verify_hostname: without it, s_client does not compare the name and answers 0 (ok) for a certificate issued for another site. I saw it on wrong.host.badssl.com.

curl gives the same diagnosis, in one line:

curl: (60) SSL certificate OpenSSL verify result: certificate has expired (10)
curl: (60) SSL certificate OpenSSL verify result: unable to get local issuer certificate (20)
curl: (60) SSL: no alternative certificate subject name matches target hostname 'wrong.host.badssl.com'

3. Expired: renew it, and watch the date

The fix is on the server: renew the certificate and reload the web service. To avoid being caught out again, I watch the date:

echo | openssl s_client -connect site:443 -servername site 2>/dev/null \
  | openssl x509 -noout -enddate -checkend 2592000

-checkend 2592000 asks whether the certificate expires within 30 days (in seconds). The answer is Certificate will expire or Certificate will not expire.

Careful, and I checked it twice: with OpenSSL 3.5.5, the exit code was 0 in both cases, including for a certificate expired since 2015. In a monitoring script, test the text of the answer, not the exit code:

if echo | openssl s_client -connect site:443 -servername site 2>/dev/null \
   | openssl x509 -noout -checkend 2592000 | grep -q "will expire"; then
  echo "the certificate of site expires in less than 30 days"
fi

4. Incomplete chain: the server must send the intermediate

This is the most misleading fault: the site works in some browsers, which kept the intermediate in cache, and fails elsewhere, in curl, in a Java application or on a phone. To see what the server really sends:

echo | openssl s_client -connect site:443 -servername site -showcerts 2>/dev/null | grep -E "^ *[0-9] s:|^ *i:"

A correct server sends at least two certificates: its own (0 s:) and the intermediate that signed it (1 s:). On the test address, there was only the line 0 s:CN=*.badssl.com. The fix: configure the full chain file (fullchain.pem with certbot, for example) instead of the certificate alone.

5. Wrong name: look at the list of names

The certificate is valid, but not for this name. The subjectAltName line from part 1 gives the exact list. The causes I meet most: the name without www forgotten, a subdomain deeper than a wildcard (*.example.com covers api.example.com, not v2.api.example.com), or DNS pointing to the wrong server.

The procedure, in short

echo | openssl s_client -connect site:443 -servername site -verify_hostname site 2>&1 | grep "Verify return code"
echo | openssl s_client -connect site:443 -servername site 2>/dev/null | openssl x509 -noout -enddate -ext subjectAltName
echo | openssl s_client -connect site:443 -servername site -showcerts 2>/dev/null | grep -E "^ *[0-9] s:"

Code 10: renew. Code 21 or 20: send the full chain. Code 62: fix the name or the certificate.

  • tls
  • openssl
  • certificat
  • ssl
  • curl