Skip to content
Documentation Background

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


Take a client proving its identity to a server, with an attacker on the path. Each version fixes the previous version’s flaw.

VersionMechanismFlaw
1The client sends “I am client A”Anyone can send that message
2The server checks the source IP addressSpoofing. An attacker can write any source address into a packet. Ingress filtering at provider edges blocks some of it, but not everywhere
3The client sends a password in cleartextSniffing. Anyone on the path reads it. This is Telnet and FTP
4The client sends the password encrypted with a shared keyReplay. The attacker records the encrypted password and sends the same bytes later. The server cannot tell it is a copy
5Challenge-response with a nonceNeeds a shared key between every pair of parties
6Challenge-response with public keys and certificatesNeeds a trusted way to know whose public key it is

A nonce is a number used once. It is the central idea of the whole page.

  1. The client says who it is.
  2. The server replies with a fresh random number R.
  3. The client returns R transformed with a secret that only the two of them know (encrypted, or better, an HMAC of it).
  4. 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 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:

TechniqueHow it worksWhere you see it
Challenge nonceThe verifier supplies a fresh value to be included in the responseLogin protocols, Kerberos, 5G authentication
Sequence numbersEach message carries a counter. The receiver rejects duplicates and gapsTLS records, IPsec ESP (with a sliding window), TCP, Wi-Fi
TimestampsMessages carry a time. The receiver rejects those outside a short windowSigned webhooks and API requests, Kerberos tickets, TOTP
One-time tokensA token is valid once and the server remembers itCSRF tokens, password reset links, authorization codes

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.

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.


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:

Terminal window
# Verify a webhook: HMAC over "timestamp.body" with the shared secret
ts="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 repeats

Proving who someone is differs from deciding what they may do. The first is covered here. The second belongs to access control: see AAA.