OpenSSL for inspecting TLS certificates
Check a TLS handshake, read a certificate and make a useful expiry check with OpenSSL.
Record the endpoint and your tools
Start with the hostname and port you expect the client to use. A certificate question is easier to investigate when the notes identify one endpoint. These commands use a POSIX shell and OpenSSL 3.x. Record openssl version before testing.
For a private service, use its configured hostname and the CA bundle supplied by the lab owner. Make a note of the machine clock as well. Certificate validity depends on time, and an incorrect local clock can complicate the result.
openssl version
date -uCheck the handshake with verification enabled
This connects to example.com on port 443, sends its hostname through SNI and checks the certificate against that hostname. The brief output includes the negotiated protocol, cipher and verification result. Once the summary appears, press Ctrl+C to end the diagnostic.
The -verify_return_error flag makes certificate verification errors abort the handshake. Read the verification result alongside any connection error. If your installation has no usable default trust store, provide your approved CA bundle with -CAfile and record that choice.
openssl s_client -connect example.com:443 \
-servername example.com -verify_hostname example.com \
-verify_return_error -briefRead a certificate you already have
Use the PEM certificate supplied with your lab service or an exported public certificate. Save it as certificate.pem in your working folder. A PEM certificate has BEGIN CERTIFICATE and END CERTIFICATE markers. Keep the service’s private key out of this exercise.
Inspect the subject, issuer, validity dates and subject alternative names. Write down which name matches the service you tested. Printing these fields gives you information to compare with the handshake. Trust verification still depends on the chain, trusted roots, hostname and other validation checks.
openssl x509 -in certificate.pem -noout \
-subject -issuer -dates -ext subjectAltNameTurn expiry into a repeatable check
The check below asks whether the certificate expires within the next seven days, expressed as 604800 seconds. OpenSSL returns zero when it is outside that window and a nonzero status when it expires within it. A malformed or missing file can also cause an error, so keep the diagnostic output.
For a useful handoff, include the endpoint, OpenSSL version, trust source, verification result and expiry date. If a certificate was renewed, repeat the live handshake and inspect the certificate actually served. Comparing the same fields makes a stale deployment easier to spot.
openssl x509 -in certificate.pem -noout -checkend 604800
printf 'expiry check exit %s\n' "$?"