SSL/TLS
Cryptography

SSL/TLS

A complete guide to SSL and TLS, covering the TLS 1.3 handshake step-by-step, cipher suites, digital certificates, and Perfect Forward Secrecy.

Every single day, trillions of dollars move across the internet. People enter credit card numbers, file tax documents, and check private medical charts. However, the basic plumbing of the internet (cables, commercial routers, cellular towers, and Wi-Fi networks) was originally built without built-in encryption. Standard network packets travel as plain text. If you connect to an open Wi-Fi network at a coffee shop or hotel, anyone running a network monitoring tool like Wireshark can capture unencrypted traffic passing through the air. Transport Layer Security (TLS), and its older predecessor Secure Sockets Layer (SSL), provides the cryptographic armor that protects internet communications. It establishes an encrypted, authenticated connection between a client (like your web browser) and a remote server, ensuring that nobody can listen in or tamper with your data in transit.

Definition

Transport Layer Security (TLS) is an industry-standard cryptographic protocol that operates between the transport layer (TCP) and the application layer (like HTTP). It provides secure communication by ensuring confidentiality, server authentication, and message integrity.

Why It Matters

Without TLS, modern online banking, remote working, and web shopping would be unsafe. Anyone between you and the server could read passwords, and malicious internet providers could inject ads or malware directly into web pages. Today, modern web browsers like Chrome, Firefox, and Safari show clear 'Not Secure' warnings whenever users visit unencrypted websites, and search engines prioritize encrypted sites in search rankings.

How It Works

TLS combines asymmetric and symmetric cryptography in two phases: the Handshake (verifying identity and agreeing on keys) and the Record Layer (encrypting actual application data): 1. From SSL to Modern TLS: • SSL 1.0, 2.0, and 3.0: Developed by Netscape in the 1990s. All versions of SSL are now considered insecure, vulnerable to known attacks (like POODLE), and completely deprecated. • TLS 1.0 and 1.1: Standardized by the IETF in 1999 and 2006; formally retired by the industry in 2020. • TLS 1.2: Standardized in 2008. Secure when properly configured, but requires two network round trips (2-RTT) and allows some older, weaker ciphers. • TLS 1.3 (The Modern Standard, RFC 8446): Released in 2018. It removes outdated ciphers, finishes the handshake in just one round trip (1-RTT), encrypts certificate exchange, and makes Perfect Forward Secrecy mandatory. 2. The TLS 1.3 Handshake Step-by-Step (1-RTT): • Step 1 (ClientHello): The browser sends its supported TLS version (1.3), a list of supported modern ciphers, and an ephemeral Diffie-Hellman key share. • Step 2 (ServerHello): The server selects a cipher (such as TLS_AES_256_GCM_SHA384), sends its own key share, and both sides calculate the shared master secret. • Step 3 (Encrypted Certificate Exchange): The server switches to encrypted communication and delivers its X.509 digital certificate, proving its domain identity. • Step 4 (Certificate Verification): The server signs the handshake transcript with its private key. The browser verifies the signature using trusted Certificate Authorities in its operating system. • Step 5 (Encrypted Application Traffic): Both sides independently calculate identical symmetric session keys and begin exchanging encrypted HTTP data using fast AES-256-GCM. 3. Perfect Forward Secrecy (PFS): In older systems, if an attacker recorded encrypted network traffic for years and later stole the server's long-term private key, they could decrypt all that historical traffic. Under TLS 1.3 with Perfect Forward Secrecy, unique temporary session keys are created for every connection and wiped from memory when the session ends. Even if the server's private key is compromised in the future, past recorded sessions remain secure.

The TLS 1.3 Handshake Workflow (1-RTT)

1. ClientHello
Client sends supported ciphers and an ephemeral Diffie-Hellman key share
2. ServerHello & Key Agreement
Server picks cipher, returns its key share, and both compute the shared master secret
3. Encrypted Certificate Delivery
Server encrypts and sends its X.509 certificate and digital signature
4. Trust Chain Verification
Client verifies the certificate chain against root CAs stored in its operating system
5. Session Key Derivation
Both sides derive identical symmetric AES-256-GCM session keys
6. Secure Data Transfer
All HTTP requests and responses travel safely inside the encrypted tunnel

Key Points

  • SSL is obsolete and insecure; modern systems use TLS 1.2 and TLS 1.3.
  • TLS uses asymmetric crypto to verify server identity and agree on keys, then uses fast symmetric AES-GCM to encrypt data.
  • TLS 1.3 completes its handshake in one network round trip (1-RTT) and encrypts the certificate exchange.
  • Perfect Forward Secrecy (PFS) ensures that future key compromises cannot decrypt past recorded sessions.
  • X.509 certificates prevent Man-in-the-Middle attacks by validating domain ownership through trusted Certificate Authorities.

Steps

  1. Obtain a Trusted X.509 Certificate

    Use an automated Certificate Authority like Let's Encrypt with Certbot to obtain free, auto-renewing TLS certificates for your domain.

  2. Disable Outdated Protocols

    Configure web servers (NGINX, Apache, Envoy) and load balancers to disable SSLv3, TLS 1.0, and TLS 1.1, allowing only TLS 1.2 and TLS 1.3.

  3. Configure Strong AEAD Cipher Suites

    Enable secure cipher suites like TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256, and TLS_AES_128_GCM_SHA256.

  4. Turn On OCSP Stapling

    Enable OCSP Stapling on your server so it delivers pre-signed certificate validity proofs directly, speeding up connections and improving visitor privacy.

  5. Enable HTTP Strict Transport Security (HSTS)

    Add the Strict-Transport-Security header to ensure browsers only connect to your site via secure HTTPS, preventing downgrade attacks.

Examples

The Armored Transport Analogy

Sending information over plain HTTP is like sending cash down the highway in an open pickup truck: anyone can look inside or take what they want. Using TLS is like sending the cash inside an armored, locked truck with security guards who check identification badges before handing anything over.

Real-World Examples

The Heartbleed Bug in OpenSSL (CVE-2014-0160)

In 2014, a critical security flaw named Heartbleed was discovered in OpenSSL's handling of the TLS Heartbeat extension. Attackers could send a crafted heartbeat message with an incorrect length value, tricking vulnerable servers into sending back 64 kilobytes of active system memory. This allowed attackers to harvest private keys, passwords, and user session cookies from thousands of servers worldwide.

Technical Examples

Testing TLS Handshakes with the OpenSSL Command Linebash
# 1. TEST A SECURE TLS 1.3 CONNECTION
openssl s_client -connect google.com:443 -tls1_3

# Expected Output Highlights:
# CONNECTED(00000003)
# Certificate chain
#  0 s:CN = *.google.com
#    i:C = US, O = Google Trust Services LLC, CN = GTS CA 1C3
# TLS Session Details:
# Protocol       : TLSv1.3
# Cipher         : TLS_AES_256_GCM_SHA384
# Key Exchange   : ECDH, curve P-256 (Perfect Forward Secrecy)
# Verification   : OK

# 2. VERIFY THAT RETIRED TLS 1.0 IS REJECTED
openssl s_client -connect google.com:443 -tls1
# Expected result: Handshake failure / connection reset
Security engineers use openssl s_client to inspect a server's TLS configuration. It reveals the active protocol version, the cipher suite, certificate chains, and whether deprecated protocols like TLS 1.0 are properly rejected.

TLS 1.2 (Older Standard) vs TLS 1.3 (Modern Standard)

AspectTLS 1.2 (Older Standard)TLS 1.3 (Modern Standard)
Handshake Latency2 network round trips (2-RTT, roughly 50-100ms)1 network round trip (1-RTT, roughly 20ms) with optional 0-RTT
Cipher SuitesSupported legacy ciphers (RC4, 3DES, static RSA, CBC mode)Eliminates legacy ciphers, allowing only modern AEAD ciphers
Forward SecrecyOptional: servers could be misconfigured to static RSAMandatory: enforced on every single connection
Certificate PrivacyServer certificate was sent in plain text during handshakeServer certificate is encrypted during handshake
Downgrade ResistanceVulnerable to legacy padding and downgrade attacksArchitecturally resistant to cryptographic downgrade attempts

Advantages

  • Confidential Communication: Blocks eavesdropping across public Wi-Fi, internet service providers, and mobile carriers.
  • Identity Verification: Digital certificates prevent Man-in-the-Middle impersonation of trusted domains.
  • Data Integrity: Authenticated ciphers stop attackers from injecting malicious scripts or modifying data in flight.

Limitations

  • Certificate Expiration Risks: Forgetting to renew an SSL/TLS certificate triggers severe browser security warnings that block visitor access.
  • Domain Visibility via SNI: Standard TLS handshakes expose the target domain name in the Server Name Indication (SNI) header, an issue being addressed by Encrypted Client Hello (ECH).

Interview Questions

What is Perfect Forward Secrecy (PFS) and how does TLS 1.3 guarantee it?

Perfect Forward Secrecy ensures that compromise of a server's long-term private key does not expose past encrypted sessions. In older TLS configurations, static RSA key exchange meant that an attacker who recorded historical traffic could decrypt all of it if the server's private key was ever leaked. TLS 1.3 removes static RSA key exchange completely and mandates Ephemeral Diffie-Hellman (ECDHE). Unique, temporary session keys are created for each connection and discarded immediately after use, keeping past recordings permanently secure.

What is the 0-RTT feature in TLS 1.3 and what security trade-off does it involve?

0-RTT (Zero Round Trip Time) allows a returning client who previously connected to a server to send application data (such as an HTTP GET request) in its very first packet using a pre-shared key, eliminating handshake latency. However, 0-RTT introduces a risk of replay attacks: because the initial data does not yet have forward secrecy, an attacker who intercepts the packet could replay it to the server. For this reason, 0-RTT should only be used for idempotent requests that do not alter account state or trigger transactions.

Practice Questions

  1. Run openssl s_client -connect github.com:443 in your terminal to view the negotiated TLS version, cipher suite, and certificate chain.
  2. Test your own website or a public domain using the Qualys SSL Labs tool (ssllabs.com/ssltest) to inspect its cipher configuration.