openssl-s_client
Test TLS/SSL connections to a server
TLDR
Display the start and expiry dates for a domain's certificate
Display the certificate presented by an SSL/TLS server
Set the Server Name Indicator (SNI) when connecting to the SSL/TLS server
Display the complete certificate chain of an HTTPS server
SYNOPSIS
openssl s_client [-connect host:port] [-servername name] [-ssl2|-ssl3|-tls1_1|-tls1_2|-tls1_3] [-cipher alg] [-ciphersuites str] [-CAfile file] [-cert file] [-key file] [-verify depth] [-showcerts] [-debug] [-msg] [-state] [-status] [-starttls protocol] [options...]
PARAMETERS
-connect host:port
Specifies the remote server address and port to connect to. This is often the most common option.
-servername name
Sets the Server Name Indication (SNI) hostname. Essential for accessing virtual hosts on servers that use SNI.
-ssl2 | -ssl3 | -tls1 | -tls1_1 | -tls1_2 | -tls1_3
Forces the use of a specific SSL/TLS protocol version. Note that SSLv2 and SSLv3 are deprecated and often disabled.
-cipher alg
Specifies the list of acceptable TLSv1.2 (or older) cipher suites. Use openssl ciphers to list available options.
-ciphersuites str
Specifies the list of acceptable TLSv1.3 cipher suites.
-CAfile file
Specifies a file containing trusted Certificate Authority (CA) certificates. Used for verifying the server's certificate.
-CApath dir
Specifies a directory containing trusted CA certificates. Certificates must be hashed and symlinked correctly.
-cert file
Specifies the client's certificate file (PEM format) for client authentication.
-key file
Specifies the client's private key file (PEM format) corresponding to the client certificate.
-verify depth
Sets the maximum depth for the certificate chain verification. A value of 0 means only the peer certificate is verified.
-showcerts
Displays all certificates in the server's certificate chain received during the handshake.
-debug
Prints extensive debug information about the handshake process, including hex dumps of protocol messages.
-msg
Shows verbose information about the protocol messages exchanged during the handshake.
-state
Prints out the SSL session states as they change during the handshake.
-status
Requests an OCSP (Online Certificate Status Protocol) status response from the server if supported (OCSP stapling).
-starttls protocol
Negotiates STARTTLS for a specified application protocol (e.g., smtp, pop3, ftp, imap, xmpp, ldap). Converts an insecure connection to a secure one.
-quiet
Suppresses output of the certificates and other default handshake information, showing only errors and interactive output.
-reconnect
Attempts to reconnect to the server after the initial handshake, often used to test session reuse.
-no_ticket
Disables the use of RFC 5077 session tickets (stateless session resumption).
-keylog file
Logs TLS key material to the specified file in NSS Key Log Format, allowing tools like Wireshark to decrypt the TLS traffic.
DESCRIPTION
openssl s_client is a powerful command-line tool within the OpenSSL toolkit, primarily used for interacting with and diagnosing SSL/TLS servers. It acts as a client, establishing a secure connection to a specified host and port, then allowing interactive communication.
This utility is invaluable for system administrators, network engineers, and developers. It helps in debugging connectivity issues, inspecting server certificate chains, verifying server configurations (like supported protocol versions and cipher suites), and testing client certificate authentication. After a successful handshake, it typically forwards standard input to the server and prints server output to standard output, enabling low-level protocol interaction and analysis.
CAVEATS
Deprecated Protocols: Older SSL/TLS protocol versions (e.g., SSLv2, SSLv3) are highly insecure and typically disabled by default in modern OpenSSL builds and on most servers. Attempting to use them may result in connection failures.
Certificate Verification: Correct certificate verification requires trusted CA certificates to be properly configured via -CAfile or -CApath. Without proper CA trust, the client may accept untrusted certificates, or reject valid ones.
Verbose Output: The default output can be very verbose, especially with debugging options. Understanding the output requires familiarity with SSL/TLS handshake processes and certificate structures.
COMMON USE CASES
openssl s_client is widely used for:
Debugging Handshake Failures: Identifying why a TLS connection fails (e.g., protocol mismatch, cipher mismatch, certificate issues).
Inspecting Server Certificates: Viewing the server's certificate details, validity, issuer, and the entire certificate chain (with -showcerts).
Testing Protocol and Cipher Support: Verifying which TLS versions and cipher suites a server supports and prefers.
Verifying SNI Configuration: Ensuring that servers correctly respond to different hostnames via SNI.
Client Certificate Authentication: Testing client-side authentication by providing a client certificate and key.
STARTTLS Services: Connecting to services like SMTP, POP3, IMAP, or LDAP that upgrade an initial plain-text connection to TLS.
INTERACTIVE MODE
After a successful TLS handshake, openssl s_client enters an interactive mode. Any input typed into the console is sent to the remote server over the secure channel, and any data received from the server is displayed. This allows for manual interaction with application protocols, such as sending HTTP GET requests, SMTP commands, or other plain-text protocol messages over the established secure connection. Pressing Ctrl+D (EOF) typically closes the input stream, allowing the server to finish sending data before the connection closes.
HISTORY
The openssl s_client command has been a core component of the OpenSSL toolkit since its inception, tracing back to the SSLeay library developed by Eric Young and Tim Hudson in the mid-1990s. As the SSL/TLS protocols evolved from SSLv2 to TLSv1.3, s_client has continually been updated to support new features like Server Name Indication (SNI), OCSP stapling, TLS session tickets, and various new cipher suites and extensions. Its enduring utility lies in its flexibility as a debugging and diagnostic tool for network security, mirroring the development and adoption of secure communication standards across the internet.
SEE ALSO
openssl(1), openssl-s_server(1), openssl-x509(1), openssl-genrsa(1), openssl-req(1), openssl-ciphers(1)