• Proposal for a Zero-Knowledge End-to-End Authentication & Identification Method
Recently, countries all over the world (and France in particular) have been hit by a huge wave of cyberattacks aimed at monetizing the user data of the targeted apps and services.
But believe it or not, the cryptographic tools to mitigate this kind of data leak already exist. They won't stop an attacker who takes over the application, but they can prevent them from dumping the whole user base in action.
That is the point of this proposal, which I wrote a year ago and am making public today :
Zero-knowledge end-to-end Authentication & Identification (ZKAI) is a protocol designed to strengthen user confidentiality by reducing the amount of time any information is available in plaintext. The information stays encrypted until its final use by the website's backend logic, and it is never stored in plaintext in the database or in the user browser.
The name is more of a goal than a cryptographic property. ZKAI isn't zero-knowledge in the strict sense (a zero-knowledge proof reveals nothing beyond its own validity, while here the server sees the data at each login), and it isn't end-to-end either, since the server reads the data. What it means is that between two sessions, the server doesn't keep the data itself, only what it needs to check it.
The goal is to build an authentication method that :
-
Never stores plaintext data in the database
-
Never stores plaintext data in the browser
-
Dont hurt the user experience too much (the cost is discussed at the end)
We'll go through each step of the auth flow to see how this works. The general idea is that the database only keeps keyed hashes of the user data, the user provides the actual data at login, encrypted so that only the authentication service can read it, and the server hands it back inside a signed session token where each field is encrypted with a session key only the server holds.
Registration process
To register, the user generates their own key pair (a Private Key and its Public Key) and the dataset the application needs (name, email, etc...). A dedicated application usually handles both, and it's this application, not the browser, that keeps the Private Key and the dataset afterwards.
The application also knows the server identity key (SERVER_ID_PUBLIC_KEY), the public part of a long-term signing key that only the authentication service holds. It either shipped with the application or fetched once at registration and kept alongside the user ID. It lets the application check that the encryption keys it receives really come from the authentication service and not from something in between.
The application asks for a challenge. The server generates a random nonce and an ephemeral key pair, keeps the nonce and the ephemeral Private Key in a cache for a few seconds and for a single use, and returns the nonce and the ephemeral Public Key, signed with SERVER_ID_KEY.
The application checks this signature, encrypts the dataset with the ephemeral Public Key with the nonce and the application domain as associated data, and sends it along with its own Public Key. Reverse proxies, WAF and other application in front of the authentication service only see ciphertext.
The key is ephemeral because request bodies end up in logs that are kept for months. With a single static server key, an attacker who gets it one day (the exact scenario this protocol is built for) could decrypt every request ever logged and rebuild the whole user base. With one key per challenge, deleted as soon as it used, a request captured today can't be decrypted tomorrow. The server signs it so that a compromised proxy can't slip in its own.
sequenceDiagram
title Registration (1/2) : challenge
actor USER
participant SERVER
participant CACHE
USER->>USER: generate user_private_key, user_public_key
USER->>SERVER: registration request
SERVER->>SERVER: nonce = RANDOM()<br/>eph_private_key, eph_public_key = KEYGEN()
SERVER->>CACHE: challenges[nonce] = (eph_private_key, expires_at)
SERVER->>USER: nonce, eph_public_key,<br/>server_sig = SIGN(SERVER_ID_KEY, nonce || eph_public_key)
USER->>USER: VERIFY(SERVER_ID_PUBLIC_KEY, server_sig, nonce || eph_public_key)<br/>enc_dataset = HPKE_SEAL(eph_public_key, dataset, aad = nonce || domain)
The server takes the ephemeral Private Key out of the cache, decrypts the dataset, checks that it contains exactly the fields the application expects and assigns an ID to the account. It then stores the Public Key and, for each field, HMAC(K_hmac, user_id || field_name || value).
K_hmac is a server secret that doesn't live in the database. A plain hash wouldn't be enough, because names, emails or phone numbers have little entropy because with a plain hash, anyone holding a dump could find the values by trying candidates. With the key, the dump alone doesn't allow testing anything. Putting the user ID and the field name in the input also means two users with the same name don't get the same value, so accounts can't be linked across the database.
The server returns the ID, which the user application stores with the dataset.
sequenceDiagram
title Registration (2/2) : account creation
actor USER
participant SERVER
participant DB
participant CACHE
USER->>SERVER: nonce, enc_dataset, user_public_key
SERVER->>CACHE: pop challenges[nonce]
CACHE-->>SERVER: (eph_private_key, expires_at)
SERVER->>SERVER: check nonce is not expired<br/>dataset = HPKE_OPEN(eph_private_key, enc_dataset, aad = nonce || domain)<br/>check dataset fields == expected fields<br/>user_id = NEW_ID()
SERVER->>DB: store {<br/>user_public_key,<br/>for each field: HMAC(K_hmac, user_id || field || value)<br/>}
SERVER->>USER: user_id
USER->>USER: keep user_id, dataset, user_private_key
Authentication process
The user sends their ID. The server answers with a challenge, like at registration (a random nonce and an ephemeral Public Key signed with SERVER_ID_KEY). It keeps the nonce, the ID and the ephemeral Private Key in the cache, for a few seconds and for a single use.
The user application checks the server signature, encrypts the dataset with the ephemeral Public Key, then signs, with its Private Key, the nonce, the application domain and the encrypted dataset. The application has to read the domain from the connection itself (the site the user is actually talking to), not from what the server sends (otherwise a phishing site could relay the real server nonce and get a valid signature). The phishing site doesn't get the dataset either, since it encrypted for a key only the real server holds, and it can't sign a key of its own with SERVER_ID_KEY.
The server takes the nonce out of the cache, checks that it was issued for this ID and is still valid, verifies the signature with the registered Public Key, then decrypts the dataset with the ephemeral Private Key. Since the signature covers the ciphertext, the server knows the dataset really comes from the key holder. It then checks that the dataset contains exactly the registered fields (a missing field must be rejected, otherwise an empty dataset would pass every check), and that the HMAC of each value matches the one in the database.
sequenceDiagram
title Authentication (1/2) : proof of identity
actor USER
participant SERVER
participant DB
participant CACHE
USER->>SERVER: user_id
SERVER->>SERVER: nonce = RANDOM()<br/>eph_private_key, eph_public_key = KEYGEN()
SERVER->>CACHE: challenges[nonce] = (user_id, eph_private_key, expires_at)
SERVER->>USER: nonce, eph_public_key,<br/>server_sig = SIGN(SERVER_ID_KEY, nonce || eph_public_key)
USER->>USER: VERIFY(SERVER_ID_PUBLIC_KEY, server_sig, nonce || eph_public_key)<br/>enc_dataset = HPKE_SEAL(eph_public_key, dataset, aad = nonce || domain)<br/>sig = SIGN(user_private_key, nonce || domain || enc_dataset)
USER->>SERVER: user_id, nonce, enc_dataset, sig
SERVER->>CACHE: pop challenges[nonce]
CACHE-->>SERVER: (user_id, eph_private_key, expires_at)
SERVER->>DB: get user_public_key and HMACs of user_id
DB-->>SERVER: user_public_key, HMACs
SERVER->>SERVER: check nonce was issued for user_id and is not expired<br/>VERIFY(user_public_key, sig, nonce || domain || enc_dataset)<br/>dataset = HPKE_OPEN(eph_private_key, enc_dataset, aad = nonce || domain)<br/>check dataset fields == registered fields<br/>for each field: HMAC(K_hmac, user_id || field || value) == stored HMAC
If everything is valid, the server opens a session by creating a random session ID and a random symmetric key, stored in the cache under that session ID until the session expires.
The server encrypts each field with this key using an AES-GCM, with the session ID and the field name as associated data, so an encrypted field can't be moved to another field or another session.
Finally, the server puts the user ID, the session ID, an expiry date and the encrypted fields into a JWT, signs it and sends it back as a cookie (HttpOnly, Secure, SameSite).
sequenceDiagram
title Authentication (2/2) : session opening
actor USER
participant SERVER
participant CACHE
SERVER->>SERVER: session_id = RANDOM()<br/>session_key = RANDOM_KEY()
SERVER->>CACHE: sessions[session_id] = session_key (TTL = session lifetime)
SERVER->>SERVER: for each field:<br/>enc_field = AEAD_ENCRYPT(session_key, value, aad = session_id || field)
SERVER->>SERVER: token = SIGN({ user_id, session_id, exp, enc_fields }, SERVER_SIGNING_KEY)
SERVER->>USER: token (HttpOnly, Secure, SameSite cookie)
Authentication process (variant with a signed timestamp)
The nonce isn't the only way to prove the user holds the Private Key. In this variant, the user application signs the current timestamp along with the user ID, the application domain (read from the connection, as above) and the encrypted dataset, and sends everything in a single request.
Since there no challenge, there no ephemeral key either. The application encrypts the dataset with a key the server publishes and rotates often (every hour, for example), signed with SERVER_ID_KEY, and the server deletes each private key at the end of its period. A leak of the current key exposes the requests logged during that period, not all of them.
Both methods work, but they don't offer the same things. The nonce costs two round trips and the server has to keep each nonce until it is used. In return, freshness is entirely controlled by the server, a captured answer can't be replayed, the user clock doesn't matter, and each login gets its own encryption key.
The signed timestamp fits in one request and the server doesn't have to remember anything to authenticate the user. On the other hand, it relies on the user clock being roughly right, and a request captured inside the time window can be replayed, unless the server keeps track of the signatures it has already seen during that window (which brings back a bit of state). Either way the session keys live in the server cache, so the protocol as a whole isn't stateless.
Identification process
When the application needs user data, it verifies the token signature and expiry, fetches the session key from the cache using the session ID, and decrypts only the fields it needs. If the key is no longer in the cache (expired session or logout), the token is useless even though its signature is still valid.
Only the application backend should be able to trigger this decryption.
sequenceDiagram
title Identification process
actor USER
participant SERVER
participant CACHE
USER->>SERVER: token
SERVER->>SERVER: VERIFY(token, SERVER_SIGNING_KEY)<br/>check exp
SERVER->>CACHE: get sessions[token.session_id]
CACHE-->>SERVER: session_key, or nothing if expired or logged out
SERVER->>SERVER: for each needed field:<br/>value = AEAD_DECRYPT(session_key, enc_field, aad = session_id || field)
SERVER-->>SERVER: use the values in backend logic
USER->>SERVER: logout
SERVER->>CACHE: delete sessions[token.session_id]
What it protects against, and what it doesn't
A database dump only gives Public Keys and HMACs, which are useless without K_hmac. Logged login requests only give ciphertexts whose keys no longer exist. A stolen token alone gives nothing as long as the decryption endpoint is protected, and neither does the cache alone (it holds keys, not data).
An attacker who fully compromises the backend can still read data, since it arrives in plaintext at each login and gets decrypted on each request. What they can't do is dump the whole user base at once. They only get the users who log in or use the application while they're inside, so they have to keep their access for a long time to collect data as users come and go, which gives the defenders time to notice them.
Conclusion
ZKAI doesn't make an application immune to compromise. What it changes is the cost of the attack because instead of a single dump of the whole base, the attacker has to stay inside and collect users one by one as they log in. For applications that only need user data during a session, that worth the extra UX cost.