Skip to main content

capsule_core/crypto/
revoke.rs

1//! The master-key proof that authorizes a global sign-out (SSoT:
2//! [Authentication — Explicit Revocation](https://docs/design/authentication/#explicit-revocation)).
3//!
4//! # The asymmetry this exists to create
5//!
6//! Revoking one session is authenticated by any live session token. Revoking *every* session is
7//! not, and deliberately: an attacker holding a stolen token could otherwise invoke "log out of
8//! all devices" and lock the legitimate user out of every device they own. Gating the global
9//! revoke on a signature by the account's identity key means a stolen token can revoke only
10//! itself — it cannot escalate a theft into a denial of service.
11//!
12//! # Why the message is built here rather than at each end
13//!
14//! The server verifies this proof and a client produces it, so it is a two-ended format — and a
15//! two-ended format defined twice is one edit away from a signature that stops verifying. This
16//! is the same reasoning that moved the custody receipt into [`crate::crypto::receipts`], with
17//! one difference that makes it cheaper: the signed message is a byte string rather than a CBOR
18//! map, so there is no key-ordering trap. The trap that remains is the domain separator, and
19//! that is exactly what a shared constant removes.
20//!
21//! # Domain separation is not decoration
22//!
23//! The IK signs several things — the device directory core, and this. A bare challenge is a
24//! short opaque string, and a signature over one is a signature over anything else of that
25//! shape. Prefixing every revoke-all proof with [`REVOKE_ALL_DOMAIN`] means a signature
26//! produced for one purpose cannot be replayed as the other, whatever a future ceremony chooses
27//! to sign.
28
29use crate::crypto::keys::{HybridSignature, HybridVerifyingKey};
30
31/// The domain separator every revoke-all proof is signed under.
32///
33/// Versioned, so a future change to what the proof covers is a *different* message rather than
34/// a silently compatible one.
35pub const REVOKE_ALL_DOMAIN: &[u8] = b"capsule/revoke-all/v1";
36
37/// The exact bytes a revoke-all proof signs, for `challenge`.
38///
39/// The challenge is a single-use, server-issued, high-entropy token; it carries the freshness
40/// and the account binding, and this function carries the domain.
41#[must_use]
42pub fn revoke_all_signing_bytes(challenge: &str) -> Vec<u8> {
43    let mut bytes = Vec::with_capacity(REVOKE_ALL_DOMAIN.len() + challenge.len());
44    bytes.extend_from_slice(REVOKE_ALL_DOMAIN);
45    bytes.extend_from_slice(challenge.as_bytes());
46    bytes
47}
48
49/// Whether `signature` is a valid revoke-all proof for `challenge` under `identity_key`.
50///
51/// `identity_key` is the account's **anchor** — the identity public key its published device
52/// directory verifies under — not a key the request supplied. A proof checked against
53/// a caller-supplied key proves only that the caller can sign, which is not a fact about the
54/// account.
55#[must_use]
56pub fn verify_revoke_all_proof(
57    identity_key: &HybridVerifyingKey,
58    challenge: &str,
59    signature: &HybridSignature,
60) -> bool {
61    identity_key.verify(&revoke_all_signing_bytes(challenge), signature)
62}
63
64#[cfg(test)]
65mod tests;