TLS Handshake
TLS Cipher Negotiation
Read aloud is unavailable in this browser.
The Language of Security: Cipher Negotiation
When a TLS handshake begins, the client and server face an immediate challenge: they must agree on a common set of cryptographic algorithms before any secure communication can occur. This agreement process is called cipher negotiation, and it's far more complex and security-critical than it might initially appear.
Cipher negotiation determines everything about the connection's security:
- How keys will be exchanged (RSA, Diffie-Hellman, Elliptic Curve)
- How the server will prove its identity (RSA signature, ECDSA, EdDSA)
- How data will be encrypted (AES, ChaCha20)
- How message integrity will be verified (HMAC-SHA256, GCM, Poly1305)
A poor choice in cipher negotiation can undermine the entire security model. Using deprecated algorithms exposes connections to known attacks. Misconfigured servers might allow attackers to force weak ciphers through downgrade attacks. Understanding cipher negotiation is essential for anyone configuring secure systems.
This page provides a comprehensive examination of TLS cipher negotiation. You will understand cipher suite naming conventions, the negotiation protocol, security implications of different choices, TLS 1.2 vs 1.3 cipher differences, and best practices for secure configuration.
Anatomy of a Cipher Suite
A cipher suite is a combination of cryptographic algorithms that together provide all the security functions needed for a TLS connection. Understanding cipher suite naming is essential for security configuration.
TLS 1.2 Cipher Suite Format:
TLS 1.2 cipher suites follow a specific naming pattern that describes all components:
TLS_[Key Exchange]_[Authentication]_WITH_[Encryption]_[MAC]
Let's dissect a concrete example:
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
- TLS: Protocol identifier
- ECDHE: Elliptic Curve Diffie-Hellman Ephemeral (key exchange)
- RSA: RSA signature (server authentication)
- WITH: Separator
- AES_256_GCM: AES-256 in Galois/Counter Mode (encryption + authentication)
- SHA384: Hash function for key derivation (not integrity—GCM handles that)
| Component | Purpose | Examples | Security Implications |
|---|---|---|---|
| Key Exchange | Establish shared secret over insecure channel | RSA, DHE, ECDHE, PSK | ECDHE provides forward secrecy; RSA does not |
| Authentication | Verify server (and optionally client) identity | RSA, ECDSA, EdDSA | Must match certificate type; ECDSA more efficient |
| Encryption | Encrypt application data | AES-256, AES-128, ChaCha20 | AES-GCM preferred; ChaCha20 on mobile/embedded |
| Mode of Operation | How block cipher processes data | GCM, CBC, CCM | GCM is AEAD; CBC vulnerable to padding oracles |
| Message Authentication | Verify message integrity | HMAC-SHA256, GCM (built-in), Poly1305 | AEAD modes integrate authentication |
| PRF Hash (TLS 1.2) | Key derivation and Finished message | SHA256, SHA384 | Must be collision-resistant; SHA384 for higher security |
TLS 1.3 Cipher Suite Simplification:
TLS 1.3 dramatically simplified cipher suite naming by separating key exchange from the cipher specification. Key exchange is now negotiated via the supported_groups extension, and signature algorithms via the signature_algorithms extension.
TLS 1.3 cipher suites only specify:
TLS_[AEAD Algorithm]_[Hash Algorithm]
TLS 1.3 Cipher Suites:
TLS_AES_128_GCM_SHA256— AES-128-GCM with SHA-256 HKDFTLS_AES_256_GCM_SHA384— AES-256-GCM with SHA-384 HKDFTLS_CHACHA20_POLY1305_SHA256— ChaCha20-Poly1305 with SHA-256 HKDFTLS_AES_128_CCM_SHA256— AES-128-CCM with SHA-256 (constrained devices)TLS_AES_128_CCM_8_SHA256— AES-128-CCM with 8-byte tag (IoT)
TLS 1.2's cipher suite explosion (over 300 combinations) made configuration error-prone and analysis difficult. TLS 1.3's approach—only 5 cipher suites, all with mandatory forward secrecy and AEAD—eliminates entire classes of vulnerabilities. You can't misconfigure what doesn't exist.
The Negotiation Protocol
Cipher negotiation occurs during the TLS handshake's Hello message exchange. The process is asymmetric: the client proposes, and the server chooses.
ClientHello Cipher Proposal:
The client includes an ordered list of cipher suites in its ClientHello message. This list typically contains:
- Most preferred cipher suites first
- All cipher suites the client supports
- Order based on client's security preferences
Example ClientHello cipher_suites (TLS 1.2 client):
cipher_suites (12 suites)
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (0xc02c)
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (0xc030)
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (0xc02b)
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (0xc02f)
TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 (0xcca9)
TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (0xcca8)
TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 (0x009f)
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 (0x009e)
TLS_RSA_WITH_AES_256_GCM_SHA384 (0x009d)
TLS_RSA_WITH_AES_128_GCM_SHA256 (0x009c)
TLS_RSA_WITH_AES_256_CBC_SHA (0x0035)
TLS_RSA_WITH_AES_128_CBC_SHA (0x002f)
ServerHello Cipher Selection:
The server examines the client's list and selects ONE cipher suite that:
- Appears in the client's list
- Is supported by the server
- Is compatible with the server's certificate
- Meets the server's security requirements
Selection Strategies:
Servers can use different selection strategies:
-
Client preference order: Select the first suite from the client's list that the server supports. This respects client preferences but can result in weaker security if clients are poorly configured.
-
Server preference order: Ignore client order; select the first suite from the SERVER's preference list that the client supports. This enforces server security policy.
Modern best practice: Server preference order with a carefully curated server list.
The cipher suite must be compatible with the server's certificate. An RSA certificate cannot be used with ECDHE_ECDSA suites. A server with only an RSA certificate must select an RSA authentication cipher suite, regardless of client preferences for ECDSA.
Key Exchange Algorithms in Depth
The key exchange algorithm determines how the client and server establish a shared secret over an insecure channel. This is perhaps the most security-critical component of the cipher suite.
RSA Key Exchange (Deprecated in TLS 1.3):
In RSA key exchange, the client generates a random pre-master secret, encrypts it with the server's public key (from the certificate), and sends it to the server. Only the server, possessing the private key, can decrypt it.
Critical Weakness: No forward secrecy. If the server's private key is ever compromised, all recorded sessions can be decrypted. This motivated TLS 1.3's removal of RSA key exchange.
- •Client generates 48-byte pre-master secret
- •Encrypted with server's RSA public key
- •Sent in ClientKeyExchange message
- •No forward secrecy—long-term key compromise reveals all sessions
- •Vulnerable to BEAST, CRIME (with compression)
- •Removed entirely from TLS 1.3
- •Each connection uses fresh key pairs
- •ECDHE: Elliptic Curve Diffie-Hellman Ephemeral
- •DHE: Finite Field Diffie-Hellman Ephemeral
- •Forward secrecy: past sessions protected if long-term key compromised
- •Mandatory in TLS 1.3
- •Should be required in TLS 1.2 configurations
ECDHE (Elliptic Curve Diffie-Hellman Ephemeral):
The modern standard for key exchange. ECDHE uses elliptic curve mathematics to achieve the same security as DHE with much smaller key sizes:
| Curve | Security Level | Equivalent RSA | NIST Classification |
|---|---|---|---|
| X25519 | 128 bits | RSA-3072 | Not NIST-approved |
| P-256 (secp256r1) | 128 bits | RSA-3072 | NIST Suite B |
| P-384 (secp384r1) | 192 bits | RSA-7680 | NIST Suite B |
| P-521 (secp521r1) | 256 bits | RSA-15360 | NIST Suite B |
X25519 is the most widely deployed curve, designed by Daniel J. Bernstein. It offers excellent performance, constant-time implementations (resistance to timing attacks), and avoids potential weaknesses in NIST curves.
DHE (Finite Field Diffie-Hellman Ephemeral):
The classical Diffie-Hellman algorithm uses modular exponentiation. Still supported but generally slower than ECDHE and requires larger key sizes:
- 2048-bit DHE ≈ 112 bits of security
- 3072-bit DHE ≈ 128 bits of security
- 4096-bit DHE ≈ 140 bits of security
Prefer ECDHE when available. DHE remains a fallback for legacy systems.
In TLS 1.3, key exchange curves are negotiated via the supported_groups extension, separately from cipher suites. The client includes key shares for expected groups in ClientHello. If the server prefers a different group, it sends HelloRetryRequest. Modern configurations typically offer X25519 first, then P-256, covering virtually all servers.
Authentication Algorithms
Authentication in TLS serves a distinct purpose from key exchange: it proves the identity of the server (and optionally the client). The authentication algorithm must match the type of certificate deployed.
RSA Authentication:
The server's certificate contains an RSA public key. Authentication occurs through:
- TLS 1.2 (DHE/ECDHE): Server signs the ServerKeyExchange message with its RSA private key
- TLS 1.3: Server signs the handshake transcript in the CertificateVerify message
RSA Signature Schemes (TLS 1.3):
rsa_pkcs1_sha256— PKCS#1 v1.5 with SHA-256 (legacy compatibility)rsa_pss_rsae_sha256— RSA-PSS with SHA-256 (recommended)rsa_pss_pss_sha256— RSA-PSS with PSS OID in certificate
RSA-PSS (Probabilistic Signature Scheme) is preferred over PKCS#1 v1.5 due to stronger security proofs.
ECDSA (Elliptic Curve Digital Signature Algorithm):
The server's certificate contains an EC public key. ECDSA offers:
- Smaller signatures than RSA at equivalent security levels
- Faster signature verification
- Native curve compatibility with ECDHE key exchange
ECDSA Curves:
- P-256 (secp256r1) — Most widely deployed
- P-384 (secp384r1) — Higher security, slower
- P-521 (secp521r1) — Maximum security, rarely used
EdDSA (Edwards-Curve Digital Signature Algorithm):
The newest authentication algorithm, based on Edwards curves:
ed25519— 128-bit security, constant-time by designed448— 224-bit security
EdDSA offers deterministic signatures (no randomness needed), resistance to timing attacks, and simple, fast implementations. Ed25519 is gaining adoption in TLS 1.3.
Signature Scheme Selection (TLS 1.3):
Clients and servers communicate supported signature algorithms via the signature_algorithms extension. The intersection determines which can be used.
| Algorithm | Key Size (128-bit security) | Signature Size | Speed (Sign/Verify) | Notes |
|---|---|---|---|---|
| RSA (PKCS#1) | 3072 bits | 384 bytes | Slow/Fast | Universal support; large signatures |
| RSA-PSS | 3072 bits | 384 bytes | Slow/Fast | Stronger proofs than PKCS#1 |
| ECDSA P-256 | 256 bits | 64 bytes | Fast/Fast | Small signatures; widely deployed |
| ECDSA P-384 | 384 bits | 96 bytes | Medium/Medium | Higher security; government/financial |
| Ed25519 | 256 bits | 64 bytes | Very Fast/Very Fast | Deterministic; timing-resistant |
The authentication algorithm is constrained by the server's certificate. An ECDSA cipher suite requires an EC certificate. If you only have an RSA certificate, you cannot use ECDSA authentication, regardless of client preferences. Many sites now deploy dual certificates (RSA + ECDSA) to serve all clients optimally.
Encryption Algorithms and AEAD
Once keys are established, the encryption algorithm protects all application data. Modern TLS exclusively uses AEAD (Authenticated Encryption with Associated Data) ciphers, which provide both confidentiality and integrity in a single operation.
Why AEAD?
Historically, encryption (confidentiality) and MAC (integrity) were separate operations:
- Encrypt data with AES-CBC
- MAC the ciphertext with HMAC-SHA
This "MAC-then-Encrypt" or "Encrypt-then-MAC" approach created vulnerabilities:
- Padding oracle attacks (POODLE, Lucky13): CBC mode padding errors leaked information
- Timing attacks: MAC verification time revealed plaintext length
- Implementation complexity: Two operations = more room for errors
AEAD ciphers integrate encryption and authentication into a single, atomic operation, eliminating these attack surfaces.
AES-GCM (Galois/Counter Mode):
The dominant AEAD cipher in TLS. Hardware acceleration (AES-NI) makes it extremely fast on modern processors.
Properties:
- Block cipher: AES-128 or AES-256
- Mode: Galois/Counter Mode
- Tag size: 128 bits (16 bytes)
- Nonce: 96 bits (12 bytes) — must never repeat with same key
AES-GCM Operation:
- Counter mode encryption (CTR) provides confidentiality
- Galois field multiplication (GHASH) provides authentication
- Single pass over the data
- Authentication tag covers ciphertext + associated data (e.g., sequence number)
Vulnerability: Nonce Reuse
If the same nonce is ever used twice with the same key, AES-GCM's security completely collapses:
- XOR of plaintexts is revealed
- Authentication key is recoverable
- All data encrypted with that key is compromised
TLS mitigates this by deriving unique nonces from the record sequence number, which is guaranteed to be unique and sequential.
- •Hardware acceleration (AES-NI) on most CPUs
- •Single-pass encryption + authentication
- •Parallelizable encryption
- •Well-analyzed, standardized (NIST)
- •Universal browser and server support
- •Catastrophic if nonce reused
- •Slower without hardware acceleration
- •Short nonce limits (2^32 records with same key)
- •Tag truncation vulnerabilities if misused
- •Complex implementation (field multiplication)
ChaCha20-Poly1305:
Alternative AEAD cipher designed by Daniel J. Bernstein. Optimized for software implementations without hardware AES support.
Properties:
- Stream cipher: ChaCha20 (20 rounds)
- MAC: Poly1305 one-time authenticator
- Key: 256 bits
- Nonce: 96 bits (12 bytes)
- Tag: 128 bits (16 bytes)
Why ChaCha20-Poly1305?
- Mobile devices: Many ARM processors lack AES-NI; ChaCha20 is 3x faster in software
- Constant-time: Naturally resistant to timing side-channels
- Simplicity: Easier to implement correctly than AES-GCM
- Independent design: If AES has undiscovered weaknesses, ChaCha20 provides backup
Google deployed ChaCha20-Poly1305 in Chrome/Android for connections to their servers, specifically for mobile battery and performance improvements.
For servers with significant mobile traffic, offering ChaCha20-Poly1305 improves user experience. Modern servers can detect client capabilities and prefer AES-GCM for desktop clients (with AES-NI) while serving ChaCha20-Poly1305 to mobile clients.
Cipher Suite Security Tiers
Not all cipher suites provide equal security. They can be categorized into tiers based on their cryptographic properties and known vulnerabilities.
| Tier | Characteristics | Example Cipher Suites | Recommendation |
|---|---|---|---|
| 🟢 Modern (TLS 1.3) | AEAD only, mandatory forward secrecy, current algorithms | TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256 | Enable and prefer |
| 🟢 Strong (TLS 1.2) | ECDHE/DHE, AEAD, SHA-256+ | TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 | Enable for compatibility |
| 🟡 Acceptable (TLS 1.2) | ECDHE/DHE, CBC mode, SHA-256+ | TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA256 | Enable only if necessary |
| 🟠 Legacy (TLS 1.2) | RSA key exchange, CBC, SHA-1 | TLS_RSA_WITH_AES_256_CBC_SHA | Disable unless required for legacy |
| 🔴 Weak (Deprecated) | DES, 3DES, RC4, MD5, export ciphers | TLS_RSA_WITH_3DES_EDE_CBC_SHA | Disable immediately |
| ⛔ Broken (Banned) | NULL encryption, anonymous DH, export 40-bit | TLS_RSA_WITH_NULL_SHA, TLS_DH_anon_* | Never enable under any circumstances |
Known Vulnerabilities by Algorithm:
RC4 — Stream cipher with measurable biases. BEAST attack mitigation drove RC4 adoption, then RC4 attacks (Bar-Mitzvah, NOMORE) led to deprecation.
3DES — Sweet32 attack: after 2^32 blocks (~32GB), birthday collision reveals plaintext patterns. Too slow and weak.
CBC mode — Padding oracles (POODLE, Lucky13) enabled plaintext recovery. Timing side-channels in MAC verification. Requires complex countermeasures.
SHA-1 — Collision attacks demonstrated (SHAttered). No longer considered secure for signatures.
RSA key exchange — No forward secrecy. Bleichenbacher attacks on PKCS#1 padding (F1 Racing, ROBOT).
Export ciphers — Deliberately weakened (40-bit, 56-bit keys) for 1990s US export regulations. FREAK, Logjam attacks exploited servers still supporting these.
If your server supports weak ciphers, attackers can potentially force their use through downgrade attacks—manipulating the handshake to select weaker algorithms. TLS 1.3's encrypted handshake and TLS 1.2's renegotiation info extension mitigate this, but the safest defense is to not offer weak ciphers at all.
Modern Configuration Best Practices
Configuring cipher suites correctly is critical for security. Here are current best practices for server configuration.
- •Enable TLS 1.3 — Mandatory forward secrecy, reduced handshake latency, encrypted handshake. No reason not to enable.
- •Prefer server cipher order — Don't let misconfigured clients choose weak ciphers. Server should enforce its preferences.
- •Offer ECDHE suites only (TLS 1.2) — Disable RSA key exchange. Forward secrecy should be mandatory.
- •Use AEAD ciphers only — AES-GCM or ChaCha20-Poly1305. Disable all CBC mode ciphers if possible.
- •Prefer X25519, then P-256 — For ECDHE curves. Both provide excellent security; X25519 is faster.
- •Disable TLS 1.0, TLS 1.1 — Deprecated as of 2020. Major browsers no longer support them.
- •Consider dual certificates — RSA + ECDSA certificates cover all clients while optimizing for modernity.
- •Test with SSL Labs — Use Qualys SSL Labs to verify configuration and achieve A+ rating.
1234567891011121314151617181920212223242526
# Modern TLS Configuration for Nginx # Enable only TLS 1.2 and TLS 1.3ssl_protocols TLSv1.2 TLSv1.3; # Cipher suites - TLS 1.3 ciphers are automatic# TLS 1.2 ciphers ordered by preferencessl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256'; # Server preference orderssl_prefer_server_ciphers on; # ECDHE curvesssl_ecdh_curve X25519:secp256r1:secp384r1; # Session settingsssl_session_timeout 1d;ssl_session_cache shared:SSL:50m;ssl_session_tickets off; # Disable for forward secrecy # OCSP staplingssl_stapling on;ssl_stapling_verify on; # HSTS (optional but recommended)add_header Strict-Transport-Security "max-age=63072000" always;Stricter configurations improve security but may break older clients (IE 10, Android 4.x, Java 7). Know your user base. For public websites, a compatibility scan with tools like testssl.sh helps identify the impact of configuration changes.
KEEP LEARNING
There’s more to understand.
You’re reading the introduction. Create a free account to read the complete lesson, save notes and keep track of your progress.