Model Checking a Handshake: TLS 1.3 and QUIC
Fuzzing and bounded search give evidence for the inputs they try. For a security protocol that is not enough: an attacker controls the network and will try the one interleaving of messages you didn't. Model checking explores every reachable state of a model of the protocol, including every move of a network attacker, and either proves that a property holds in all of them or returns a counterexample trace: the exact sequence of steps that breaks it. This lesson writes a small model checker for a toy challenge-response handshake, finds a replay attack in a design with a too-small nonce, and then looks at how the same ideas shaped TLS 1.3 and QUIC.
Models, properties, attackers
- A model is a state machine for every participant: honest client, server, and the attacker. The standard attacker (the Dolev-Yao model) controls the network: it sees every message, can drop, delay, reorder and replay them, and can send any message it can construct, but it cannot break the cryptography (it cannot forge a signature or a MAC for a key it doesn't have).
- A safety property says that something bad never happens: "the server never accepts the client more often than the client actually ran the protocol" (injective agreement, the property that rules out replay). A liveness property says something good eventually happens; this lesson sticks to safety.
- A model checker explores the state space, usually breadth-first so the first counterexample is a shortest one. The limit is state explosion: states multiply with every participant, session and message, so models are kept small and bounded (here: at most three sessions).
The toy handshake
The server sends a challenge nonce CHAL(n); the client answers with RESP(n), a signature over n that only client A can make. The server accepts A when it receives RESP(n) for its outstanding nonce. The design choice under test is the nonce: a 1-bit counter (some embedded protocols really did use tiny counters), or a fresh value per session. The attacker can open sessions itself (it receives the challenge, but cannot sign) and can deliver any RESP it has seen. The checker explores every interleaving. It runs in your browser:
from collections import deque
MAX_SESSIONS = 3
def successors(s, nonce):
"""All moves of the honest client A, the server and the network attacker from state s."""
client, count, outstanding, accepts, known = s
if client == "idle" and count < MAX_SESSIONS: # A says HELLO, gets CHAL(n)
n = nonce(count)
yield f"A: HELLO, server answers CHAL({n})", (("chal", n), count + 1, n, accepts, known)
if isinstance(client, tuple): # A answers with RESP(n), signed
n = client[1]
yield f"A: RESP({n}) on the network", ("done", count, outstanding, accepts, known | {n})
if count < MAX_SESSIONS: # the attacker opens a session
n = nonce(count)
yield f"attacker: HELLO, server answers CHAL({n})", (client, count + 1, n, accepts, known)
for x in sorted(known): # the attacker delivers or replays
if outstanding == x: # any RESP it has seen
yield f"network delivers RESP({x}): server ACCEPTS A", (client, count, None, accepts + 1, known)
def safe(s):
"""Injective agreement: the server accepted A at most as often as A really completed a run."""
client, _, _, accepts, _ = s
return accepts <= (1 if client == "done" else 0)
def check(nonce, label):
start = ("idle", 0, None, 0, frozenset())
parent, queue = {start: None}, deque([start])
while queue: # breadth-first: shortest trace first
s = queue.popleft()
if not safe(s):
trace = []
while parent[s]:
s, step = parent[s]
trace.append(step)
print(f"{label}: VIOLATION after exploring {len(parent)} states; counterexample:")
for i, step in enumerate(reversed(trace), 1):
print(f" {i}. {step}")
return
for step, t in successors(s, nonce):
if t not in parent:
parent[t] = (s, step)
queue.append(t)
print(f"{label}: property holds in all {len(parent)} reachable states")
check(lambda k: k % 2, "nonce from a 1-bit counter")
check(lambda k: k, "fresh nonce per session ")nonce from a 1-bit counter: VIOLATION after exploring 21 states; counterexample:
1. A: HELLO, server answers CHAL(0)
2. A: RESP(0) on the network
3. network delivers RESP(0): server ACCEPTS A
4. attacker: HELLO, server answers CHAL(1)
5. attacker: HELLO, server answers CHAL(0)
6. network delivers RESP(0): server ACCEPTS A
fresh nonce per session : property holds in all 22 reachable states
The counterexample is six steps long and reads like an attack description: A runs once; the attacker opens two sessions so the 1-bit counter wraps back to 0; then it replays A's old response, and the server accepts "A" a second time although A ran only once. With a fresh nonce per session the property holds in all 22 reachable states: within the bound, no interleaving of attacker moves produces a replay.
From toy to real: tools and what they prove
| Tool | Style | Typical use |
|---|---|---|
| TLA+ with TLC | explicit-state model checking of system designs | distributed protocols, consensus, cloud services |
| SPIN, NuSMV | classic model checkers | concurrent protocols, hardware |
| Tamarin, ProVerif | symbolic cryptographic protocol verifiers with a built-in Dolev-Yao attacker | key exchanges, authentication protocols; can prove properties for an unbounded number of sessions |
| CryptoVerif, EasyCrypt, F* | computational proofs, verified implementations | cryptographic reductions, verified code |
The toy has the classic limitation of explicit-state checking: it proves the property only up to three sessions. Symbolic tools such as Tamarin and ProVerif reason about unboundedly many sessions, at the price of a more abstract model and, sometimes, non-termination.
TLS 1.3
TLS 1.3 (first published as RFC 8446 in 2018; the current specification is RFC 9846, July 2026, which obsoletes RFC 8446 with clarifications and no new protocol version) is the first version of TLS designed alongside formal analysis: during its standardisation, academic teams modelled drafts in Tamarin and ProVerif and built verified implementations, and some of that work found problems in drafts that were fixed before publication. Design choices that a model makes easy to justify: the whole handshake transcript is hashed into the keys and signed or MACed (so any reordering or tampering breaks the Finished check), obsolete key exchanges were removed (no static RSA), and the version downgrade protection lives in the server's random value. The handshake itself is in Applied Cryptography, and the tls13 visualisation steps through it. One deliberate trade-off is 0-RTT early data: it is sent before the handshake proves freshness, so it can be replayed, exactly the property the toy model violated. The RFC therefore warns that 0-RTT data has no replay protection across connections and requires any application protocol that uses it to say how, which in practice means only requests that are safe to repeat.
QUIC
QUIC (RFC 9000, with TLS 1.3 integrated by RFC 9001, both 2021) runs over UDP, so it must solve problems that TCP's handshake used to solve. Two of them are state-machine and protocol-security problems:
- Address validation and amplification. Over UDP an attacker can spoof the source address. Until the client's address is validated, a QUIC server may send at most three times the bytes it received, and it can force validation with a Retry token, so it cannot be used to amplify traffic towards a victim.
- Connection IDs and migration. Connections survive address changes (a phone moving from Wi-Fi to mobile data). The server must validate the new path before sending much data to it, or the migration becomes another amplification vector.
QUIC inherits TLS 1.3's 0-RTT replay caveat, and implementations are fuzzed and tested for state-machine bugs like any other protocol stack.
How protocol design flaws are detected and fixed
Detection: write the model and the properties, run the checker, and treat every counterexample as a potential attack; then check that the implementation follows the model (by testing, by state-machine learning, or by generating code from the verified model). Fixes are design changes: fresh nonces and timestamps for freshness, binding every message to the transcript, explicit state machines, limits such as anti-amplification factors. The model, with its properties, becomes a regression artefact like a test suite: every protocol change is checked again.
Pitfalls
- Proving the wrong property. "The server eventually accepts" says nothing about replay; state injective agreement, secrecy and downgrade resistance explicitly.
- A model that is not the code. A verified design implemented with a skipped check is still broken; test the implementation against the model.
- Bounds that are too small. The 1-bit counter needed three sessions to fail; a model with two sessions would have "proved" it safe.
- Assuming 0-RTT is like 1-RTT. Early data is replayable by design.
Practice
1. Change MAX_SESSIONS to 2. What does the checker report for the 1-bit counter, and why is that dangerous?
It reports that the property holds: with two sessions the counter never repeats a nonce. The bound hid the bug, which is why bounds must be argued (here: the counter wraps after 2, so you need at least 3 sessions).
2. Model a 2-bit counter (k % 4). What minimum bound reveals the replay?
Five sessions: the nonce 0 repeats at session index 4, so A's session plus four attacker sessions. The counterexample grows accordingly. With any finite counter the replay exists; only the bound needed to see it changes.
3. Why does TLS 1.3 restrict 0-RTT to replay-safe requests rather than fixing replay?
0-RTT data is sent before the server has contributed any fresh value, so the protocol cannot prove freshness for it; servers can limit replays (single-use tickets, time windows) but not exclude them in general. Applications must decide which requests can tolerate being received twice.
Test yourself
What does a model checker return when a property fails?
- A crash dump
- A counterexample trace: the exact sequence of steps that breaks the property
- A CVSS score
- Nothing
What can the Dolev-Yao attacker NOT do?
- Replay messages
- Forge a signature without the key
- Drop messages
- Reorder messages
Why did the 1-bit counter design fail injective agreement?
- The signature was weak
- The nonce repeated, so an old signed response was valid again in a new session
- The client ran twice
- The server crashed
What does QUIC's anti-amplification limit do?
- Limits connection count
- Lets a server send at most three times the bytes it received until the client's address is validated
- Encrypts headers
- Disables 0-RTT