Skip to main content

FfiWrappedMasterKeyStore

Struct FfiWrappedMasterKeyStore 

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

The application’s master key held wrapped by a key-encryption key inside the platform key store.

The store generates the key-encryption key (a non-exportable CNG key on Windows, an Android Keystore key on Android), keeps it where nothing can read it out, and wraps the master key with it. FfiWrappedMasterKeyStore::store hands back the wrapped bytes for the host side to persist, and FfiWrappedMasterKeyStore::load takes them back and returns the master key.

§Nothing here wraps, unwraps or hands out a key-encryption key

Wrapping is the internal design of this form, and the library keeps it that way: no operation of this object encrypts, decrypts or returns the key-encryption key, and none is added here. The host side stores a master key and receives bytes to keep; what those bytes mean is the platform’s business.

§The bytes belong to one store entry

Bytes produced by another store entry, or damaged in storage, fail rather than unwrap into a key that merely differs. That is what makes them safe to persist next to the vault file they belong to. The wrapped form is not secret the way the master key is: whoever copies the bytes still needs the platform key, which is not in them.

§Current state

Same as FfiDirectMasterKeyStore: Windows and Android have a backend, and every other platform reports unsupported_platform from every operation.

Implementations§

Source§

impl FfiWrappedMasterKeyStore

Source

pub fn open() -> Result<Arc<Self>, FfiError>

Opens the wrapped master key store of the current platform.

§Errors

A FfiError::Core error with the kind hardware_unavailable when this machine has no provider that can create a key-encryption key; see FfiDirectMasterKeyStore::open for why an unimplemented platform opens anyway.

Source

pub fn backend(&self) -> String

The platform key store that holds the key-encryption key, as a stable short name: "tpm", "android-keystore", "software", "secure-enclave" or "unavailable".

Reported truthfully, like FfiDirectMasterKeyStore::backend; this is the value the host side tells the user about before it relies on the wrapped form.

Source

pub fn is_hardware_backed(&self) -> bool

Whether the key-encryption key cannot leave hardware.

Consistent with FfiWrappedMasterKeyStore::backend by construction: true exactly when that backend is a hardware one.

Source

pub fn store(&self, label: String, key: Vec<u8>) -> Result<Vec<u8>, FfiError>

Wraps the 32-byte key under label and returns the bytes the host side has to persist.

The bytes are opaque: their length and contents belong to the platform, and only the same store entry can turn them back into the master key. Persist them next to the vault file they belong to; losing them means the master key has to be recovered another way, and deleting the label’s entry makes them permanently unusable.

Wrapping under a label that already exists reuses the key-encryption key that is already there, so bytes persisted earlier keep unwrapping.

§Errors

FfiError::InputTooLong for an oversized label; the core’s master_key_wrong_length when key is not 32 bytes; otherwise a key store failure, reported as unsupported_platform or device_error — a platform that cannot create a key-encryption key included.

Source

pub fn load(&self, label: String, wrapped: Vec<u8>) -> Result<Vec<u8>, FfiError>

Unwraps wrapped — the bytes FfiWrappedMasterKeyStore::store handed back for label — and returns the master key.

§Errors

invalid_wrapped_key when the bytes do not unwrap: a damaged blob, or one produced by another store entry or another device. The method never returns bytes it could not authenticate, so a failure here means “these bytes are unusable”, not “here is a different key”. A label that holds no key-encryption key at all is device_error today.

Source

pub fn delete(&self, label: String) -> Result<(), FfiError>

Deletes the key-encryption key stored under label.

§Warning

Every blob wrapped with that key becomes permanently unusable, which is how a device forgets a master key. The host side has to ask the user first, and it has to be prepared for the persisted bytes to be worthless afterwards.

§Errors

FfiError::InputTooLong for an oversized label, and otherwise the same key store failures as FfiWrappedMasterKeyStore::load.

Trait Implementations§

Source§

impl<UT> LiftRef<UT> for FfiWrappedMasterKeyStore

Source§

impl<UT> LowerError<UT> for FfiWrappedMasterKeyStore

Source§

fn lower_error(obj: Self) -> RustBuffer

Lower this value for scaffolding function return Read more
Source§

impl<UT> LowerReturn<UT> for FfiWrappedMasterKeyStore

Source§

type ReturnType = <Arc<FfiWrappedMasterKeyStore> as LowerReturn<UniFfiTag>>::ReturnType

The type that should be returned by scaffolding functions for this type. Read more
Source§

fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>

Lower the return value from an scaffolding call Read more
Source§

fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>

Lower the return value for failed argument lifts Read more
Source§

impl<UT> TypeId<UT> for FfiWrappedMasterKeyStore

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
Source§

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

Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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

Create a new handle for an Arc value Read more
Source§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

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

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

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

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

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

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
Source§

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
Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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