pub struct DbKeyStore { /* private fields */ }Implementations§
Source§impl DbKeyStore
impl DbKeyStore
Sourcepub fn rekey(
source_path: impl AsRef<Path>,
source_opts: Option<&EncryptionOpts>,
dest_path: impl AsRef<Path>,
dest_opts: Option<&EncryptionOpts>,
) -> Result<RekeyOutcome, RekeyError>
pub fn rekey( source_path: impl AsRef<Path>, source_opts: Option<&EncryptionOpts>, dest_path: impl AsRef<Path>, dest_opts: Option<&EncryptionOpts>, ) -> Result<RekeyOutcome, RekeyError>
Rekey a keystore out-of-place with exact verification: read every credential from the source database, write it into a freshly and safely created destination database, then compare all source and destination records (service, user, uuid, comment, and secret bytes) before checkpointing and durably closing the destination.
This is used to add, remove, or rotate the on-disk encryption key (a
DEK rotation): pass dest_opts = Some(..) to add or rotate encryption,
or dest_opts = None to write an unencrypted copy. source_opts must
supply the cipher/key the source was written with (or None if the
source is unencrypted).
Success means “exactly verified”: if this function returns Ok, the
destination contains a byte-exact copy of every source credential, has
been checkpointed and file-synced, and no WAL/SHM sidecar files remain.
On every failure the source is left unchanged, partially written
destination files are removed, and a typed RekeyError is returned
without panicking.
The destination is created O_CREAT | O_EXCL | O_NOFOLLOW with mode
0600 relative to a pinned parent directory descriptor; an existing
file or symlink at dest_path (or at its WAL/SHM sidecar names) is
rejected and never deleted. Missing destination parent directories are
created. Whether the source enforced (service, user) uniqueness is
detected from the source schema and mirrored on the destination so
ambiguous keystores round-trip unchanged. Callers needing full
directory-descriptor control should use rekey_at (Linux); see the
module docs for the substitution-resistance caveat shared by
both entry points.
§Choosing an entry point
Security-sensitive callers on Linux should prefer rekey_at. This
path-based entry point creates missing destination parent directories
with create_dir_all (umask-default modes) and follows
symlinks when canonicalizing the source path; rekey_at does neither,
pins both directories by descriptor for the whole operation, and
returns the created destination’s file descriptor so custody extends
through the caller’s subsequent swap.
See the module docs for caller obligations: quiescence,
panic = "unwind", and the internal executor/retry behavior.
No secret material is logged or included in any returned value.
Sourcepub fn verify(
source_path: impl AsRef<Path>,
source_opts: Option<&EncryptionOpts>,
dest_path: impl AsRef<Path>,
dest_opts: Option<&EncryptionOpts>,
) -> Result<u64, RekeyError>
pub fn verify( source_path: impl AsRef<Path>, source_opts: Option<&EncryptionOpts>, dest_path: impl AsRef<Path>, dest_opts: Option<&EncryptionOpts>, ) -> Result<u64, RekeyError>
Verify that two existing keystores contain exactly equal credential records, without copying or modifying anything.
This is the same streaming comparison DbKeyStore::rekey runs
before returning success: every record’s service, user, uuid,
comment, and secret bytes compared byte- and storage-class-exact,
one record at a time (bounded memory), with no digest of secrets
computed and no secret material in any error. Returns the number of
records verified; any divergence (differing field, missing record,
extra record) is a RekeyError::VerificationMismatch.
Use it to re-verify a rekeyed candidate before or after an
atomic-rename swap, or to compare any two keystores. Unlike rekey,
both databases must already exist (RekeyError::SourceNotFound /
RekeyError::DestinationNotFound otherwise); nothing is created and
no schema is initialized or written on either side. A destination that
cannot be decrypted with dest_opts returns
RekeyError::WrongDestinationKey; a destination that is not a
keystore database returns RekeyError::CorruptDestination.
One side effect is unavoidable at the database layer: opening a database creates an empty WAL sidecar if none exists. Sidecar files that this verification’s own open created, and that are still empty, are removed before returning; pre-existing sidecar files are never touched (a source with uncheckpointed WAL frames verifies fine and keeps its WAL).
As with rekey, quiescence is the caller’s job; see the module docs.
Source§impl DbKeyStore
impl DbKeyStore
pub fn new(config: DbKeyStoreConfig) -> Result<Arc<DbKeyStore>>
pub fn new_with_modifiers( modifiers: &HashMap<&str, &str>, ) -> Result<Arc<DbKeyStore>>
Sourcepub fn is_encrypted(&self) -> bool
pub fn is_encrypted(&self) -> bool
Returns true if the db file is encrypted
Trait Implementations§
Source§impl Clone for DbKeyStore
impl Clone for DbKeyStore
Source§fn clone(&self) -> DbKeyStore
fn clone(&self) -> DbKeyStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl CredentialStoreApi for DbKeyStore
impl CredentialStoreApi for DbKeyStore
Source§fn build(
&self,
service: &str,
user: &str,
modifiers: Option<&HashMap<&str, &str>>,
) -> Result<Entry>
fn build( &self, service: &str, user: &str, modifiers: Option<&HashMap<&str, &str>>, ) -> Result<Entry>
Create a credential entry for service and user.
Service and user must be non-empty, and within the length limits. (<=1024 chars)
Supported modifiers: uuid, comment.
Source§fn search(&self, spec: &HashMap<&str, &str>) -> Result<Vec<Entry>>
fn search(&self, spec: &HashMap<&str, &str>) -> Result<Vec<Entry>>
Source§fn persistence(&self) -> CredentialPersistence
fn persistence(&self) -> CredentialPersistence
Auto Trait Implementations§
impl !RefUnwindSafe for DbKeyStore
impl !UnwindSafe for DbKeyStore
impl Freeze for DbKeyStore
impl Send for DbKeyStore
impl Sync for DbKeyStore
impl Unpin for DbKeyStore
impl UnsafeUnpin for DbKeyStore
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
Source§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
Source§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
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 more