Skip to main content

capsule_core/crypto/authority/
mod.rs

1//! The album authorization seam — exactly what [`verify_asset`] needs to learn from MLS
2//! about an album, behind a trait so the real OpenMLS group state can drop in later.
3//!
4//! [`verify_asset`] needs only three facts about an album, and the *authority* on all
5//! three is the album's admin-signed MLS commit chain — never the server:
6//! 1. the monotonic **epoch ceiling** (the highest `amk_version` the chain attests),
7//! 2. the **write-tier public key** for a given epoch (only writers at that epoch held the
8//!    private half), and
9//! 3. whether the **AMK content key** for an epoch is *locally held* (to tell a key still
10//!    in flight apart from a forged epoch).
11//!
12//! Two backends implement this seam:
13//! - [`ReferenceAuthority`] — the deterministic, admin-signature-backed offline/test authority.
14//!   It preserves every property `verify_asset` tests for with no MLS dependency, and remains
15//!   available on every build (including the wasm sealing build).
16//! - [`OpenMlsAuthority`] — the design-target backend over a live OpenMLS group pinned to the
17//!   X-Wing ciphersuite `0x004D`. Host-only, behind the `mls` feature (implied by
18//!   `native`, excluded from wasm since its libcrux provider does not target wasm32).
19//!
20//! Because `verify_asset` consumes only `&dyn AlbumAuthority`, the two are interchangeable; the
21//! [`Authority`] enum lets a caller store either without naming a concrete backend.
22//!
23//! [`verify_asset`]: crate::crypto::verify_asset::verify_asset
24//! SSoT for the rules this seam encodes: [Keys — Write Authorization].
25//!
26//! [Keys — Write Authorization]: https://docs/design/cryptography/keys/#write-authorization
27
28mod reference;
29
30#[cfg(feature = "mls")]
31mod openmls_authority;
32
33#[cfg(feature = "mls")]
34pub use openmls_authority::{
35    AddOutcome, AlbumHistoryBundle, AlbumKeyDistribution, AlbumStateSummary, AmkHistoryEntry,
36    BlockOutcome, CommitHash, DEFAULT_UPGRADE_DEADLINE, HistoryPolicy, LostCommitTracker,
37    MlsDeviceIdentity, OpenMlsAuthority, OpenMlsAuthorityError, PINNED_CIPHERSUITE_ID,
38    ReconcileOutcome, RekeyOutcome, RekeyReason, RemoveOutcome, ServerChainView,
39    SignedUpgradeIntent, TombstoneOutcome, UpgradeIntent, UpgradeLineage, UpgradeProposal,
40    WriteTierDistribution,
41};
42pub use reference::{LedgerEntry, ReferenceAuthority, SignedEpochLedger};
43use uuid::Uuid;
44
45use crate::crypto::keys::{AmkVersion, HybridVerifyingKey};
46
47/// One album's MLS-attested authorization state, as needed by `verify_asset`.
48///
49/// An instance represents a single album. All methods reflect the album's admin-signed
50/// commit chain; an implementation must never let server-asserted state substitute for it.
51pub trait AlbumAuthority {
52    /// The album this authority speaks for.
53    fn album_id(&self) -> Uuid;
54
55    /// The monotonic epoch ceiling: the highest `amk_version` the admin chain attests. A
56    /// manifest claiming a higher epoch is terminal-rejected (the server cannot fabricate
57    /// a future epoch a client will honor).
58    fn epoch_ceiling(&self) -> AmkVersion;
59
60    /// The write-tier public key for `epoch`, or `None` if the chain attests no such epoch.
61    /// `verify_asset` checks the manifest's `write_sig` against this key.
62    fn write_tier_pubkey(&self, epoch: AmkVersion) -> Option<HybridVerifyingKey>;
63
64    /// Whether the AMK *content key* for `epoch` is held locally. When an epoch is within
65    /// the attested range but its AMK has not yet arrived over MLS, the asset is *pending*,
66    /// not forged.
67    fn has_amk(&self, epoch: AmkVersion) -> bool;
68
69    /// Whether the admin-signed attestation chain itself verifies. If this is false, the
70    /// authority is untrusted and `verify_asset` must terminal-reject everything — an
71    /// implementation must never trust an unsigned or forged ledger.
72    fn admin_chain_verifies(&self) -> bool;
73}
74
75/// A concrete album authority behind the [`AlbumAuthority`] seam, so a holder (e.g.
76/// `Workspace`) can store either backend without naming a
77/// concrete type. `Reference` is the offline/test default present on every build; `OpenMls` is
78/// the live MLS backend, available only under the `mls` feature (host-only). The enum itself
79/// implements [`AlbumAuthority`], so `&Authority` coerces to `&dyn AlbumAuthority` at every
80/// `verify_asset` call site.
81pub enum Authority {
82    /// The offline, admin-signed epoch-ledger authority.
83    Reference(Box<ReferenceAuthority>),
84    /// The live OpenMLS-group authority (X-Wing suite `0x004D`).
85    #[cfg(feature = "mls")]
86    OpenMls(Box<OpenMlsAuthority>),
87}
88// Both variants are boxed: each backend owns substantial per-album state (the reference ledger,
89// or a whole MLS group + libcrux provider), so indirection keeps `Authority` a single word and
90// avoids a large size difference between variants.
91
92impl Authority {
93    /// The reference backend, if this is the offline/reference authority; `None` for the live
94    /// MLS backend. Used to capture the admin-signed epoch ledger for persistence.
95    pub fn as_reference(&self) -> Option<&ReferenceAuthority> {
96        match self {
97            Authority::Reference(a) => Some(a.as_ref()),
98            #[cfg(feature = "mls")]
99            Authority::OpenMls(_) => None,
100        }
101    }
102
103    /// The reference backend, mutably, if this is the offline/reference authority. Returns
104    /// `None` for the live MLS backend — whose epoch advances are self-update commits, not
105    /// ledger attestations, and so ride the MLS ceremonies rather than this path.
106    pub fn as_reference_mut(&mut self) -> Option<&mut ReferenceAuthority> {
107        match self {
108            Authority::Reference(a) => Some(a.as_mut()),
109            #[cfg(feature = "mls")]
110            Authority::OpenMls(_) => None,
111        }
112    }
113}
114
115impl From<ReferenceAuthority> for Authority {
116    fn from(a: ReferenceAuthority) -> Self {
117        Authority::Reference(Box::new(a))
118    }
119}
120
121#[cfg(feature = "mls")]
122impl From<OpenMlsAuthority> for Authority {
123    fn from(a: OpenMlsAuthority) -> Self {
124        Authority::OpenMls(Box::new(a))
125    }
126}
127
128impl AlbumAuthority for Authority {
129    fn album_id(&self) -> Uuid {
130        match self {
131            Authority::Reference(a) => a.album_id(),
132            #[cfg(feature = "mls")]
133            Authority::OpenMls(a) => a.album_id(),
134        }
135    }
136
137    fn epoch_ceiling(&self) -> AmkVersion {
138        match self {
139            Authority::Reference(a) => a.epoch_ceiling(),
140            #[cfg(feature = "mls")]
141            Authority::OpenMls(a) => a.epoch_ceiling(),
142        }
143    }
144
145    fn write_tier_pubkey(&self, epoch: AmkVersion) -> Option<HybridVerifyingKey> {
146        match self {
147            Authority::Reference(a) => a.write_tier_pubkey(epoch),
148            #[cfg(feature = "mls")]
149            Authority::OpenMls(a) => a.write_tier_pubkey(epoch),
150        }
151    }
152
153    fn has_amk(&self, epoch: AmkVersion) -> bool {
154        match self {
155            Authority::Reference(a) => a.has_amk(epoch),
156            #[cfg(feature = "mls")]
157            Authority::OpenMls(a) => a.has_amk(epoch),
158        }
159    }
160
161    fn admin_chain_verifies(&self) -> bool {
162        match self {
163            Authority::Reference(a) => a.admin_chain_verifies(),
164            #[cfg(feature = "mls")]
165            Authority::OpenMls(a) => a.admin_chain_verifies(),
166        }
167    }
168}