Skip to content

Commit 2765999

Browse files
Merge pull request #115 from brotskydotcom/final-tweaks-for-release
Lots of doc updates and a few API cleanups. Also: FreeBSD support. This support is experimental because we don't do CI on FreeBSD so have to rely on field reports. Fixes #36. Contributed by @ryanvella.
2 parents 9e5a1f6 + c745fd1 commit 2765999

13 files changed

+78
-36
lines changed

.github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Rust build (stable)
1+
name: build
22

33
on: [workflow_dispatch, push, pull_request]
44

CHANGELOG.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
## Version 2.0
2-
- Introduce traits for pluggable credential-store implementations.
2+
- (API change) Allow creation of entries to fail.
3+
- (API change) Introduce an ambiguous error on credential lookup.
4+
- (API change) Make the `Error` enum non-exhaustive.
5+
- (API change) Introduce traits for pluggable credential-store implementations. (This removes the old `platform` module.)
36
- Add a `mock` credential store for easy cross-platform client testing.
4-
- Use service-level search in secret-service.
7+
- Upgrade to secret-service v3.
8+
- Always use service-level search in secret-service.
59
- Allow creation of new collections in secret-service.
6-
- Add the kernel keyring as a linux credential store.
10+
- Add the kernel keyutils as a linux credential store.
11+
- Add build support for FreeBSD (thanks @ryanavella).
712

813
## Version 1.2.1
914
- password length was not validated correctly on Windows (#85)

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords = ["password", "credential", "keychain", "keyring", "cross-platform"]
66
license = "MIT OR Apache-2.0"
77
name = "keyring"
88
repository = "https://github.com/hwchen/keyring-rs.git"
9-
version = "2.0.0-rc.3"
9+
version = "2.0.0"
1010
edition = "2021"
1111
exclude = [".github/"]
1212
readme = "README.md"
@@ -34,6 +34,9 @@ security-framework = "2.6"
3434
secret-service = { version = "3", optional = true }
3535
linux-keyutils = { version = "0.2", features = ["std"] }
3636

37+
[target.'cfg(target_os = "freebsd")'.dependencies]
38+
secret-service = { version = "3", optional = true }
39+
3740
[target.'cfg(target_os = "windows")'.dependencies]
3841
byteorder = "1.2"
3942
winapi = { version = "0.3", features = ["wincred", "winerror", "errhandlingapi", "minwindef"] }

README.md

+46-23
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
## Keyring-rs
2-
[![CI](https://github.com/hwchen/keyring-rs/actions/workflows/build.yaml/badge.svg)](https://github.com/hwchen/keyring-rs/actions?query=workflow%3Abuild)
3-
[![Crates.io](https://img.shields.io/crates/v/keyring.svg?style=flat-square)](https://crates.io/crates/keyring)
4-
[![API Documentation on docs.rs](https://docs.rs/keyring/badge.svg)](https://docs.rs/keyring)
2+
[![build](https://github.com/hwchen/keyring-rs/actions/workflows/build.yaml/badge.svg)](https://github.com/hwchen/keyring-rs/actions)
3+
[![dependencies](https://deps.rs/repo/github/hwchen/keyring-rs/status.svg)](https://github.com/hwchen/keyring-rs)
4+
[![crates.io](https://img.shields.io/crates/v/keyring.svg?style=flat-square)](https://crates.io/crates/keyring)
5+
[![docs.rs](https://docs.rs/keyring/badge.svg)](https://docs.rs/keyring)
56

67
A cross-platform library to manage storage and retrieval of passwords
78
(and other secrets) in the underlying platform secure store,
89
with a fully-developed example that provides a command-line interface.
910

1011
## Usage
1112

12-
**Currently supports Linux, iOS, macOS, and Windows.**
13-
Please file issues if you have have questions or problems.
14-
1513
To use this library in your project add the following to your `Cargo.toml` file:
1614

1715
```toml
@@ -26,11 +24,7 @@ and a user name which together identify the entry.
2624

2725
Passwords can be added to an entry using its `set_password` method.
2826
They can then be read back using the `get_password` method,
29-
and removed using the `delete_password` method.
30-
(The persistence of the `Entry` is determined via Rust rules,
31-
so deleting the password doesn't delete the entry,
32-
but it does delete the underlying platform credential
33-
which is used to store the password.)
27+
and removed using the `delete_password` method.
3428

3529
```rust
3630
use keyring::{Entry, Result};
@@ -57,16 +51,12 @@ underlying platform errors or more information about what went wrong.
5751
The keychain-rs project contains a sample application (`cli`)
5852
and a sample library (`ios`).
5953

60-
The application is a command-line interface to the keyring.
54+
The `cli` application is a command-line interface to the keyring.
6155
It can be used to explore how the library is used.
6256
It can also be used in debugging keyring-based applications
6357
to probe the contents of the credential store.
64-
When run in "singly verbose" mode (-v),
65-
it outputs the retrieved credentials on each `get` run.
66-
When run in "doubly verbose" mode (-vv),
67-
it also outputs any errors returned.
6858

69-
The sample library is a full exercise of all the iOS functionality;
59+
The `ios` library is a full exercise of all the iOS functionality;
7060
it's meant to be loaded into an iOS test harness
7161
such as the one found in
7262
[this project](https://github.com/brotskydotcom/rust-on-ios).
@@ -75,23 +65,55 @@ doing so doesn't provide any advantages over the standard macOS tests.
7565

7666
## Client Testing
7767

78-
This crate comes with a "mock" credential store
68+
This crate comes with a mock credential store
7969
that can be used by clients who want to test
8070
without accessing the native platform store.
8171
The mock store is cross-platform
8272
and allows mocking errors as well as successes.
8373

8474
## Extensibility
8575

86-
This crate comes with built-in support for the keychain on Mac,
87-
the credential manager on Windows,
88-
and both secret-service and the kernel keyutils on Linux.
89-
But it's also designed to allow clients
90-
to "bring their own credential stores"
76+
This crate allows clients
77+
to "bring their own credential store"
9178
by providing traits that clients can implement.
9279
See the [developer docs](https://docs.rs/keyring/latest/keyring/)
9380
for details.
9481

82+
## Platforms
83+
84+
This crate provides secure storage support for
85+
Linux (secret-service and kernel keyutils),
86+
iOS (keychain), macOS (keychain),
87+
and Windows (credential manager).
88+
89+
It also builds on FreeBSD (secret-service),
90+
and probably works there,
91+
but since neither the maintainers nor GitHub do
92+
building and testing on FreeBSD, we can't be sure.
93+
94+
Please file issues if you have questions or problems.
95+
96+
## Upgrading from v1
97+
98+
The v2 release,
99+
although it adds a lot of functionality relative to v1,
100+
is fully compatible with respect to persisted entry data:
101+
it will both read and set passwords on entries that were
102+
originally written by v1, and entries written
103+
by v2 will be readable and updatable by v1.
104+
105+
From a client API point of view, the biggest difference
106+
between v2 and v1 is that entry creation using `Entry::new`
107+
and `Entry::new_with_target` can now fail, so v1 client
108+
code will need to add an `unwrap` or other error handling
109+
in order to work with v2.
110+
111+
There are also new `Error` variants in v2, and the enum
112+
has been declared non-exhaustive (to allow for variants
113+
to be added without breaking client code).
114+
This means that v1 client code that relies on exhaustive
115+
matching will need to be updated.
116+
95117
## License
96118

97119
Licensed under either of
@@ -123,6 +145,7 @@ whether through contributing code, discussion, or bug reports!
123145
- @MaikKlein
124146
- @Phrohdoh
125147
- @Rukenshia
148+
- @ryanavella
126149
- @samuela
127150
- @stankec
128151
- @steveatinfincia

examples/cli.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ fn execute_set_password(description: &str, entry: &Entry, password: &str) {
8383
Ok(()) => {
8484
println!("(Password for '{description}' set successfully)")
8585
}
86+
Err(Error::Ambiguous(creds)) => {
87+
eprintln!("More than one credential found for {description}: {creds:?}")
88+
}
8689
Err(err) => {
8790
eprintln!("Couldn't set password for '{description}': {err}",);
8891
}
@@ -110,7 +113,10 @@ fn execute_delete_password(description: &str, entry: &Entry) {
110113
match entry.delete_password() {
111114
Ok(()) => println!("(Password for '{description}' deleted)"),
112115
Err(Error::NoEntry) => {
113-
eprintln!("(No password for '{description}' found)");
116+
eprintln!("(No password found for '{description}')");
117+
}
118+
Err(Error::Ambiguous(creds)) => {
119+
eprintln!("More than one credential found for {description}: {creds:?}")
114120
}
115121
Err(err) => {
116122
eprintln!("Couldn't delete password for '{description}': {err}",);

src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
3-
Defines a platform-independent error model.
3+
Platform-independent error model.
44
55
There is an escape hatch here for surfacing platform-specific
66
error information returned by the platform-specific storage provider,

src/ios.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
3-
# iOS Keychain Credential Store
3+
# iOS Keychain credential store
44
55
iOS credential stores are called Keychains. On iOS there is only one of these.
66
Generic credentials on iOS can be identified by a large number of _key/value_ attributes;

src/keyutils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
3-
# Linux kernel credential store (via keyutils)
3+
# Linux kernel (keyutils) credential store
44
55
Modern linux kernels have a built-in secure store, [keyutils](https://www.man7.org/linux/man-pages/man7/keyutils.7.html).
66
This module (written primarily by [@landhb](https://github.com/landhb)) uses that secure store

src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ use crate::secret_service as default;
122122
#[cfg(all(target_os = "linux", feature = "linux-default-keyutils"))]
123123
use keyutils as default;
124124

125+
#[cfg(target_os = "freebsd")]
126+
pub mod secret_service;
127+
#[cfg(target_os = "freebsd")]
128+
use crate::secret_service as default;
129+
125130
#[cfg(target_os = "windows")]
126131
pub mod windows;
127132
#[cfg(target_os = "windows")]

src/macos.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
3-
# macOS Keychain Credential Store
3+
# macOS Keychain credential store
44
55
macOS credential stores are called keychains.
66
The OS automatically creates three of them (or four if removable media is being used).

src/mock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
3-
# Mock Credential Store
3+
# Mock credential store
44
55
To facilitate testing of clients, this crate provides a Mock credential store
66
that is platform-independent, provides no persistence, and allows the client

src/secret_service.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
3-
# secret-service Credential Store
3+
# secret-service credential store
44
55
Items in the secret-service are identified by an arbitrary collection
66
of attributes, and each has "label" for use in graphical editors. This

src/windows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
3-
# Windows Crendential Manager Credential Store
3+
# Windows Crendential Manager credential store
44
55
This module uses Windows Generic credentials to store entries.
66
These are identified by a single string (called their _target name_).

0 commit comments

Comments
 (0)