11 releases (stable)

2.0.2 Jun 28, 2022
2.0.1 Jan 7, 2021
1.1.3 Dec 13, 2020
1.1.1 Oct 25, 2020
0.2.0 Feb 10, 2016

#4 in Authentication

Download history 10590/week @ 2022-04-27 10776/week @ 2022-05-04 9526/week @ 2022-05-11 9495/week @ 2022-05-18 9333/week @ 2022-05-25 9229/week @ 2022-06-01 9143/week @ 2022-06-08 8103/week @ 2022-06-15 9810/week @ 2022-06-22 8934/week @ 2022-06-29 11173/week @ 2022-07-06 13987/week @ 2022-07-13 15211/week @ 2022-07-20 13408/week @ 2022-07-27 13193/week @ 2022-08-03 7996/week @ 2022-08-10

52,522 downloads per month
Used in 42 crates (5 directly)

MIT/Apache

69KB
1.5K SLoC

Secret Service

Secret Service Rust library.

Interfaces with the Linux Secret Service API through dbus.

This library is feature complete, has stabilized its API, and has removed extraneous dependencies, so I've made it 1.0.

Documentation

Get Docs!

Basic Usage

Does not require dbus library! Pure Rust! (On ubuntu, this was libdbus-1-dev when building, and libdbus-1-3 when running)

In Cargo.toml:

[dependencies]
secret-service = "2.0.0"

If you have cargo-extras installed, can replace above step with the command at the prompt in your project directory:

$ cargo add secret-service

In source code (below example is for --bin, not --lib)

extern crate secret_service;
use secret_service::SecretService;
use secret_service::EncryptionType;
use std::error::Error;

fn main() -> Result<(), Box<Error>> {

    // initialize secret service (dbus connection and encryption session)
    let ss = SecretService::new(EncryptionType::Dh)?;

    // get default collection
    let collection = ss.get_default_collection()?;

    //create new item
    collection.create_item(
        "test_label", // label
        vec![("test", "test_value")], // properties
        b"test_secret", //secret
        false, // replace item with same attributes
        "text/plain" // secret content type
    )?;

    // search items by properties
    let search_items = ss.search_items(
        vec![("test", "test_value")]
    )?;

    let item = search_items.get(0)?;

    // retrieve secret from item
    let secret = item.get_secret()?;
    assert_eq!(secret, b"test_secret");

    // delete item (deletes the dbus object, not the struct instance)
    item.delete()?;
}

Functionality

  • SecretService: initialize dbus, create plain/encrypted session.
  • Collections: create, delete, search.
  • Items: create, delete, search, get/set secret.

Changelog

0.1.0

  • dependency on gmp is removed.
  • rust-crypto replaced by RustCrypto.
  • as a result of above, error on encrypting and decrypting blank input is fixed.

...

0.4.0

  • gmp is now optional dependency.
  • gmp upgraded to 0.3 to fix "private-in-public" warnings which will be hard errors soon.

1.0.0

  • switch from rust-crypto to RustCrypto
  • remove gmp dep for powm
  • update rand and num

1.1.0

  • Fix, get_collection_* returns Error::NoResult when doesn't exist
  • udpate hkdf to 0.8

1.1.1

  • update deps

1.1.2

  • update rand

1.1.3

  • update deps

2.0.0

  • dbus replaced by zbus, PURE RUST!
  • update to 2018 edition
  • BREAKING: SsError renamed to Error
  • BREAKING: variants added to Error
  • BREAKING: attributes are now HashMap<&str, &str> or HashMap<String, String> instead of Vec<(&str, &str)>. Not sure why I decided this way back when, but it could cause unexpected behavior for user: when the Vec was transformed to HashMap internally, tuples could be lost if the keys were the same.
  • BREAKING: Collection::new and Item::new are now private (although I don't think it was possible to use them anyways)

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~7MB
~140K SLoC