OpenSSL is a widely used open-source cryptographic toolkit and SSL/TLS implementation.
It provides:
openssl for working with:
If you have ever generated a TLS certificate, built a private CA, debugged a TLS handshake, created a CSR, or inspected an X.509 certificate — you were using OpenSSL directly or indirectly.
This article builds a layered mental model so you can hold the TLS and PKI stack together in memory.
TLS performs two separate cryptographic jobs:
Identity proof = certificates and signatures
Traffic secrecy = symmetric session encryptionCertificates prove identity. Session keys encrypt traffic.
OpenSSL gives you the tools to build, inspect, verify, and debug both layers.
Everything starts with a key pair:
private key = secret
public key = shareableGenerate a private key:
openssl genrsa -out server.key.pem 2048Private keys are used to:
If the private key leaks, identity is compromised.
An X.509 certificate binds identity to a public key and a CA signature:
identity + public key + CA signature = certificateCertificates contain:
Inspect a certificate:
openssl x509 -in cert.pem -text -nooutX.509 defines structure, not encoding.
Distinguished Name (DN) fields come from directory systems (X.500 / X.509 heritage):
CN = Common Name
O = Organization
OU = Organizational Unit
C = Country
ST = State
L = LocalityThese fields are mostly descriptive.
Operational identity lives in SAN (Subject Alternative Name). Example SAN values:
DNS:api.example.com
IP:10.0.0.5
URI:spiffe://prod/paymentModern TLS hostname validation checks SAN, not CN.
Practical check:
openssl x509 -in cert.pem -noout -ext subjectAltNameA CSR is a certificate application form (standard: PKCS#10). It contains:
Create a CSR:
openssl req -new -key server.key.pem -out server.csr.pemFlow:
key -> CSR -> CA signs -> certificateA Certificate Authority is simply a key that signs certificates.
Create a lab Root CA:
openssl genrsa -out ca.key.pem 4096
openssl req -x509 -new -key ca.key.pem -out ca.crt.pem -days 3650 -subj "/C=DK/O=Lab PKI/CN=Lab Root CA"Clients trust CA certificates via a trust store. Verification builds a chain:
leaf (server) -> intermediate(s) -> root (trusted)Verify a server cert against a CA file:
openssl verify -CAfile ca.crt.pem server.crt.pemX.509 is the data structure. PEM and DER are encodings.
PEM is text (Base64 with headers), for example:
-----BEGIN CERTIFICATE-----
(base64)
-----END CERTIFICATE-----DER is binary ASN.1 encoding.
PFX (PKCS#12) is an encrypted bundle containing:
Convert PEM to PFX:
openssl pkcs12 -export -inkey server.key.pem -in server.crt.pem -certfile ca.crt.pem -out server.pfxInspect a PFX:
openssl pkcs12 -in server.pfx -info -nooutSimplified TLS handshake:
1. client hello
2. server sends certificate (and chain)
3. client verifies chain
4. client verifies SAN hostname match
5. key agreement (usually ECDHE)
6. session keys derived
7. encrypted channel beginsModern TLS typically uses:
The server private key is used to sign handshake data to prove identity (possession of the private key). Traffic is not encrypted with the server private key.
Client validation checks commonly include:
Three proofs to remember:
CA signature -> issuer authenticity
private key -> possession proof (live handshake signing)
SAN match -> name binding to the endpoint you contactedMost useful diagnostic command:
openssl s_client -connect host:port -servername hostnameIt shows:
Force hostname verification (useful for catching SAN mistakes):
openssl s_client -connect host:port -servername hostname -verify_hostname hostname -verify_return_errorIn zero-trust and service-mesh environments, identities are often expressed as URIs in SAN:
URI:spiffe://domain/workloadThis is still X.509 and TLS; it is just modernized identity and automation on top.