OO7
This library allows to store secrets using two different backends:
-
dbusimplements theorg.freedesktop.Secretspecification. -
filestores secrets in an encrypted file compatible with libsecret. For sandboxed applications use case, the file can be encrypted using a secret retrieved from theorg.freedesktop.portal.Secretsportal.
Sandboxed applications should prefer using the file backend as it doesn't expose the application secrets to other applications that can talk to the org.freedesktop.Secrets service.
The library provides types that automatically pick a backend based on whether the application is sandboxed or not. Applications developers should use those APIs.
Goals
- Async only API
- Ease to use
- Integration with the Secret portal if sandboxed
- Provide API to migrate from host secrets to sandboxed ones
Examples
Basic usage
use HashMap;
async
If your application makes heavy usage of the keyring like a password manager. You could store an instance of the Keyring in a OnceCell / OnceLock / Lazy
use OnceLock;
use HashMap;
static KEYRING: = new;
Migrating your secrets to the file backend
The library also comes with API to migrate your secrets from the host Secret Service to the sandboxed file backend. Note that the items are removed from the host keyring if they are migrated successfully.
use HashMap;
// SOME_RUNTIME could be a tokio/async-std/glib runtime
SOME_RUNTIME.block_on;
Optional features
| Feature | Description | Default |
|---|---|---|
tracing |
Record various debug information using the tracing library |
No |
async-std |
Use async-std APIs for IO/filesystem operations |
No |
tokio |
Use tokio APIs for IO/Filesystem operations |
Yes |
native_crypto |
Use Rust Crypto crates for cryptographic primitives | Yes |
openssl_crypto |
Use openssl crate for cryptographic primitives |
No |
unstable |
Unlock internal APIs | No |
How does it compare to other libraries?
-
libsecret is a C library that provides the same two backends. The current main pain point with it is that it does assume things for you so it will either use the host or the sandbox file-based keyring which makes migrating your secrets to inside the sandbox a probably impossible task. There are also issues like https://gitlab.gnome.org/GNOME/libsecret/-/issues/58 that makes it not usable inside the Flatpak sandbox.
-
libsecret-rs provides Rust bindings to libsecret.
-
secret-service-rs uses zbus internally as well but does provide a sync only API, hasn't seen an update in a while, doesn't integrate with Secret portal if sandboxed.
License
The project is released under the MIT license.
Credits
- secret-service-rs for the encrypted Secret Service implementation.