End-to-end encryption
Each user has a 64-byte identity secret. The client makes it and seals it; the server stores envelopes.
use auth_chad::core::Draws;
use auth_chad::e2ee::{self, Context, Method, OpenError, RecoveryKey};
fn seal(draws: &mut impl Draws, prf: &[u8; 32], user: &str, kid: &str, secret: &[u8; 64]) -> Result<e2ee::Envelope, OpenError> {
let context = Context { namespace: "myapp/v1", user, kid, method: Method::Prf };
e2ee::seal(draws, prf, context, secret)
}
fn new_recovery_key(draws: &mut impl Draws) -> RecoveryKey {
RecoveryKey::generate(draws) // show `display()` once, seal with Method::Recovery
}
Turn the mode on in the routes with Auth::with_e2ee(). The routes then keep each envelope in the commit that adds,
uses or removes its passkey:
| Call | Adds | Gets |
|---|---|---|
POST /auth/signup/finish | "e2ee": { "envelope", "recovery_envelope", "recovery_verifier" } | |
POST /auth/login/finish | "envelope": the one of the passkey that was used | |
POST /auth/passkeys | "envelope" for the new passkey | |
DELETE /auth/passkeys/{id} | its envelope goes too | |
PUT /auth/recovery/key | "envelope" sealed with the new recovery key | |
POST /auth/recovery/key/start | "envelope" sealed with the recovery key; a decoy for an unknown name | |
POST /auth/recovery/key/finish | "envelope" for the new passkey |
- A call without its envelope, or with one when the mode is off, gets
400 invalid_request. - A passkey from before the mode logs in without an envelope. Give it one by adding a new passkey with the secret.
recovery_verifieris the public key ofrecovery::recovery_signer(namespace, key): the recovery key both opens its envelope and proves the recovery.- Recovery by email, by a link or by an owner gets
403: it cannot restore the key. - Ask for the PRF extension with
e2ee::prf_input(namespace)increateandget. Never send its output. - Without the routes: add
e2ee::attach_passkeyandattach_recoveryto the signup’s commit, ande2ee::detachto a passkey’s removal. - New identity:
replace_identity, with your own rewrapped data in the same commit. - Losing every passkey, the recovery key and every device loses the data. Say so in the page.