How to Test HTTPS and TLS via CLI with curl and OpenSSL

Dive into testing HTTPS, TLS, and certificates using curl and OpenSSL with realistic examples and technical depth.

Key takeaway: follow the security steps carefully and prefer AES-256 encryption where available.

Before You Start Testing HTTPS connections and their security parameters directly from the command line with tools like curl and OpenSSL s_client provides deep insights into how secure connections are established and maintained. Ensure you have curl and OpenSSL installed on your system. Note that incorrect commands can expose sensitive information or disrupt services, so proceed with caution. Technical Background HTTPS (Hypertext Transfer Protocol Secure) is a secure version of HTTP, achieved by layering HTTP over TLS (Transport Layer Security). TLS ensures data privacy and integrity through encryption and mutual authentication between the server and client. When a client (like a web browser or a command-line tool) connects to a server via HTTPS, a TLS handshake occurs. This process involves the client and server agreeing on encryption methods, verifying each other’s identities using digital certificates, and establishing a secure session key for encryption. Digital certificates, often issued by Certificate Authorities (CA), play a crucial role in this process by proving the identity of a server. They contain the server's public key and related metadata, providing the foundation for encrypted communication. Step By Step 1. Verify curl and OpenSSL Installation (Windows / macOS / Linux) Command: curl --version openssl version Ensure both commands return version information. If not, install the missing tool via your package manager or official website. 2. Test Basic HTTPS Connection with curl Command: curl -I https://example.com This retrieves HTTP headers, helping verify the server's response and SSL certificate information. 3. Inspect Certificate Details with OpenSSL Command: openssl s_client -connect example.com:443 -servername example.com This command initiates a connection to the server and displays detailed certificate information. Worked Example Example: Testing a Connection with curl Command: curl -v https://10.8.0.2 Expected Output: * Connected to 10.8.0.2 * SSL certificate verify ok. Example: Inspecting a Certificate with OpenSSL Command: openssl s_client -connect 10.8.0.2:443 -servername 10.8.0.2 Expected Output: Certificate chain 0 s:/CN=example.com Configuration Or Command Reference - -I: Fetches HTTP headers only. - -v: Verbose mode, provides more details about the SSL handshake. - --insecure: Allow connections to SSL sites without certificates. - -connect: Specifies the server and port to connect to. - -servername: Used for SNI (Server Name Ind…

Related reading

VPN guides and use cases

More blog articles · VPN plans