Production Concerns

SSL, TLS & mTLS

● Intermediate ⏱ 12 min read production

Transport Layer Security (TLS) is the cryptographic protocol that secures most internet communication — HTTPS, email, database connections, and service-to-service API calls. SSL (Secure Sockets Layer) is TLS’s predecessor and is now deprecated, but the term “SSL” persists colloquially. Understanding TLS matters for every engineer working on networked systems: it underlies the security of your APIs, your users’ sessions, and your internal service mesh.

TLS Basics

TLS provides three security properties for a connection:

TLS sits between the TCP layer and the application layer. Once a TLS session is established, the application sends data as if it were a normal TCP stream — TLS handles encryption and decryption transparently.

The TLS Handshake

Before any application data flows, TLS performs a handshake to establish the session. TLS 1.3 (current standard) completes in 1 round-trip (1-RTT), down from 2-RTT in TLS 1.2:

  1. ClientHello: The client sends supported TLS versions, a list of supported cipher suites, and a random nonce.
  2. ServerHello + Certificate: The server selects a cipher suite, sends its certificate (containing its public key), and generates its own random nonce. In TLS 1.3, the server also immediately sends its key share.
  3. Certificate verification: The client verifies the server’s certificate: checks the signature chain up to a trusted root CA, verifies the hostname matches the certificate’s Common Name or Subject Alternative Name (SAN), and checks the validity period and revocation status.
  4. Key exchange: Both sides use the Diffie-Hellman key exchange to derive a shared secret — without ever transmitting the secret. From this shared secret, session keys are derived for symmetric encryption (AES-GCM in TLS 1.3).
  5. Finished: Both sides send a Finished message (MAC of the full handshake transcript) to verify neither party was tampered with. Application data can now flow.

Why Diffie-Hellman? The server’s certificate contains a public key, but if that key were used directly for encryption, an attacker who later obtained the server’s private key could decrypt all recorded past sessions. DH key exchange provides forward secrecy: session keys are ephemeral, derived fresh per connection, and deleted after the session. A future private key compromise doesn’t decrypt past traffic.

Certificates and CAs

A TLS certificate is a digital document containing:

The certificate chain of trust:

  1. A Root CA is a self-signed certificate whose public key is baked into operating systems and browsers. There are ~50 trusted root CAs worldwide.
  2. Intermediate CAs are signed by a root CA. Root CAs rarely sign leaf certificates directly — they sign intermediates and keep root keys offline.
  3. Leaf certificates (your server’s certificate) are signed by an intermediate CA.

When a client verifies your certificate, it walks this chain: your cert → intermediate → root. If it finds the root in its trusted store, the chain is valid.

Let’s Encrypt is a free, automated CA that issues 90-day certificates via the ACME protocol. Certbot, Caddy, and Traefik automate renewal. The 90-day limit encourages automation and limits the damage from a compromised private key.

TLS Versions

VersionStatusNotes
SSL 2.0 / 3.0Deprecated (broken)Multiple critical vulnerabilities (POODLE, DROWN). Never use.
TLS 1.0 / 1.1DeprecatedVulnerable to BEAST, CRIME. Disabled by all major browsers since 2020. PCI-DSS prohibits for cardholder data.
TLS 1.2Acceptable (with care)Still widely supported. Safe with strong cipher suites (ECDHE + AES-GCM). Avoid weak ciphers like RC4, 3DES.
TLS 1.3Current standard1-RTT handshake, mandatory forward secrecy, removed weak cipher suites, 0-RTT session resumption. Use this.

Mutual TLS (mTLS)

In standard TLS, only the server presents a certificate — the client is anonymous. Mutual TLS (mTLS) requires both sides to present and verify certificates. The client proves its identity to the server, not just the reverse.

mTLS handshake additions:

  1. After verifying the server’s certificate, the server sends a CertificateRequest.
  2. The client sends its certificate.
  3. The server verifies the client’s certificate against a trusted CA (typically an internal CA, not a public one).
  4. The client signs a message with its private key to prove it possesses the key corresponding to the certificate.

Where mTLS is used:

💡
mTLS vs API Keys

API keys are bearer tokens — anyone who has the key can use it. mTLS requires the caller to prove possession of the private key corresponding to a certificate, and private keys never leave the machine. A stolen API key grants immediate access; a stolen certificate without the private key is useless. For high-security service-to-service communication, mTLS provides stronger assurance than API keys.

TLS Termination

TLS can be terminated at different points in your infrastructure:

Design Considerations