Checking an SSL/TLS certificate (online check, OpenSSL, fixing errors)

How do I check an SSL/TLS certificate?

A server sends its certificate along when the TLS connection is set up. openssl s_client with the -showcerts option shows exactly that list. According to the documentation these are the certificates the server has sent, in the order it sent them, and explicitly “not a verified chain”.

openssl x509 then reads the fields: subject, issuer, validity, names. The result of the check is in the Verify return code line. Where the certificate file lies for nginx is shown on the page on the incomplete chain with the ssl_certificate directive.

Measurement and edge cases: test addresses and runs

The commands shown were run on 12 November 2026 with OpenSSL 3.6.4 on macOS, against public test addresses of badssl.com. The project page on GitHub calls badssl.com a list of test subdomains, including self-signed and expired.

The outputs come from these runs, the option descriptions from the OpenSSL documentation. Nothing was run on Windows.

What is easy to miss?

Two points are easy to miss, measured below:

  • s_client continues the connection even after verification errors.
  • For a certificate issued for a different name it reported 0 (ok) as long as -verify_hostname was missing.

Is an online check enough, or do I need OpenSSL?

Qualys SSL Labs describes its SSL Server Test as a free online service that performs “a deep analysis of the configuration of any SSL web server on the public Internet”. You enter a hostname. On data use the provider says the information submitted is used only to provide the service; that is its statement, not verified.

Because the service speaks of the “public Internet”, a host reachable only inside your own network is a case for OpenSSL run from a machine in that network.

How do I query the certificate sent?

openssl s_client -connect expired.badssl.com:443 -servername expired.badssl.com -showcerts </dev/null
  • -connect takes host and port, 443 for https.
  • -servername sets the SNI value in the ClientHello; without the option it is filled, according to the documentation, from the name given to -connect if that is a DNS name.
  • </dev/null closes the input so the command ends after the handshake; in the run it ended with exit 0 and the word DONE.

What does the output look like?

Output of the run:

Certificate chain
 0 s:OU=Domain Control Validated, OU=PositiveSSL Wildcard, CN=*.badssl.com
   i:C=GB, ST=Greater Manchester, L=Salford, O=COMODO CA Limited, CN=COMODO RSA Domain Validation Secure Server CA
   v:NotBefore: Apr  9 00:00:00 2015 GMT; NotAfter: Apr 12 23:59:59 2015 GMT
...
    Verify return code: 10 (certificate has expired)

s: is the subject, i: the issuer, v: the validity.

May applications carry on after errors?

No, and the documentation says so itself: the command is a test tool and designed to continue the handshake after verification errors. Applications that are not tests should not do this, because it makes them vulnerable to man-in-the-middle attacks. With -verify_return_error the handshake aborts instead; that option was not run here.

How do I read the certificate fields?

openssl s_client -connect expired.badssl.com:443 -servername expired.badssl.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltName

According to the documentation -subject prints the subject name, -issuer the issuer name, -dates the start and end of validity and -ext extensions in text form; -noout suppresses all output except the requested items. The output in the run, shortened:

notAfter=Apr 12 23:59:59 2015 GMT
X509v3 Subject Alternative Name:
    DNS:*.badssl.com, DNS:badssl.com

RFC 5280 calls notBefore and notAfter the validity period, the interval during which the CA warrants that it will maintain information about the status of the certificate.

How do I script an expiry check?

For that there is -checkend: according to the documentation the command checks whether the certificate expires within the next given number of seconds and exits nonzero if it does. In the run with -checkend 0 the certificate from expired.badssl.com reported Certificate will expire with exit 1, the one from wrong.host.badssl.com Certificate will not expire with exit 0.

What do the results mean?

Measured on 12 November 2026:

Test addressVerify return codeObservation
expired.badssl.com10 (certificate has expired)NotAfter is in 2015
self-signed.badssl.com18 (self-signed certificate)subject and issuer are the same
incomplete-chain.badssl.com21 (unable to verify the first certificate)the server sends only certificate 0
wrong.host.badssl.com0 (ok) without, 62 (hostname mismatch) with -verify_hostname wrong.host.badssl.comcertificate names *.badssl.com and badssl.com

What is behind codes 21 and 18?

For the chain the run first showed num=20:unable to get local issuer certificate and then num=21:unable to verify the first certificate. Two existing pages cover causes of these codes: when nginx sends the certificate chain incompletely and when the root CA is unknown to the client.

For self-signed, RFC 5280 describes self-signed certificates as certificates whose signature can be verified with the public key in the certificate itself.

Why does wrong.host.badssl.com give code 62 with -verify_hostname?

For the name the situation is different. RFC 9525 obsoletes RFC 6125 and requires DNS names to be checked via the subjectAltName extension; the Common Name must not be used to identify a service. A wildcard may only be the complete left-most label and matches exactly one label.

The measured subjectAltName of the certificate of wrong.host.badssl.com names *.badssl.com and badssl.com. wrong.host.badssl.com has two labels in front of badssl.com, so neither name matches; that explains code 62. The start page of badssl.com names no cause; the explanation follows from the rule and the measured names.

The error is not in the chain but in the names in the certificate.

How do I check a chain with openssl verify?

According to its documentation openssl verify verifies certificate chains and tries to display all problems. In the run with the certificate from incomplete-chain.badssl.com alone:

error 20 at 0 depth lookup: unable to get local issuer certificate

The number after at is the depth, 0 for the server’s own certificate.

With the remaining certificates sent by the server of wrong.host.badssl.com passed via -untrusted and with -show_chain, the run reported OK and listed the chain up to the root. Which certificates count as trusted is controlled by options such as -CAfile and -CApath.

Where are the Windows certificate stores?

According to the Microsoft documentation you open via “Run” on the Start menu:

  • certmgr.msc for the certificates of the current user,
  • certlm.msc for those of the local device.

Which other stores and tools does Microsoft mention?

Microsoft describes the certificate stores “Local computer”, “Current user” and “Service account”, examinable in the MMC snap-in. Certmgr.exe, by contrast, is a command-line utility. A step that shows which certificate a server sends is not on the retrieved page.

How do I sort certificate files?

The PKI Toolkit sorts certificate files in any order entirely in the browser, without upload, and outputs the chain as fullchain.pem. If an intermediate is missing and the existing certificate carries an AIA caIssuers URL, it names that address for fetching.

Sources

Let's talk

Free initial consultation - no sales pitch, just an honest assessment.

Request a consultation →