TLS: inspect certificates and identity
Separate a completed TLS handshake from certificate trust, hostname validation and application security.
Keep three questions separate: which endpoint was contacted, which name the certificate must cover, and which CA store is trusted by the client.
Validate a named endpoint
openssl s_client -connect 192.0.2.20:443 \
-servername app.example.org -verify_hostname app.example.org \
-verify_return_error -showcerts </dev/null-connectchooses the network endpoint.-servernamesends SNI so the server can select the virtual host.-verify_hostnamechecks the expected certificate identity; SNI alone does not.-verify_return_errorstops on verification errors. Without it,s_clientis a diagnostic client that can continue after errors.-showcertsprints certificates sent by the server, not a verified chain.
For an internal CA, add -CAfile /path/to/ca.pem. Check verification messages
and exit status, not merely CONNECTED. An untrusted issuer may reflect a
missing local CA or an incomplete served chain; an expired certificate and a
hostname mismatch are different failures.
Inspect a saved leaf certificate
Save the leaf PEM certificate block from the output as leaf.pem, then:
openssl x509 -in leaf.pem -noout -subject -issuer -dates -ext subjectAltName
openssl x509 -in leaf.pem -noout -checkend 604800The second command returns nonzero if the certificate expires within seven days (or cannot be processed). It does not validate hostname, chain, revocation or the rest of the deployment. Date checks depend on the local clock.
StartTLS and connection behavior
For LDAP StartTLS, use the protocol upgrade instead of immediate TLS:
openssl s_client -starttls ldap -connect dc.example.org:389 \
-servername dc.example.org -verify_hostname dc.example.org \
-verify_return_error </dev/nullFor SMTP, select -starttls smtp and the intended SMTP port. A failed upgrade
does not diagnose an LDAPS or HTTPS listener. If the diagnostic client waits,
interrupt it; on Linux an external timeout 15s can bound runtime.
OpenSSL’s -timeout option is for DTLS, not a general TCP deadline.
A successful handshake samples one negotiated protocol/cipher and one trust context. It is not a complete cipher audit, revocation check or vulnerability assessment. Continue with HTTP or LDAP for application-level behavior.
Sources
OpenSSL s_client, reviewed 2026-11-24; see also OpenSSL x509.
Provenance and confidence
- Version
- 1
- Sources reviewed
- 2026-11-24
- Confidence
- medium — OpenSSL 3.0 s_client documentation reviewed on 2026-11-24. No deployed TLS configuration assessed.
Also searched as: tls, ssl, certificat, chaîne de confiance, sni, expiration certificat