Skip to main content

Keychain

Struct Keychain 

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

A parsed (and possibly unlocked) macOS keychain database.

Keychain owns the file bytes, the parsed table catalogue, the discovered schema, and its unlock state. Extraction methods take &self because every state mutation happens during Keychain::unlock / Keychain::try_unlock.

Implementations§

Source§

impl Keychain

Source

pub fn generic_passwords(&self) -> Result<Vec<GenericPassword>>

Return all generic-password records.

Returns Error::Locked if the keychain has not been unlocked (or partially unlocked via Keychain::try_unlock). When try_unlock was used and per-record decryption fails, metadata fields are still populated and password is None.

Source

pub fn internet_passwords(&self) -> Result<Vec<InternetPassword>>

Return all internet-password records. Semantics match Keychain::generic_passwords.

Source

pub fn private_keys(&self) -> Result<Vec<PrivateKey>>

Return all private-key records.

Under try_unlock, records whose payload fails to decrypt are still returned with metadata populated but name empty and data empty.

Source

pub fn certificates(&self) -> Result<Vec<Certificate>>

Return all X.509 certificate records. Certificates are not encrypted at rest, so they are fully populated regardless of unlock state (subject to the Locked guard).

Source

pub fn password_hash(&self) -> Result<String>

Export the keychain password hash in $keychain$*<salt_hex>*<iv_hex>*<ciphertext_hex> format (compatible with hashcat mode 23100 and John the Ripper). Does not require unlock.

Source§

impl Keychain

Source

pub fn open_default() -> Result<Self>

Open the default macOS login keychain at $HOME/Library/Keychains/login.keychain-db.

Returns Error::Io on hosts where $HOME is unset or the file is absent (every non-macOS target).

Source

pub fn open_file<P: AsRef<Path>>(path: P) -> Result<Self>

Open a keychain from a specific path.

Source

pub fn open_bytes<B: Into<Vec<u8>>>(buf: B) -> Result<Self>

Open a keychain from an in-memory buffer.

Source

pub fn builder() -> KeychainBuilder

Construct a KeychainBuilder for the case that needs a custom logger or wants to defer source selection.

Source§

impl Keychain

Source

pub fn unlock(&mut self, cred: Credential) -> Result<()>

Decrypt the keychain using cred. On failure the keychain is left locked, so extraction methods return Error::Locked.

Takes the credential by value so it is consumed (and dropped) by the unlock attempt rather than lingering at the call site.

Source

pub fn try_unlock(&mut self, cred: Option<Credential>) -> Result<()>

Attempt to decrypt, but fall back to metadata-only extraction instead of failing on a wrong credential.

  • None enables partial mode without attempting decryption.
  • Some(cred) attempts a full unlock; a wrong password / key leaves the keychain in partial mode and returns Ok(()) (check Self::unlocked to tell full from partial). Only a structural problem (e.g. a corrupt table) returns Err.
Source

pub const fn unlocked(&self) -> bool

true once a Self::unlock / Self::try_unlock has fully decrypted the database key. false in locked and partial states.

Trait Implementations§

Source§

impl Debug for Keychain

Source§

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

Formats the value using the given formatter. 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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, 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.