Authentication protocols and replay
Encryption hides data. Integrity shows it was not altered. Neither shows that the other party is who they claim to be, or that a message is fresh and not a recording of an old one. End-point authentication is the proof that the party you are talking to is the real one and is live right now. This page walks through how authentication protocols are designed by fixing one flaw at a time, then shows where those fixes live in protocols you use. Cryptography fundamentals has the building blocks (MACs, signatures, key exchange).
Building it up
Section titled “Building it up”Take a client proving its identity to a server, with an attacker on the path. Each version fixes the previous version’s flaw.
| Version | Mechanism | Flaw |
|---|---|---|
| 1 | The client sends “I am client A” | Anyone can send that message |
| 2 | The server checks the source IP address | Spoofing. An attacker can write any source address into a packet. Ingress filtering at provider edges blocks some of it, but not everywhere |
| 3 | The client sends a password in cleartext | Sniffing. Anyone on the path reads it. This is Telnet and FTP |
| 4 | The client sends the password encrypted with a shared key | Replay. The attacker records the encrypted password and sends the same bytes later. The server cannot tell it is a copy |
| 5 | Challenge-response with a nonce | Needs a shared key between every pair of parties |
| 6 | Challenge-response with public keys and certificates | Needs a trusted way to know whose public key it is |
The nonce
Section titled “The nonce”A nonce is a number used once. It is the central idea of the whole page.
- The client says who it is.
- The server replies with a fresh random number
R. - The client returns
Rtransformed with a secret that only the two of them know (encrypted, or better, an HMAC of it). - The server checks the answer.
A recording of an old session is useless, because the next session’s R is different. The answer proves two things: that the client holds the secret, and that it is live, since it responded to a value generated moments ago.
With public keys, the client signs R with its private key and the server verifies with the client’s public key. That removes the shared secret, but the server has to be sure the public key really belongs to that client. Without that, a man-in-the-middle attack works: the attacker hands the server its own key, claiming it is the client’s, and then authenticates as the client. The fix is a certificate from a trusted authority that binds the key to an identity. That is the purpose of PKI, and it is why TLS clients validate the server’s certificate chain.
Replay beyond login
Section titled “Replay beyond login”Replay is not limited to passwords. Any captured message can be sent again: a payment request, a “delete” command, a signed API call. Integrity alone does not stop it, because the replayed copy is a perfectly valid, unmodified message.
Defenses all add freshness:
| Technique | How it works | Where you see it |
|---|---|---|
| Challenge nonce | The verifier supplies a fresh value to be included in the response | Login protocols, Kerberos, 5G authentication |
| Sequence numbers | Each message carries a counter. The receiver rejects duplicates and gaps | TLS records, IPsec ESP (with a sliding window), TCP, Wi-Fi |
| Timestamps | Messages carry a time. The receiver rejects those outside a short window | Signed webhooks and API requests, Kerberos tickets, TOTP |
| One-time tokens | A token is valid once and the server remembers it | CSRF tokens, password reset links, authorization codes |
Sequence numbers must be protected
Section titled “Sequence numbers must be protected”A sequence number in the clear can be forged. TLS and IPsec fold it into the integrity check (the MAC or the AEAD tag), so a replayed, reordered, or altered message fails verification. In TLS the sequence number is not even sent: both ends keep a counter and use it in each record’s tag, so a dropped or reordered record causes failure rather than silent misbehavior.
Truncation
Section titled “Truncation”If integrity is checked only per message, an attacker can cut off the end of a stream: drop the last records, or forge a TCP FIN to close a connection early. The receiver sees valid messages and a clean end, and has no idea part is missing. A secure protocol therefore has an authenticated close message. TLS sends close_notify, protected like other records. If a connection ends without it, the application should treat the data as possibly incomplete. This matters for downloads and API responses that are read until EOF.
Where this shows up
Section titled “Where this shows up”TLS. The server proves identity with a certificate and a signature over the handshake. The handshake carries random values from both sides (nonces) so session keys are fresh, and records are protected with sequence-aware AEAD. TLS 1.3’s 0-RTT early data is the one exception. It is sent before the handshake completes, so a replay is possible, and servers should accept it only for idempotent requests. See TLS handshake.
IPsec. ESP has a sequence number and a replay window at the receiver. See IPsec and VPNs.
Kerberos. Tickets and authenticators carry timestamps. This is why a client whose clock is more than a few minutes off cannot log in, a common source of mysterious authentication failures.
Wi-Fi and cellular. Wi-Fi’s four-way handshake uses nonces from both sides. 5G authentication uses a fresh random challenge and a sequence number in the network’s token. See Wireless security.
Signed APIs and webhooks. A good design signs the timestamp together with the body, and rejects requests older than a few minutes:
# Verify a webhook: HMAC over "timestamp.body" with the shared secretts="1730768400"body='{"event":"deploy.done"}'sig=$(printf '%s.%s' "$ts" "$body" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" -hex | awk '{print $NF}')echo "$sig"# Server: recompute, compare in constant time, then require |now - ts| < 300 s# and optionally remember the signature or an event ID to reject exact repeatsAuthentication is not authorization
Section titled “Authentication is not authorization”Proving who someone is differs from deciding what they may do. The first is covered here. The second belongs to access control: see AAA.