sequenceDiagram
participant Client
participant Server
Note over Client,Server: TCP three-way Handshake
Client->>Server: SYN
Server->>Client: SYN-ACK
Client->>Server: ACK
Note over Client,Server: TLS 1.2 Handshake (2-RTT)
Client->>Server: ClientHello (TLS version, cipher suites, client random)
Server->>Client: ServerHello (chosen cipher suite, server random)
Server->>Client: Certificate (server cert chain, signed by CA)
Server->>Client: ServerHelloDone
Note over Client: Verify certificate chain
Note over Client: Generate pre-master secret
Note over Client,Server: Key Exchange
Client->>Server: ClientKeyExchange (pre-master secret, encrypted with server pubkey)
Client->>Server: ChangeCipherSpec
Client->>Server: Finished (HMAC of handshake)
Note over Server: Derive session key
Server->>Client: ChangeCipherSpec
Server->>Client: Finished (HMAC of handshake)
Note over Client,Server: Encrypted Communication
Client->>Server: Application Data
Server->>Client: Application Data
TLS Cryptography and Handshake Overview
Understanding the Foundations of Secure Communication
Introduction
Transport Layer Security (TLS) is the backbone of secure communication on the internet. It ensures that data transmitted between clients and servers remains confidential and authenticated.
- Types of Ciphers
- Symmetric Key Cryptography
- Asymmetric Key Cryptography
- Hash Functions
- TLS Overview
- TLS 1.2
- TLS 1.3
Types of Ciphers
Symmetric Key Cryptography
| Cipher | Usage |
|---|---|
| AES | Modern standard, widely used in TLS (AES-GCM, AES-CBC) |
| ChaCha20 | Fast in software, used in TLS as ChaCha20-Poly1305 |
| DES | Insecure, banned in modern TLS |
| 3DES | Legacy, slow and small block size; being phased out in TLS |
| RC4 | Severe weaknesses, banned in TLS |
| Blowfish | Legacy, 64-bit block size limits suitability for TLS |
| Twofish | AES finalist, used in some systems |
Asymmetric Key Cryptography
| Cipher | Usage |
|---|---|
| RSA | Widely used for key exchange and digital signatures in TLS (RSA key exchange, RSA signatures) |
| DSA | Digital Signature Algorithm (signature-only; not used for encryption or key exchange). Legacy in TLS and not used in TLS 1.3. |
| ECDSA | Used for digital signatures in TLS (ECDSA signatures) |
| Diffie-Hellman (DH) | Used for secure key exchange in TLS (DHE) |
| Elliptic Curve Diffie-Hellman (ECDH) | Used for secure key exchange in TLS (ECDHE) |
| Ed25519 | Modern signature scheme, not widely used in TLS yet |
Hash Functions
| Hash Function | Usage |
|---|---|
| SHA-256 | Widely used in TLS for message authentication and digital signatures |
| SHA-384 | Used in TLS for stronger security (e.g., in ECDSA signatures) |
| SHA-1 | Insecure, banned in modern TLS |
| MD5 | Insecure, banned in modern TLS |
TLS Overview
HTTPS is the secure version of HTTP, and it relies on TLS to encrypt the communication between the client and the server. The TLS handshake is the process that establishes a secure connection by negotiating cryptographic parameters and exchanging keys.
HTTPS connection consists of two phases:
- TCP three-way handshake: SYN, SYN-ACK, ACK to establish a TCP connection.
- TLS handshake: The client and server negotiate cipher suites, verify the server’s certificate, and derive a shared session key.
After this process, the client and server can securely transmit data using the established TLS connection.
TLS 1.2
TLS 1.2 requires 2 round trips (2-RTT) for the handshake. The server sends its certificate and the client encrypts a pre-master secret with the server’s public key (RSA key exchange), or they use ECDHE for forward secrecy.
TLS 1.3
TLS 1.3 reduces the handshake to 1 round trip (1-RTT) by embedding the key share in the ClientHello. It removes weak algorithms (RSA key exchange, MD5, SHA-1, CBC mode) and mandates forward secrecy via ECDHE.
sequenceDiagram
participant Client
participant Server
Note over Client,Server: TCP three-way Handshake
Client->>Server: SYN
Server->>Client: SYN-ACK
Client->>Server: ACK
Note over Client,Server: TLS 1.3 Handshake (1-RTT)
Client->>Server: ClientHello (TLS 1.3, cipher suites, ECDHE key share, client random)
Note over Server: Select cipher suite
Note over Server: Generate ECDHE key share
Note over Server: Derive handshake keys
Server->>Client: ServerHello (chosen cipher suite, ECDHE key share)
Server->>Client: EncryptedExtensions
Server->>Client: Certificate (server cert chain, signed by CA)
Server->>Client: CertificateVerify (signature over handshake)
Server->>Client: Finished (HMAC)
Note over Client: Verify certificate & signature
Note over Client: Derive session keys
Client->>Server: Finished (HMAC)
Note over Client,Server: Encrypted Communication
Client->>Server: Application Data
Server->>Client: Application Data