Inspect a TLS certificate with openssl s_client
Display a TLS server's certificate chain and read certificate details with openssl s_client and openssl x509.
openssl s_client opens a TLS connection and prints the certificate chain presented by the server. It is useful to read a certificate's details, or to check whether a network device (for example an intercepting proxy) presents a self-signed certificate in place of the public one.
Display the certificate chain
echo -n | openssl s_client -connect www.example.com:443
Show every certificate in the chain
openssl s_client -showcerts -connect www.example.com:443 </dev/null
Send the server name (SNI)
When the connection is made to an IP address, pass the host name with -servername so the server returns the right certificate:
openssl s_client -showcerts -servername www.example.com -connect 192.0.2.10:443 </dev/null
Read the certificate details
Pipe the first certificate to openssl x509 to print its fields:
echo | openssl s_client -showcerts -servername www.example.com -connect 192.0.2.10:443 2>/dev/null | openssl x509 -inform pem -noout -text
Further reading
- Understanding self-signed certificate in chain issues, on self-signed certificates in certificate chains.