
Demystifying the TLS Protocol: Evolution from 1.2 to 1.3
Demystifying the TLS Protocol: Evolution from 1.2 to 1.3 and Core Technologies In internet communications, the TCP protocol ensures reliable data transmission, while HTTP defines application-layer data formats. However, both lack a critical element: security. When data travels across untrusted networks, it faces three primary threats:
- Eavesdropping: Sensitive information like passwords can be intercepted
- Tampering: Transmission content may be maliciously modified (e.g., injecting ads into webpages)
- Spoofing: Attackers may impersonate legitimate websites (e.g., fake banking pages)
The Transport Layer Security (TLS) protocol was designed to address these issues, providing three core security mechanisms:
- Encryption: Uses advanced cryptographic algorithms to ensure only communicating parties can decrypt content
- Integrity Verification: Prevents data tampering through message authentication
- Authentication: Validates server/client identities using digital certificates
Learning Tip: For an intuitive understanding of TLS, we recommend watching Why HTTPS is Secure before continuing. This article serves as a technical deep dive focusing on TLS 1.2 and 1.3 mechanisms and their differences.
This article will analyze:
- TLS 1.2's fundamental workings
- Key improvements in TLS 1.3
- Security and efficiency comparisons between both versions
TLS 1.2 uses a classic 2-RTT handshake protocol with this complete workflow:
Client Server
ClientHello -------->
ServerHello
Certificate*
ServerKeyExchange*
CertificateRequest*
<-------- ServerHelloDone
Certificate*
ClientKeyExchange
CertificateVerify*
[ChangeCipherSpec]
Finished -------->
[ChangeCipherSpec]
<-------- Finished
Application Data <-------> Application Data(* indicates optional messages depending on context)
Imagine you (Client) and a bank website (Server) as two agents establishing secure communication in hostile territory.
Objectives
- Confirm mutual authenticity (prevent MITM attacks)
- Negotiate "code phrases" (encryption algorithms)
- Generate unique session keys (Master Secret)
Step-by-Step Process
-
๐ต Step 1: ClientHello - Client Launch Connection
๐ You (Client) say to the server๏ผ
Hello! I support these cipher suites (TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 etc.), here's my random number (Client Random), let's establish a secure session!
Technical Details๏ผ
- Parameters๏ผ
- โ TLS version (e.g., 1.2)
- โ Cipher suite list (e.g., ECDHE_RSA+AES_128_GCM)
- โ Client Random (32-byte random number)
- โ Session ID (for session resumption)
- Cipher Suite Example๏ผ
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256- Key Exchange: ECDHE (ephemeral keys for forward secrecy)
- Authentication: RSA signatures
- Symmetric Encryption: AES-128-GCM
- Hash Algorithm: SHA-256
- Parameters๏ผ
-
๐ข Step 2: ServerHello - Server Negotiation Response
๐ Bank Website replies
Received! We'll use ECDHE_RSA+AES_128_GCM, here's my random number (Server Random), and my ID (certificate)!
Key Actions๏ผ
- Selects optimal cipher suite from client's options
- Generates Server Random (32 bytes) for key derivation
- Includes session ID (for resumption)
-
๐ Step 3: Certificate - Identity Authentication
๐ Bank Website presents certificate
This is an X.509 certificate issued by DigiCert, containing my public key and CA signature, please verify
Verification Process๏ผ
- Validates certificate chain trust
- Checks certificate validity period and domain match
- Confirms certificate isn't revoked (OCSP/CRL checks)
-
๐ Step 4: ServerKeyExchange - Key Exchange Parameters
๏ผRequired only for ephemeral key algorithms like ECDHE/DHE๏ผ
๐ Bank Website adds๏ผHere are elliptic curve parameters (secp256r1) and my ephemeral public key for key calculation
Technical Points๏ผ
- Includes signature to prevent parameter tampering
- Ephemeral keys provide forward secrecy (PFS)
-
๐ก๏ธ Step 5: CertificateRequest (Optional)
Upon completing these steps, the TLS handshake concludes:
โ
All communication now uses AES-128-GCM encryption
โ
Unique per-session keys ensure forward secrecy
โ
Browser displays ๐ icon (HTTPS)
| Step | Core Purpose | Key Technology |
|---|---|---|
| ClientHello | Initiate handshake, offer capabilities | Cipher suite negotiation |
| ServerHello | Confirm encryption scheme | Optimal cipher selection |
| Certificate | Identity verification | X.509 certificate chain validation |
| KeyExchange | Key material exchange | ECDHE/RSA key exchange |
| Finished | Handshake integrity check | PRF function computation |
Imagine establishing a super-secure chat room requiring multiple keys:
- Key 1: Encrypt your messages
- Key 2: Encrypt friend's messages
- Key 3: Verify message integrity
- ...
TLS 1.2's key derivation acts as a key factory, using initial "raw material" (Pre-Master Secret) mixed with random numbers to "juice out" all required keys.
-
Stage 1: Create "Universal Base Key" (Master Secret)
Starting with temporary
pre_master_secret, process it into a more secure base:Formula:
master_secret = PRF( input: pre_master_secret, label: "master secret", seasoning: client_random + server_random )- "Juicer": TLS 1.2's
PRF(pseudorandom function), essentially a mathematical blender (HMAC-SHA256 based). - "Seasoning": Client/server random numbers exchanged during handshake ensure unique session keys.
Purpose: This
master_secretacts as the "mother key" for deriving subsequent keys but isn't directly used for encryption. - "Juicer": TLS 1.2's
-
Stage 2: Mass-Produce "Session Key Bundle" (Key Block)
Using the base key to generate practical encryption keys:
Formula:
input: master_secret, label: "key expansion", seasoning: server_random + client_random (reversed!) )
Key Takeaways
- Layered Derivation:
pre_master_secretโmaster_secretโkey_block. - Randomness Assurance: Client/server randoms ensure unique session keys.
- Precise Allocation: Specialized keys for specific tasks like factory assembly.
The TLS record layer functions like a secure packaging workshop, preparing data (e.g., web content, passwords) for encrypted network transmission in two phases:
-
Phase 1: Plaintext (Pre-Packaging)
Original data (e.g., "hello") is structured as:
struct { ContentType type; // Label: package type? // 20: Key change notice // 21: Alert // 22: Handshake // 23: User data ...