6. SSL/TLS Encryption & Handshake Mechanics
Symmetric vs Asymmetric Encryption in TLS
Transport Layer Security (TLS) relies on two distinct cryptographic primitives: Asymmetric encryption for the initial handshake and identity verification, and Symmetric encryption for the bulk data transfer. This hybrid approach balances security with high-performance throughput.
| Encryption Type | TLS Role |
|---|---|
| Asymmetric | Key exchange and server authentication (RSA/ECDH) |
| Symmetric | Bulk data encryption (AES-GCM/ChaCha20) |
Asymmetric encryption is computationally expensive, so it is only used to establish a shared 'master secret'. Once this secret is derived, both parties switch to symmetric encryption, which is significantly faster for encrypting large payloads.
from cryptography.hazmat.primitives.ciphers.aead import AESGCM import os # Symmetric encryption demonstration key = AESGCM.generate_key(bit_length=256) aesgcm = AESGCM(key) data = b'Sensitive session data' nonce = os.urandom(12) # Encrypt ct = aesgcm.encrypt(nonce, data, None) print(f'Ciphertext: {ct.hex()}')
TLS 1.2 vs TLS 1.3 Handshake Flow
TLS 1.2 requires two round-trips to complete the handshake, introducing significant latency. TLS 1.3 optimizes this by defaulting to a one-round-trip flow and removing legacy, insecure cipher suites.
In TLS 1.3, the ClientHello message includes a key_share extension, allowing the server to calculate the shared secret immediately. In contrast, TLS 1.2 requires multiple messages to negotiate versions and exchange keys separately.
# Analyze TLS handshake version with OpenSSL openssl s_client -connect google.com:443 -tls1_2 < /dev/null openssl s_client -connect google.com:443 -tls1_3 < /dev/null
Cipher Suites and Handshake Mechanics
A cipher suite, such as TLS_AES_256_GCM_SHA384, defines the specific algorithms used for the connection. In this suite, TLS is the protocol, AES_256_GCM is the authenticated encryption, and SHA384 is the PRF/Hashing algorithm.
The handshake proceeds through: ClientHello (proposes suites), ServerHello (selects suite), Certificate (identity), Key Exchange, and Finished (verifying integrity of the handshake).
import hashlib # Mocking a HMAC-SHA384 verification step secret = b'shared_master_secret' handshake_transcript = b'ClientHelloServerHello' mac = hashlib.sha384(secret + handshake_transcript).digest() print(f'Handshake Verification Hash: {mac.hex()}')
Auditing Configurations with OpenSSL
Operators use 'openssl s_client' to probe remote servers for supported protocols and cipher suites. This is vital for ensuring compliance and identifying weak configurations that support deprecated protocols like TLS 1.0 or 1.1.
By iterating through specific flags, one can map the security posture of an endpoint without active exploitation.
# Testing for weak SSL/TLS protocols openssl s_client -connect target_site.com:443 -ssl3 openssl s_client -connect target_site.com:443 -tls1_0 # Checking server certificate details openssl s_client -showcerts -connect target_site.com:443
Knowledge Check
Ready to test your understanding of 6. SSL/TLS Encryption & Handshake Mechanics?