TLS

Protocols & Transport Security Notes Jan 6, 2025 BASH

Definition

Every time you see that little padlock icon in your browser, TLS (Transport Layer Security) is working behind the scenes to protect your data. It is the cryptographic protocol that makes secure communication possible on the internet - encrypting everything from your passwords to your credit card numbers so that even if someone intercepts the traffic, they cannot read it.

TLS does three critical things. First, it encrypts the communication so eavesdroppers see only gibberish. Second, it verifies the server’s identity so you know you are really talking to your bank and not an imposter. Third, it ensures data integrity so you know the message was not tampered with in transit. This combination makes secure web browsing, online banking, and e-commerce possible.

The magic happens in the TLS handshake - a carefully choreographed dance that occurs before any real data is transmitted. Your browser and the server agree on encryption algorithms, the server proves its identity with a certificate, and both sides generate session keys. This all happens in milliseconds, typically adding only 1-2 round trips to connection setup. TLS 1.3, the current standard, further optimized this process and removed older, weaker encryption options. When people say “HTTPS,” they mean HTTP protected by TLS.

Example

Online banking: When you log into your bank’s website, TLS encrypts your username and password so they cannot be stolen, verifies you are connected to the real bank, and protects your account information as you browse.

E-commerce: When you enter your credit card on Amazon, TLS ensures that card number is encrypted the entire journey to Amazon’s servers. Even your internet provider cannot see it.

Email encryption: When you send email through Gmail or Outlook, TLS encrypts the connection to the email server. Many email providers also use TLS between their servers, protecting your messages in transit.

API security: Every modern API uses TLS. When your weather app checks the forecast, when your social media app loads posts, when your smart home talks to its cloud - TLS protects it all.

Analogy

The Diplomatic Pouch: Before sending sensitive documents, diplomats seal them in special pouches that are tamper-evident and can only be opened by authorized recipients. TLS creates a similar secure channel for data - sealed against eavesdropping and tampering.

The Whispering Room: Imagine meeting someone in a soundproof room where you first verify each other’s identities, then speak freely knowing no one can overhear or impersonate either party. TLS creates this private communication channel digitally.

The Security Badge Verification: When entering a secure building, a guard checks your badge against their records before letting you in. TLS certificates work similarly - your browser checks the server’s certificate against trusted authorities before establishing a secure connection.

The Sealed Envelope: When you send a letter in a sealed envelope, only the intended recipient can open it, and they can tell if someone tried to tamper with it. TLS wraps every piece of data in a digital envelope with the same properties.

Diagram

sequenceDiagram
    participant C as Client
    participant S as Server

    rect rgb(200, 230, 200)
        Note over C,S: TLS 1.3 Handshake (1-RTT)
        C->>S: ClientHello
        Note right of C: Supported ciphers
Key share (ECDHE)
Supported versions S->>C: ServerHello + EncryptedExtensions Note left of S: Selected cipher
Key share
Certificate
CertificateVerify
Finished end rect rgb(240, 230, 200) Note over C,S: Certificate Verification C->>C: Verify server certificate Note right of C: Check CA signature
Check validity dates
Check domain name end rect rgb(200, 220, 240) Note over C,S: Handshake Complete C->>S: Finished Note right of C: Handshake hash
encrypted with
handshake key end rect rgb(220, 240, 220) Note over C,S: Encrypted Application Data C->>S: Application Data (encrypted) S->>C: Application Data (encrypted) Note over C,S: All data encrypted with
session keys derived from
ECDHE key exchange end

Code Example


# Test TLS connection and view certificate
openssl s_client -connect api.example.com:443 -showcerts

# View TLS version and cipher
curl -vI https://api.example.com 2>&1 | grep -E "TLS|SSL"

# Output shows TLS details
* TLSv1.3 (OUT), TLS handshake
* TLSv1.3 (IN), TLS handshake
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384

# Node.js enforce TLS 1.3
const https = require('https');
const options = {
  minVersion: 'TLSv1.3',
  maxVersion: 'TLSv1.3'
};

Security Notes

SECURITY NOTES

CRITICAL: TLS encryption is essential. Use TLS 1.2+ with modern cipher suites.

TLS Version Selection:

  • TLS 1.3: Use for new APIs; latest secure version
  • TLS 1.2: Minimum acceptable version
  • Disable older: Disable SSL 2.0, SSL 3.0, TLS 1.0, TLS 1.1
  • Version negotiation: Allow clients to negotiate highest supported version
  • Downgrade prevention: Prevent downgrade to older TLS versions

Cipher Suite Selection:

  • Forward secrecy: Use ECDHE or DHE for ephemeral keys
  • Strong encryption: AES-GCM or ChaCha20-Poly1305
  • Authentication: ECDSA or RSA certificates
  • Disable weak: No NULL, RC4, DES, MD5-based ciphers
  • Modern suites: Prioritize modern cipher suites

Certificate Management:

  • Valid certificates: Obtain from trusted CAs
  • Certificate expiration: Monitor and renew before expiry
  • Domain validation: Certificate matches domain name
  • Key size: RSA 2048+ bits, EC P-256 minimum
  • SAN certificates: Use Subject Alternative Names for multiple domains

TLS Handshake Security:

  • Certificate pinning: Pin certificates for critical APIs
  • OCSP stapling: Provide certificate status in TLS handshake
  • Certificate transparency: Audit certificate issuance
  • Mutual TLS: Use client certificates for additional security
  • Renegotiation: Disable unsafe renegotiation

Session Security:

  • Session resumption: Securely resume sessions with tickets
  • Perfect forward secrecy: Use ephemeral keys for each session
  • Session timeout: Implement appropriate session timeouts
  • Session stealing: Prevent session token theft
  • Bind sessions: Bind session to client IP/user agent

Standards & RFCs