Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Get Passwords From Mac's Keychain Access App In Rust

Code

//! ```cargo
//! [dependencies]
//! security-framework = "2.9.2"
//! ```


use security_framework::passwords::get_generic_password;

fn main() {
    dbg!(password("example-password", "alan"));
}

fn password(pass: &str, name: &str) -> Option<String> {
    match get_generic_password(pass, name) {
        Ok(response) => Some(String::from_utf8(response).unwrap()),
        Err(_) => None,
    }
}

I don't like using plain-text config or .env files for storing passwords. Beyond the possibility of accidentally sending them to github I also stream which opens up an entirely new way to dox credentials.

Here's what I'm using in Rust to pull credentials out of my mac's built-in Keychain Access app:

References

  • Bindings to the Apple's Security.framework. Allows use of TLS and Keychain from Rust.