Security

How to Check an SSL Certificate (Browser, OpenSSL, curl)

To check an SSL certificate, click the padlock (or site-information icon) next to the address in your browser and open the certificate details. From a terminal, run echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -subject -issuer -dates to print who the certificate is for, who issued it and when it expires.

Both methods show the same four things you usually need: the domain names the certificate covers, the issuing certificate authority (CA), the validity dates, and whether the chain verifies.

Check a certificate in the browser

  1. Click the icon at the left end of the address bar (a padlock, shield or settings-style icon, depending on the browser).
  2. Open the entry about the connection being secure.
  3. Choose the option to view the certificate.

The certificate viewer shows who the certificate was issued to, who issued it, the validity period and, on a details tab, the full chain from the site's certificate up to the root CA. The exact labels change between browsers and versions, which is why the terminal method below is more useful for repeatable checks and scripts. A warning icon instead of a padlock means the browser already found a problem with the certificate.

Check a certificate with OpenSSL

An openssl command is available on macOS and most Linux distributions, and Git for Windows includes one (run it from Git Bash). The full check, with example output for example.com as of October 2026:

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates -ext subjectAltName
subject=CN=example.com
issuer=C=US, O=SSL Corporation, CN=Cloudflare TLS Issuing ECC CA 3
notBefore=Sep 26 22:49:11 2026 GMT
notAfter=Dec 25 22:56:35 2026 GMT
X509v3 Subject Alternative Name:
    DNS:example.com, DNS:*.example.com

What each part does:

  • s_client -connect host:443 opens a TLS connection and prints the handshake, including the certificates the server sent.
  • -servername sets the SNI (Server Name Indication) value. Servers that host many sites on one IP address use it to choose which certificate to send, so always include it.
  • echo | sends end-of-file so s_client closes the connection instead of waiting for you to type. 2>/dev/null hides the handshake chatter.
  • openssl x509 -noout reads the certificate from the pipe and prints only the fields you ask for: -subject, -issuer, -dates (notBefore and notAfter) and -ext subjectAltName.

The Subject Alternative Name (SAN) list is what browsers match against the host name. A certificate whose subject says one name but whose SAN list doesn't include the host you visit will fail, so read the SAN line rather than the subject.

Is the chain trusted?

Leave out the 2>/dev/null and look for the verification result near the end of the s_client output. Example output:

Verify return code: 0 (ok)

Anything other than 0 (ok) means OpenSSL could not build a trusted chain or found a problem. To see every certificate the server sent, add -showcerts. The OpenSSL documentation notes this is the chain "as sent by the server" and "not a verified chain", so it is how you spot a missing intermediate certificate.

Check only the expiry date

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
  | openssl x509 -noout -enddate

For monitoring scripts, -checkend takes a number of seconds and sets the exit code: 0 if the certificate is still valid at the end of that window, non-zero if it will have expired. 2592000 seconds is 30 days:

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
  | openssl x509 -noout -checkend 2592000 && echo "OK for 30 days" || echo "Expires within 30 days"

Example output: Certificate will not expire, followed by OK for 30 days.

Check a certificate file instead of a website

For a .crt or .pem file on disk, skip s_client and pass the file:

openssl x509 -in server.crt -noout -subject -issuer -dates
openssl x509 -in server.crt -noout -text

-text prints every field, including the key type, signature algorithm and all extensions. -fingerprint -sha256 prints the SHA-256 fingerprint, which is how you confirm two copies are the same certificate.

Check with curl

curl verifies the certificate on every HTTPS request and refuses to connect if it fails, which makes it a quick pass/fail test. How much certificate detail curl -vI https://example.com prints depends on the TLS library curl was built with. The Windows build tested here (curl 8.8.0 with Schannel) prints none of the certificate fields, so use it only for the pass/fail answer. Its error messages are specific, though:

Problemcurl (Schannel) errorOpenSSL s_client result
Expired certificateSEC_E_CERT_EXPIRED (0x80090328) - The received certificate has expired.Verify return code: 10 (certificate has expired)
Name doesn't match the hostSEC_E_WRONG_PRINCIPAL (0x80090322) - The target principal name is incorrect.Verify return code: 62 (hostname mismatch) (with -verify_hostname)
Self-signed or unknown CASEC_E_UNTRUSTED_ROOT (0x80090325) - The certificate chain was issued by an authority that is not trusted.18 (self-signed certificate) or 19 (self-signed certificate in certificate chain)

The badssl.com test site has deliberately broken hosts (expired.badssl.com, wrong.host.badssl.com, self-signed.badssl.com) if you want to see each error yourself.

Note that s_client checks the chain but not the host name unless you add -verify_hostname example.com. Without it, wrong.host.badssl.com reports Verify return code: 0 (ok) even though its certificate is for a different name.

What to look for

  • Expiry. notAfter is in GMT. Public certificates are getting shorter: CA/Browser Forum ballot SC-081v3 cuts the maximum lifetime from 398 days to 47 days in steps between March 2026 and March 2029, so renewal has to be automated.
  • Names. The host you visit must appear in the SAN list, either exactly or under a wildcard. *.example.com covers www.example.com but not example.com itself or a.b.example.com: RFC 9525 allows a wildcard only as the whole left-most label, matching exactly one label.
  • Chain. The server should send its own certificate plus the intermediate certificates. A server that sends only its own certificate may work in one browser (which has the intermediate cached) and fail in another, or in curl.
  • Issuer. Check that it is the CA you expect. An unexpected issuer on a corporate network can mean a proxy is inspecting your TLS traffic.

A valid certificate proves the connection is encrypted and that the server controls the domain name. It does not prove the site is trustworthy: look-alike phishing domains get valid certificates too (see how to spot phishing). For how the signatures in a chain work, see public-key cryptography explained.

If the certificate looks fine but the browser still complains

Check the computer's clock first: a date that is far off makes valid certificates look expired or not yet valid. Then run the OpenSSL command from another network. If the result differs, something between you and the site (an antivirus product scanning HTTPS, a captive portal, a corporate proxy) is replacing the certificate. If the result is the same everywhere, the problem is on the server, usually a missing intermediate or a certificate that doesn't list the host name you are using.

Frequently asked questions

Is SSL the same as TLS?
In everyday use, yes. SSL was the original protocol and has been replaced by TLS, but the certificates are the same X.509 certificates and most people still call them SSL certificates. When you check an 'SSL certificate' today, the connection is using TLS.
How do I check when a certificate expires?
Click the padlock or site-information icon in the browser and open the certificate details, or run: echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -enddate. The notAfter line is the expiry date in GMT.
Can a valid certificate still mean the site is unsafe?
Yes. A valid certificate proves that the connection is encrypted and that whoever runs the server controls the domain name. It says nothing about whether the site is honest. Phishing sites routinely have valid certificates for their own look-alike domains.
Why does openssl show a different certificate than my browser?
Usually because the -servername option was left out. Servers that host several domains on one IP address pick the certificate from the SNI name the client sends; without it you get the server's default certificate. Always pass -servername with the same host name you connect to.

Sources