sew_e2ee/lib.rs
1//! `sew-e2ee`: the reference client library for end-to-end encrypted Sew calls.
2//!
3//! Every Sew call is end-to-end encrypted. The keys exist only on participant devices (and, when
4//! a call is recorded, on the recorder the members admit), agreed with MLS (RFC 9420, openmls
5//! 0.9.0), and are fed into the LiveKit SDKs' own frame encryption. This crate is that
6//! protocol, written once:
7//!
8//! - **Identity** ([`identity`], [`trust`], [`store`]): the P-256 device key interface
9//! ([`DeviceSigner`]), device certificates from the server's call CA, the call credential
10//! (`SewCallIdentity` v2, scope `call:<channel_id>`), the DS-signed `LeafBinding` table, TOFU
11//! pins and the CRL.
12//! - **Joining** ([`E2eeClient`], [`PendingKp`], [`PreparedKp`]): key packages made offline,
13//! uploaded for a single-use `key_package_ref`, claimed by the voice join or the key join.
14//! - **The call** ([`CallSession`]): a sans-IO state machine — per-sender keys from the MLS
15//! exporter by leaf index, slots `(slot_base + e) mod 64`, the two-phase install → ready →
16//! activate switch, retirement after 10 s, recovery without user action, the recorder release.
17//! - **Bridges** ([`bridge`]): the [`KeyEvent`] contract every SDK bridge applies, the
18//! [`KeyRing`] shadow and [`Caps`] (and, with the `testing` feature only, the simulated SDK
19//! `bridge::virtual_sdk::VirtualSdk`).
20//! - **The recorder side** ([`recorder`]): [`ReleaseOpener`], [`RecorderKeyPair`],
21//! [`identity::verify_table`] for the recorder; [`open_recording_chunk`] for the admin download.
22//!
23//! Sans-IO: no IO, no clock, no threads, no `Send` requirement. The host wires a session to its
24//! own HTTP client and gateway connection: `sew-call-client` is a complete native host, and
25//! Sew's WASM build for browsers (`@sew/e2ee`) wraps it too (not published here).
26//!
27//! The `testing` feature (an in-process delivery service model, a simulated SDK, test
28//! certificates and crafted protocol messages) is for tests only: it is unstable and not covered
29//! by semver, it exposes secret key material, and it builds malicious protocol messages. Never
30//! enable it outside tests.
31
32pub mod bridge;
33pub mod chunk;
34pub mod code;
35pub mod config;
36pub mod error;
37pub mod identity;
38pub mod ids;
39pub mod keypackage;
40pub mod keys;
41pub mod provider;
42pub mod recorder;
43pub mod roster;
44pub mod session;
45pub mod store;
46pub mod trust;
47pub mod wire;
48
49#[cfg(feature = "testing")]
50pub mod fuzzing;
51#[cfg(feature = "testing")]
52pub mod testing;
53
54pub use bridge::{Caps, KeyEvent, KeyRing, KeySink, SinkAck, SinkError};
55pub use chunk::{ChunkLayout, open_recording_chunk, recording_chunk_layout};
56pub use code::SecurityCode;
57pub use config::{E2eeConfig, Params};
58pub use error::{
59 BindingError, ChunkError, DecodeError, IdentityError, JoinError, ReleaseError, SessionError,
60 TrustError,
61};
62pub use identity::{
63 DeviceIdentity, DeviceSigner, EnrollAction, EnrollDraft, Enrollment, SignRequest,
64 SoftwareSigner, VerifiedTable, verify_table,
65};
66pub use ids::{
67 Consent, Epoch, FenceId, Id, JoinId, LkIdentity, MemberId, Millis, RecordingId, RequestId,
68 RoomName, SignId, Slot, UnixMs,
69};
70pub use keypackage::{E2eeClient, PendingKp, PreparedKp};
71pub use keys::{FrameIkm, ikm_context, lk_frame_key};
72pub use recorder::{RecorderKeyPair, ReleaseOpener, Released};
73pub use roster::{MediaLabel, RosterEntry, RosterState};
74pub use session::{
75 CallSession, Counters, E2eeStatus, EngineMisbehaviour, Input, LeftReason, Output, SessionState,
76 Transition, UndecryptReason, UnknownCallBuffer,
77};
78pub use store::{DeviceStore, MemoryDeviceStore, Pins, StoredDevice};
79pub use trust::TrustAnchors;
80pub use wire::{ApiFailure, KeyReply, KeyRequest};
81
82/// The call scope: always `call:<channel_id>` (voice channels and DM calls alike).
83/// It has one constructor and no empty form.
84pub type Scope = sew_proto::e2ee::CallScope;
85
86/// For Sew's own bridges in other crates (not published) only: builds [`Caps`]. Not part of the
87/// supported API (`caps_only_from_bridge`). An app that calls it declares a capability its SDK
88/// may lack, which the server then refuses only by observation.
89#[doc(hidden)]
90pub mod __bridge {
91 use crate::bridge::Caps;
92
93 /// The caps a bridge reports for its SDK.
94 pub fn caps(
95 sender_key_index: bool,
96 sdk: &str,
97 sdk_version: &str,
98 browser: Option<&str>,
99 ) -> Caps {
100 Caps::from_bridge(sender_key_index, sdk, sdk_version, browser)
101 }
102}
103
104/// README.md's examples, compiled and run as doc tests.
105#[cfg(doctest)]
106#[doc = include_str!("../README.md")]
107struct ReadmeExamples;