Lesson 15 of 15
TLS Handshake
TLS Handshake
TLS (Transport Layer Security) provides encryption, authentication, and integrity for network communication. HTTPS = HTTP + TLS. The TLS handshake establishes a secure connection before any application data is exchanged.
TLS 1.2 Handshake Steps
Client Server
│ │
│── ClientHello ──────────────────>│ (supported ciphers, random)
│ │
│<──────────────── ServerHello ────│ (chosen cipher, random)
│<──────────────── Certificate ────│ (server's public key)
│<──────────── ServerHelloDone ────│
│ │
│── ClientKeyExchange ────────────>│ (pre-master secret)
│── ChangeCipherSpec ─────────────>│
│── Finished ─────────────────────>│
│ │
│<─────────── ChangeCipherSpec ────│
│<──────────────────── Finished ───│
│ │
│ SECURE CONNECTION │
Key Concepts
- Cipher Suite: Combination of key exchange, encryption, and MAC algorithms (e.g.,
TLS_RSA_WITH_AES_256_CBC_SHA256) - Pre-Master Secret: Random value encrypted with server's public key
- Master Secret: Derived from pre-master secret + client random + server random
- Session Keys: Derived from master secret, used for symmetric encryption
Your Task
Implement simulateTLSHandshake(clientCiphers, serverCiphers, serverCert) that simulates a TLS handshake:
- Client sends supported ciphers and a random value
- Server picks the first matching cipher and sends its random + certificate
- Client generates a pre-master secret, derives a master secret (simplified: XOR of all three values)
- Both sides derive session keys
Return an array of handshake message objects with step, from, to, and data.
Also implement deriveSessionKey(preMaster, clientRandom, serverRandom) that returns a simplified "key" (sum mod 256).
Node.js loading...
Loading...
Click "Run" to execute your code.