Actualizado 4 hours ago
When an HTTPS connection fails, most tools just say "connection failed." They can't show you why. The encryption is a black box.
openssl s_client opens that box. It establishes an SSL/TLS connection to any server, performs the handshake, shows you every certificate in the chain, tells you what cipher was negotiated—and then hands you the keyboard. You're not observing a connection. You're making one. You become the client, speaking directly to the server, seeing exactly what it sends back.
Basic Usage
Connect to an HTTPS server:
This establishes an SSL/TLS connection to port 443 and displays everything about the negotiation: certificate chain, TLS version, cipher suite, verification status.
What the Output Tells You
A successful connection shows:
The depth lines show certificate chain validation—depth 0 is the server's certificate, higher numbers are the chain leading to the root CA. verify return:1 means each certificate passed validation.
Speaking Protocols by Hand
Once connected, you can type protocol commands directly. For HTTPS:
Then type:
(Press Enter twice after the Host line.)
You'll see the raw HTTP response—headers and body—proving the encrypted connection works end-to-end.
Inspecting Certificates
Check expiration dates:
View full certificate details:
Shows subject, issuer, validity period, public key, Subject Alternative Names (SANs), extensions, and signature algorithm.
Extract certificate to a file:
Check Subject Alternative Names:
Shows all domains covered by the certificate.
Essential Options
-servername (SNI)
Server Name Indication tells the server which certificate to present—critical when multiple sites share an IP:
Without this, you might get the wrong certificate or a handshake failure.
-showcerts
Display every certificate in the chain, not just the server's:
Essential for debugging "unable to get local issuer certificate" errors.
-starttls
For protocols that upgrade to TLS mid-connection:
-tls1_2, -tls1_3
Force a specific TLS version:
-cipher
Test if a server supports a specific cipher:
Connection succeeds if supported, fails if not.
-CAfile
Use a custom CA certificate for validation:
-cert and -key
For mutual TLS (client certificate authentication):
-brief and -quiet
Testing Different Protocols
Debugging Common Failures
"unable to get local issuer certificate"
The certificate chain doesn't reach a trusted root. Either the server isn't sending intermediate certificates, or you need to specify a CA file:
Check if intermediates are present. If not, the server is misconfigured.
"Hostname mismatch"
The certificate's CN or SANs don't include the hostname you're connecting to. Use -servername to specify the correct hostname for SNI.
"SSL handshake failure"
TLS negotiation failed—usually a cipher or version mismatch. Try forcing a specific version:
"wrong version number"
You connected with SSL to a plaintext port, or vice versa.
"Cipher is (NONE)"
No mutually supported cipher. The server and client have no cipher suites in common.
Testing Before DNS Changes
Validate a certificate on a new server before cutting over:
Connects to the IP directly while presenting the correct hostname for SNI and certificate validation.
Scripting Examples
Alert on expiring certificates:
Test TLS version support:
Security Auditing
Test for weak ciphers:
Check for Certificate Transparency:
Verify HSTS header:
Connect with openssl s_client, send an HTTP request, and look for:
Frequently Asked Questions About OpenSSL s_client
¿Fue útil esta página?