Skip to content

πŸ” Stage 2: Deep Dive into TLS

🎯 Learning Objectives

By the end of this stage, you will be able to:

  1. Explain what TLS provides (confidentiality, integrity, authentication).
  2. Describe the TLS handshake process in detail.
  3. Understand certificates, certificate chains, and PKI.
  4. Use openssl, curl, and Wireshark to inspect and troubleshoot TLS sessions.
  5. 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:

1
2
3
GET / HTTP/1.1
Host: example.com
User-Agent: curl/8.0

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)

1
2
3
4
5
6
7
8
9
ClientHello           β†’  (supported ciphers, TLS version)
← ServerHello         (selected cipher)
← Certificate         (server certificate)
← ServerHelloDone
ClientKeyExchange    β†’
ChangeCipherSpec     β†’
Finished             β†’
← ChangeCipherSpec
← Finished

🧩 TLS 1.3 Handshake (Simplified)

TLS 1.3 reduces round-trips for speed and stronger security:

1
2
3
4
5
6
7
ClientHello β†’ (includes key share)
← ServerHello (includes key share)
← EncryptedExtensions
← Certificate
← CertificateVerify
← Finished
Finished β†’

πŸ§ͺ Lab 1 – Observe a TLS Handshake

  1. Run:

    openssl s_client -connect example.com:443
    

  2. Observe:

  3. The chosen TLS version.
  4. The cipher suite.
  5. The certificate chain.
  6. The Verify return code.

  7. Try forcing specific versions:

openssl s_client -connect example.com:443 -tls1_2
openssl s_client -connect example.com:443 -tls1_3
  1. 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

openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 3650 -out rootCA.crt -subj "/CN=RootCA"

Step 2: Create Intermediate CA

1
2
3
openssl genrsa -out intermediate.key 2048
openssl req -new -key intermediate.key -out intermediate.csr -subj "/CN=IntermediateCA"
openssl x509 -req -in intermediate.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out intermediate.crt -days 1825 -sha256 -extfile <(echo "basicConstraints=CA:TRUE,pathlen:0")

Step 3: Create Server Certificate

1
2
3
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr -subj "/CN=server.local"
openssl x509 -req -in server.csr -CA intermediate.crt -CAkey intermediate.key -CAcreateserial -out server.crt -days 825 -sha256 -extfile <(echo "subjectAltName=DNS:server.local")

Step 4: Verify the Chain

openssl verify -CAfile <(cat intermediate.crt rootCA.crt) server.crt

πŸ“˜ Section 4: TLS Session Encryption and Ciphers

🧠 Concepts to Learn

  • Cipher suite structure:
    TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
    
  • 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

  1. List supported ciphers:
    openssl ciphers -v | column -t
    
  2. Test a specific cipher with a site:
    openssl s_client -connect example.com:443 -cipher 'AES128-SHA'
    
  3. 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

  1. Capture two sessions:
    curl -v --tlsv1.2 https://example.com
    curl -v --tlsv1.3 https://example.com
    
  2. Open both captures:

  3. In TLS 1.2: you’ll see ServerHello, Certificate, ServerHelloDone, etc.

  4. 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

  1. Modify your /etc/hosts to point wrongname.local to your HTTPS test server.

  2. Use:

    curl -v https://wrongname.local --cacert rootCA.crt
    
    β†’ Observe the hostname mismatch error.

  3. Fix by regenerating the certificate with the correct SAN.

πŸ“˜ Section 7: TLS Tools and Best Practices

  • openssl β†’ inspect, debug, generate certs
  • curl β†’ test clients and servers
  • ssllabs.com/ssltest/ β†’ analyze your public HTTPS configuration
  • testssl.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.