SECURITY ENGINEERING · PART 4 · CRYPTOGRAPHY IN PRACTICE · TLS · 53 OF 229

TLS 1.3 Handshake: Security, Attacks and Hardening

The TLS 1.3 handshake is where key exchange, signatures, certificates and AES-GCM work together. This episode walks through it message by message with real OpenSSL output from a practice server (TLSv1.3, X25519, TLS_AES_256_GCM_SHA384), shows what an eavesdropper can and cannot see, what TLS 1.3 removed, the attacks on older versions, 0-RTT replay risk, mutual TLS, and a hardening checklist.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 15

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Key shares in the hellos
  • certificate and signature prove identity
  • one round trip
  • AEAD only
  • TLS 1.2+ and HSTS

Notes

Three promises

TLS makes three promises. Confidentiality: nobody on the network path can read the data. Integrity: nobody can change it without being detected. Authentication: the client knows it is talking to the real server. It promises nothing about the endpoints themselves. A site with perfect TLS can still have SQL injection, and malware on a laptop reads data before it is encrypted. TLS protects data in transit, and only that.

TLS provides
  • Confidentiality: nobody on the path can read the data
  • Integrity: nobody can change it without detection
  • Authentication: you are talking to the real server
  • it does NOT protect: the endpoints, the application, or data once it arrives

Step 1: ClientHello

Step one, the client hello. The client lists the versions and cipher suites it supports, and, new in 1.3, it includes its key exchange value immediately instead of waiting. It also sends the server name it wants, called SNI, the application protocols it speaks, and a random value. This message is not encrypted. That is why a network observer can see which hostname you are connecting to, even though they cannot see the page.

ClientHello contains
  • supported versions: TLS 1.3
  • cipher suites it accepts
  • a key share: its X25519 public value, sent at once
  • SNI: the hostname it wants (visible to the network)
  • ALPN: h2, http/1.1
  • a random value
  • sent in the clear

Step 2: ServerHello

Step two, the server hello. The server picks the version and one cipher suite, and replies with its own key exchange value. At this moment, both sides can compute the same shared secret, exactly as in the Diffie-Hellman episode, and derive handshake keys from it. From here on, everything is encrypted. In 1.3, that includes the server's certificate, which older versions sent in the clear for anyone to read.

After ServerHello
  • server chooses the version and one cipher suite
  • sends its own key share
  • both sides now compute the same shared secret (Diffie-Hellman, episode 6)
  • HKDF derives handshake keys
  • everything after this message is encrypted

Step 3: prove identity

Step three is identity. The server sends its certificate chain, then a message called certificate verify: a signature over the entire handshake so far, made with the certificate's private key. The client validates the chain and the hostname, then checks that signature. An attacker in the middle cannot produce it without the private key, and because it covers the whole transcript, they also cannot alter earlier messages, such as removing the strong ciphers.

Encrypted handshake messages
  • Certificate: the chain
  • CertificateVerify: a signature over the whole handshake so far, made with the private key of the certificate
  • Finished: a MAC over the transcript
  • client validates the chain and the name (episode 8)
  • this defeats man in the middle

Step 4: Finished

Step four. Both sides send a finished message, a check value proving they saw the same handshake. Application keys are derived, one for each direction, and data flows in records protected with AES in GCM mode or ChaCha twenty. The whole handshake takes one round trip, where TLS one point two needed two. And because the key exchange values were ephemeral and are now discarded, the session has forward secrecy.

Result
  • both send Finished; each confirms the same transcript
  • application keys are derived: one per direction
  • data flows as AES-GCM or ChaCha20-Poly1305 records
  • total: 1 round trip (TLS 1.2 needed 2)
  • ephemeral keys are discarded: forward secrecy

See it

Here is a real handshake, against a practice server on our own machine, using the certificate from the last episode. Read it top to bottom and you can name every part. Protocol: TLS 1.3. Cipher suite: AES two fifty six in GCM mode. The peer certificate and its name. The signature type: ECDSA. Verification: OK, because we supplied our practice root. And the temporary key: X two five five one nine. That one screen summarises this whole part of the course.

openssl s_client -brief
CONNECTION ESTABLISHED
Protocol version: TLSv1.3
Ciphersuite: TLS_AES_256_GCM_SHA384
Peer certificate: CN = shop.example.test
Hash used: SHA256
Signature type: ECDSA
Verification: OK
Server Temp Key: X25519, 253 bits

When verification fails

Now the same connection without telling the client about our root. Two verification errors, and then, connection established. The diagnostic tool carries on so you can inspect things, but a real client must stop at this point. This output shows something important: the connection is still encrypted with TLS 1.3, but you have no idea who is on the other end. Encryption without authentication protects nothing from an active attacker.

no CA supplied
verify error:num=20:unable to get
  local issuer certificate
verify error:num=21:unable to verify
  the first certificate
CONNECTION ESTABLISHED
Protocol version: TLSv1.3

# s_client carries on anyway; a real
# client must stop here. Encrypted
# is not the same as authenticated

What 1.3 removed

Much of the security of 1.3 comes from what it removed. Static RSA key exchange, which had no forward secrecy. CBC-mode ciphers, the source of years of padding oracle attacks. RC four, triple DES, MD five and SHA one. Compression, which leaked secrets. Renegotiation. Only five cipher suites remain, all of them authenticated encryption. And the handshake detects attempts to force a downgrade to an older version.

Gone in TLS 1.3
  • static RSA key exchange (no forward secrecy)
  • CBC-mode ciphers (padding oracle attacks)
  • RC4, 3DES, MD5, SHA-1
  • compression (CRIME)
  • renegotiation
  • only 5 cipher suites remain, all authenticated (AEAD)
  • downgrade is detected

Attacks on older TLS

You do not need every old attack in detail, but know the themes. POODLE, BEAST and Lucky thirteen exploited CBC mode and SSL version three. Heartbleed was a bug in the OpenSSL library that leaked server memory, including keys. FREAK and Logjam forced connections down to weak keys. And SSL stripping keeps the user on plain HTTP so TLS never starts. The fixes: allow only TLS one point two and above, patch the library, and enable HSTS.

The history, briefly
  • POODLE, BEAST, Lucky13: CBC and SSLv3 weaknesses
  • Heartbleed: an OpenSSL bug leaked server memory
  • FREAK, Logjam: downgrade to weak "export" keys
  • SSL stripping: user never reaches HTTPS at all fix: TLS 1.2+ only, patch the library, HSTS

0-RTT and mTLS

Two features have security consequences. Zero round trip resumption lets a returning client send data with its very first message. It is faster, but that early data can be captured and replayed by an attacker, so allow it only for requests that are safe to repeat, never for a payment. And mutual TLS: the client also presents a certificate, so both sides are authenticated. It is the standard way for services to prove identity to each other inside a zero trust network.

Know these two
  • 0-RTT: a returning client sends data with its first message; faster, but an attacker can replay it
  • allow it only for safe, repeatable requests (GET)
  • mTLS: the client also shows a certificate; both sides are authenticated
  • used between services

Harden it

The hardening checklist. Allow TLS 1.3 and one point two only. For one point two, permit only suites with ephemeral key exchange and authenticated encryption. Serve the full certificate chain and automate renewal. Send the HSTS header so browsers refuse plain HTTP. Keep the TLS library patched. Encrypt internal traffic as well, not only the public edge. Test with testssl or sslyze on systems you own, and monitor certificate expiry.

Server checklist
  • TLS 1.3 and 1.2 only 1.2: ECDHE + AEAD suites only full chain served; automated renewal
  • HSTS header (with preload for public sites)
  • keep the TLS library patched
  • internal traffic encrypted too
  • test: testssl.sh, sslyze, SSL Labs
  • monitor certificate expiry

Common mistakes

Mistakes. Certificate verification disabled in clients, which removes authentication completely. TLS one point zero or one point one still enabled for one old client. TLS that ends at the load balancer, with plain HTTP across the internal network. No HSTS. Zero round trip data accepted on requests that change state. An unpatched TLS library. And believing that a padlock means a site is secure, when it only means the connection is.

Avoid these
  • certificate checks disabled in clients
  • TLS 1.0 or 1.1 still on
  • TLS ends at the load balancer; plain HTTP behind
  • no HSTS
  • 0-RTT on state-changing requests
  • an unpatched TLS library
  • "it has a padlock, so it is secure"

Say it like this

In the interview: the client hello carries supported versions, cipher suites and a key share, usually X two five five one nine. The server hello returns its key share, and both derive handshake keys with HKDF. The server then sends, encrypted, its certificate, a signature over the transcript to prove it holds the private key, and finished. The client validates the chain and name. One round trip, then AEAD-protected data with forward secrecy.

In the interview
  • "ClientHello carries versions, ciphers and an X25519 share.
  • ServerHello returns its share;
  • both derive keys with HKDF.
  • Encrypted: the certificate, a signature over the transcript, Finished. One round trip, then AEAD records, with forward
  • secrecy."

Interview questions

Q1What happens in a TLS 1.3 handshake?

The client sends a ClientHello with supported versions, cipher suites and a key share. The server replies with its key share; both derive keys. The server then sends its certificate, a signature over the handshake transcript and a Finished message, all encrypted. After the client's Finished, application data flows.

Q2What is the difference between TLS 1.2 and TLS 1.3?

TLS 1.3 completes the handshake in one round trip instead of two, encrypts most of the handshake including the certificate, requires forward secrecy, and removes insecure options such as static RSA, CBC ciphers, RC4, SHA-1 and compression.

Q3How does TLS prevent a man-in-the-middle attack?

The server presents a certificate chaining to a trusted CA and signs the handshake transcript with the matching private key. An attacker without that key cannot produce the signature, and the client rejects certificates that do not validate or do not match the hostname.

Q4What is SNI and why can it leak information?

Server Name Indication is the hostname the client sends in the ClientHello so the server can select the right certificate. It is sent unencrypted, so network observers can see which site is requested. Encrypted Client Hello (ECH) is designed to hide it.

Q5What is the risk of TLS 1.3 0-RTT?

Early data sent with the first flight is not protected against replay: an attacker can capture and resend it. It should be limited to idempotent requests, or disabled where replay would be harmful.

Q6What is mutual TLS (mTLS)?

TLS in which the client also presents a certificate and proves possession of its private key, so both parties are authenticated. It is widely used for service-to-service authentication in service meshes and zero trust architectures.

Q7What is HSTS?

HTTP Strict Transport Security is a response header instructing browsers to use only HTTPS for a site for a set period. It prevents SSL stripping attacks and accidental plain HTTP requests; preloading extends the protection to the first visit.

Q8How do you audit a server's TLS configuration?

Use openssl s_client for a quick check and scanners such as testssl.sh, sslyze or SSL Labs for a full report on protocol versions, cipher suites, certificate chain, key exchange and known vulnerabilities, on systems you are authorised to test.