Skip to main content

LocalKms

Struct LocalKms 

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

File-based KEK store for dev / on-prem deployments.

§Layout

<dir>/
  alpha.kek         # 32 raw bytes — KEK for key_id "alpha"
  beta.kek          # 32 raw bytes — KEK for key_id "beta"

Files are loaded eagerly at LocalKms::open time; subsequent adds/removals require a restart. KEK files MUST be exactly 32 bytes (other formats — hex / base64 — are intentionally not accepted here, unlike crate::sse::SseKey, because operators generating KEKs for KMS use should produce raw randomness from /dev/urandom rather than human-edited files).

§Wrap algorithm

LocalKms wraps DEKs with AES-256-GCM using the KEK as the cipher key. The wrapped form is nonce(12) || ciphertext(32) || tag(16) = 60 bytes for a 32-byte DEK. The nonce is fresh per wrap, drawn from OsRng; the AAD is the UTF-8 key_id so a wrap under one id can’t be replayed under another.

Implementations§

Source§

impl LocalKms

Source

pub fn open(dir: PathBuf) -> Result<Self, KmsError>

Open a KEK directory. Reads every *.kek file; each must be exactly 32 raw bytes. The basename (sans .kek) becomes the key_id used in KmsBackend::generate_dek / WrappedDek.

An empty directory is a valid (but useless) state — callers that haven’t loaded any KEKs will still see all generate_dek calls return KmsError::KeyNotFound.

Source

pub fn from_keks(dir: PathBuf, keks: HashMap<String, [u8; 32]>) -> Self

Construct a LocalKms directly from in-memory KEKs. Useful for tests and for callers that load KEKs out of band (e.g. from a sealed config blob). Production deployments should prefer LocalKms::open.

Source

pub fn key_ids(&self) -> Vec<String>

Sorted list of key ids present in this backend. Used by the CLI --list-kms-keys flag (orchestrator wires that) and by readiness probes that want to assert a specific key is loaded.

Trait Implementations§

Source§

impl Debug for LocalKms

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl KmsBackend for LocalKms

Source§

fn generate_dek<'life0, 'life1, 'async_trait>( &'life0 self, key_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(Vec<u8>, WrappedDek), KmsError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Generate a fresh 32-byte DEK and return both the plaintext (used immediately for AES-GCM encryption of the object body) and the wrapped form (persisted in the S4E4 frame). Read more
Source§

fn decrypt_dek<'life0, 'life1, 'async_trait>( &'life0 self, wrapped: &'life1 WrappedDek, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, KmsError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Unwrap a stored DEK ciphertext back to plaintext for the decrypt path. The 32-byte plaintext must be zeroed by the caller after use (callers in this crate hold it in a stack [u8; 32] for the duration of one GET).

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromExt for T

Source§

fn from_<T>(t: T) -> Self
where Self: From<T>,

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> IntoExt for T

Source§

fn into_<T>(self) -> T
where Self: Into<T>,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = 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> TryFromExt for T

Source§

fn try_from_<T>(t: T) -> Result<Self, Self::Error>
where Self: TryFrom<T>,

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> TryIntoExt for T

Source§

fn try_into_<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Source§

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

Source§

fn vzip(self) -> V

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