π Stage 2: Deep Dive into TLS¶
π― Learning Objectives¶
By the end of this stage, you will be able to:
- Explain what TLS provides (confidentiality, integrity, authentication).
- Describe the TLS handshake process in detail.
- Understand certificates, certificate chains, and PKI.
- Use openssl, curl, and Wireshark to inspect and troubleshoot TLS sessions.
- Explain the key differences between TLS 1.2 and TLS 1.3.
π Suggested Duration¶
2 weeks (10β12 hours total) - 5h theory - 5β7h labs
π Section 1: What TLS Does¶
π§ Concepts to Learn¶
TLS ensures:
- Confidentiality β encryption of data.
- Integrity β protection from tampering (MAC / AEAD).
- Authentication β verifies the serverβs (and optionally clientβs) identity using certificates.
π§© Key Idea¶
Without TLS, HTTP is plaintext:
With TLS, the same request becomes encrypted binary data over TCP.
π Self-Check¶
- Which security properties does TLS guarantee?
- Why does HTTP rely on TLS for security instead of implementing its own encryption?
π Section 2: Understanding the TLS Handshake¶
π§ Concepts to Learn¶
The handshake establishes: - Which cipher suite will be used. - The shared session key for encryption. - The server identity (via certificate). - Optional client certificate authentication.
π§© TLS 1.2 Handshake (Simplified)¶
π§© TLS 1.3 Handshake (Simplified)¶
TLS 1.3 reduces round-trips for speed and stronger security:
π§ͺ Lab 1 β Observe a TLS Handshake¶
-
Run:
-
Observe:
- The chosen TLS version.
- The cipher suite.
- The certificate chain.
-
The
Verify return code. -
Try forcing specific versions:
- Optional: capture the session in Wireshark (
tcp.port==443) and look at βHandshake Protocolβ messages.
π Section 3: Certificates and PKI¶
π§ Concepts to Learn¶
- Certificate Authority (CA) β trusted entity that signs certificates.
- Root CA β Intermediate CA β Server certificate.
- X.509 format for certificates.
- Certificates contain:
- Subject (who it belongs to)
- Issuer (who signed it)
- Validity period
- Public key
- Extensions (SAN, Key Usage, etc.)
π§ͺ Lab 2 β Build Your Own PKI (Root β Intermediate β Server)¶
Step 1: Create Root CA
Step 2: Create Intermediate CA
Step 3: Create Server Certificate
Step 4: Verify the Chain
π Section 4: TLS Session Encryption and Ciphers¶
π§ Concepts to Learn¶
- Cipher suite structure:
- Key exchange: ECDHE
- Authentication: RSA
- Encryption: AES_128_GCM
-
Integrity: SHA256
-
Perfect Forward Secrecy (PFS): achieved with ephemeral key exchange (ECDHE).
- AEAD ciphers (e.g., AES-GCM, ChaCha20-Poly1305) combine encryption + integrity.
π§ͺ Lab 3 β Explore Cipher Suites¶
- List supported ciphers:
- Test a specific cipher with a site:
- Observe if the connection succeeds or fails (server may reject weak ciphers).
π Self-Check¶
- Why is ECDHE preferred?
- What happens if you disable forward secrecy?
- What does AEAD mean?
π Section 5: TLS 1.2 vs TLS 1.3¶
| Feature | TLS 1.2 | TLS 1.3 |
|---|---|---|
| Handshake RTTs | 2 | 1 |
| Cipher Suites | Mix of key exchange + cipher | AEAD-only (simplified) |
| Forward Secrecy | Optional | Always required |
| Session Resumption | Tickets or session IDs | Tickets (encrypted) |
| Key Exchange | RSA, DHE, ECDHE | ECDHE only |
π§ͺ Lab 4 β Compare Handshakes in Wireshark¶
- Capture two sessions:
-
Open both captures:
-
In TLS 1.2: youβll see ServerHello, Certificate, ServerHelloDone, etc.
- In TLS 1.3: fewer messages, starts encryption sooner.
π Section 6: Troubleshooting TLS¶
π§ Common Issues¶
| Problem | Likely Cause | Example Diagnostic |
|---|---|---|
| SSL certificate expired | Certificate validity | openssl x509 -enddate -in cert.pem -noout |
| hostname mismatch | SAN not matching domain | openssl s_client -connect host:443 -servername wrongname |
| unknown CA | Missing intermediate | Add intermediate to chain |
| handshake failure | Cipher mismatch or protocol version | Try forcing with -tls1_2 or -cipher |
π§ͺ Lab 5 β Simulate a Certificate Error¶
-
Modify your
/etc/hoststo point wrongname.local to your HTTPS test server. -
Use:
β Observe the hostname mismatch error. -
Fix by regenerating the certificate with the correct SAN.
π Section 7: TLS Tools and Best Practices¶
opensslβ inspect, debug, generate certscurlβ test clients and serversssllabs.com/ssltest/β analyze your public HTTPS configurationtestssl.shβ local TLS testing tool- Mozillaβs SSL Configuration Generator
π§ Knowledge Check¶
- What is the difference between a Root and Intermediate CA?
- Which part of the handshake authenticates the server?
- Why is forward secrecy important?
- How many round trips does TLS 1.3 need for handshake?
- How do you verify if a certificate chain is valid?
π Stage 2 Completion Outcome
You should now be able to: β Explain the TLS handshake message by message. β Build and verify your own certificate chain. β Capture and interpret TLS sessions in Wireshark. β Troubleshoot TLS configuration and certificate problems. β Understand differences between TLS 1.2 and 1.3.