pub struct KeyPair {
pub master_secret: Vec<u8>,
pub certificate: Vec<u8>,
}Expand description
RedDB cryptographic keypair for vault seal and token signing.
At bootstrap time a random master_secret is generated. The
certificate is derived from the master secret via HMAC-SHA256 and
given to the admin. The admin uses the certificate to unseal the
vault on subsequent restarts.
master_secret = random_bytes(32) // lives in vault
certificate = HMAC-SHA256(master_secret, "reddb-certificate-v1") // admin keeps this
vault_key = Argon2id(certificate, "reddb-vault-seal") // AES-256-GCM key for vaultFields§
§master_secret: Vec<u8>32-byte master secret (stays encrypted inside the vault).
certificate: Vec<u8>32-byte certificate derived from master secret (admin keeps this).
Implementations§
Source§impl KeyPair
impl KeyPair
Sourcepub fn from_master_secret(master_secret: Vec<u8>) -> Self
pub fn from_master_secret(master_secret: Vec<u8>) -> Self
Re-derive a keypair from a known master secret (used when restoring state from the decrypted vault).
Sourcepub fn vault_key_from_certificate(certificate: &[u8]) -> SecureKey
pub fn vault_key_from_certificate(certificate: &[u8]) -> SecureKey
Derive the vault encryption key from a certificate.
This is the only operation that does NOT require the master secret – anyone holding the certificate can unseal the vault.
Sourcepub fn sign(&self, data: &[u8]) -> Vec<u8> ⓘ
pub fn sign(&self, data: &[u8]) -> Vec<u8> ⓘ
Sign arbitrary data with the master secret (HMAC-SHA256).
Sourcepub fn verify(&self, data: &[u8], signature: &[u8]) -> bool
pub fn verify(&self, data: &[u8], signature: &[u8]) -> bool
Verify a signature produced by sign.
Sourcepub fn certificate_hex(&self) -> String
pub fn certificate_hex(&self) -> String
Certificate as a hex string (what the admin saves).
Auto Trait Implementations§
impl Freeze for KeyPair
impl RefUnwindSafe for KeyPair
impl Send for KeyPair
impl Sync for KeyPair
impl Unpin for KeyPair
impl UnsafeUnpin for KeyPair
impl UnwindSafe for KeyPair
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request