Skip to main content

RecoveryClient

Struct RecoveryClient 

Source
pub struct RecoveryClient { /* private fields */ }
Expand description

The networked recovery client: escrow cache/refresh, stale-cache-aware local verification, and the guided re-wrap.

It holds one AuthenticatedClient, so every call rides the generated operation paths and the SDK’s bearer/refresh machinery, and this module states no route of its own. The client is behind an Arc only so RecoveryClient stays Clone — the cadence hands one client to several prompts. There is deliberately no repoint/session-swap accessor: AuthenticatedClient’s own take &mut self and are unreachable through the Arc, and an escrow client that changed origin mid-cadence would be a way to pull one account’s escrow into another’s cache. Build a new one instead.

Implementations§

Source§

impl RecoveryClient

Source

pub fn new(session: Session, api_base_url: &str) -> Result<Self, RecoveryError>

Build a recovery client against the API root — the origin the generated operation paths hang off (e.g. https://api.example.com), which is the same base AuthenticatedClient and crate::sync::SyncConsumer take.

§Errors

RecoveryError::InvalidBaseUrl when api_base_url is not a URL operation paths can hang off. Fallible where the old hand-written format! was not, because the generated client parses the base once at construction rather than per call.

Source

pub async fn fetch_escrow(&self) -> Result<EscrowCache, RecoveryError>

Fetch the current escrow blob from the server (GET /v1/auth/escrow) into a fresh EscrowCache. 404 maps to RecoveryError::NotEnrolled.

Source

pub async fn store_escrow( &self, blob: &WrappedSecret, ) -> Result<EscrowStored, RecoveryError>

Store or replace the caller’s escrow blob (PUT /v1/auth/escrow). Single active escrow: the server overwrites any prior blob in the same transaction.

The canonical CBOR goes on the wire verbatim. The answer comes back as EscrowStored: stored_at for the stale-cache rule, replaced to tell a first enrollment from a rotation.

§Errors

The refusals store_escrow_error maps, and RecoveryError::InvalidResponse when the server’s stored_at is not an RFC 3339 instant.

Source

pub async fn store_sealed_identity( &self, sealed: &[u8], ) -> Result<SealedIdentityStored, RecoveryError>

Store or replace the caller’s sealed identity (PUT /v1/auth/escrow/identity): the user identity key sealed under the master key, as Workspace::sealed_identity returns it. The other half of what a recovered device needs beside the escrow — the identity is random rather than master-derived, and the server pins it on first directory publish, so a recovered device must carry this one rather than mint its own.

Opaque on the wire and stored independently of the escrow: a guided_rewrap replaces the escrow and leaves this alone, because re-wrapping the master key under a new recovery secret does not change the master key the identity is sealed under.

§Errors

The same refusals store_escrow maps, under this operation’s statuses, and RecoveryError::InvalidResponse for an unreadable stored_at.

Source

pub async fn fetch_sealed_identity(&self) -> Result<Vec<u8>, RecoveryError>

Fetch the caller’s sealed identity (GET /v1/auth/escrow/identity), verbatim — the bytes Workspace::create_from_master opens under the recovered master key.

§Errors

RecoveryError::IdentityNotStored on the coded 404; otherwise the refusals fetch_escrow maps.

Source

pub async fn store_album_keys( &self, album_id: Uuid, sealed: &[u8], ) -> Result<AlbumKeysStored, RecoveryError>

Store or replace one album’s key escrow (PUT /v1/auth/escrow/albums/{album_id}, #741): the album’s whole key state sealed under the master key, as Workspace::album_key_escrow returns it. One slot per album; storing it never touches another album’s, the escrow or the sealed identity.

§Errors

RecoveryError::Malformed for a blob the server refuses (empty, past the album keys’ ceiling, or an album id that is not canonical), the credential and store refusals store_escrow maps, and RecoveryError::InvalidResponse for an unreadable stored_at.

Source

pub async fn list_album_keys( &self, ) -> Result<Vec<EscrowedAlbumKeys>, RecoveryError>

Every album key escrow the account holds (GET /v1/auth/escrow/albums), each blob verbatim, in album order. Empty for an account that has escrowed no album.

§Errors

The credential and store refusals fetch_escrow maps, and RecoveryError::InvalidResponse when an entry’s album id, blob or stored_at cannot be read.

Source

pub async fn verify( &self, cache: &mut EscrowCache, passphrase: &[u8], device_master: &[u8; 32], latest_stored_at: Option<Timestamp>, ) -> Result<VerifyOutcome, RecoveryError>

Local recovery-secret verification with the stale-cache rule (SSoT § Local Verification): run the offline derived-tag compare against the cached blob; if it does not verify, refresh the blob from the server once and retry before returning a failure — so a rotation on another device cannot manufacture a false failure here.

latest_stored_at is the newest escrow stored_at the caller has seen — an EscrowStored from any device, however it reached this one. When the cache is older than it, the cache is known stale: it is refreshed before the compare and stamped with latest_stored_at, and the compare against the fresh blob is the answer, with no second fetch on a failure. None, or a cache at least that new, keeps the refresh-on-failure rule above.

Purely local crypto (capsule_core::backup::verify_recovery_secret); the only network I/O is the single conditional refresh. Never blocks anything.

Source

pub async fn guided_rewrap( &self, device_master: &[u8; 32], tier: DeviceTier, shamir_enrolled: bool, ) -> Result<GuidedRewrap, RecoveryError>

Run the guided re-wrap (SSoT § On Repeated Failure): mint a fresh ≥128-bit recovery secret, re-wrap the same master key under it, replace the server escrow (single active — the old blob is deleted, so the lost secret unwraps nothing), re-issue Shamir shares when enrolled, and surface the old-artifact guidance when the store displaced an earlier escrow. Wrap rotation, not key rotation: no data re-encryption, no blob-hash changes.

After this succeeds, the caller should rearm(now, RearmTrigger::SecretRotated) its cadence when GuidedRewrap::stored says it replaced an escrow; a store that replaced nothing is a first enrollment, which arms a fresh ladder with RecoveryCadence::armed_at_setup.

Trait Implementations§

Source§

impl Clone for RecoveryClient

Source§

fn clone(&self) -> RecoveryClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self> ⓘ

Get a clone of the Arc<> using a “borrowed” handle. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more