136 Commits

Author SHA1 Message Date
Jack Grigg 9329e31dd3 v0.5.1
Publish release binaries / Publish for macos-arm64 (push) Has been cancelled
Publish release binaries / Publish for macos-x86_64 (push) Has been cancelled
Publish release binaries / Publish for linux (push) Has been cancelled
Publish release binaries / Publish for windows (push) Has been cancelled
Publish release binaries / Debian linux (push) Has been cancelled
2026-04-08 04:27:00 +01:00
Jack Grigg ac22ae1df1 Merge tag 'v0.5.0' into detect-critical-extensions 2026-04-08 04:21:39 +01:00
Jack Grigg 23a1f61e5a v0.4.1
CI checks / Test on linux (push) Has been cancelled
CI checks / Test on macos (push) Has been cancelled
CI checks / Test on windows (push) Has been cancelled
CI checks / Code coverage (push) Has been cancelled
CI checks / Intra-doc links (push) Has been cancelled
CI checks / Rustfmt (push) Has been cancelled
Publish release binaries / Publish for macos-arm64 (push) Has been cancelled
Publish release binaries / Publish for macos-x86_64 (push) Has been cancelled
Publish release binaries / Publish for linux (push) Has been cancelled
Publish release binaries / Publish for windows (push) Has been cancelled
Publish release binaries / Debian linux (push) Has been cancelled
2026-04-08 04:20:54 +01:00
Jack Grigg eb945b2849 Merge tag 'v0.4.0' into detect-critical-extensions 2026-04-08 04:16:00 +01:00
Jack Grigg bf081835c4 Release 0.3.4
CI checks / Test on linux (push) Has been cancelled
CI checks / Test on macos (push) Has been cancelled
CI checks / Test on windows (push) Has been cancelled
CI checks / Clippy (1.56.0) (push) Has been cancelled
CI checks / Clippy (nightly) (push) Has been cancelled
CI checks / Code coverage (push) Has been cancelled
CI checks / Intra-doc links (push) Has been cancelled
CI checks / Rustfmt (push) Has been cancelled
Publish release binaries / Publish for macos-arm64 (push) Has been cancelled
Publish release binaries / Publish for macos-x86_64 (push) Has been cancelled
Publish release binaries / Publish for linux (push) Has been cancelled
Publish release binaries / Publish for windows (push) Has been cancelled
Publish release binaries / Debian linux (push) Has been cancelled
2026-04-08 04:14:54 +01:00
Jack Grigg 9503f406ae Reject identities with unrecognised critical extensions
We don't know how to correctly use these identities. In particular, some
identities store parts of their private key material in certificate
extensions to work around hardware limitations. Not understanding these
extensions could lead to encrypting with the wrong protocol and
violating security assumptions.
2026-04-08 04:12:35 +01:00
Jack Grigg ca1cd587ff Merge pull request #184 from str4d/release-0.5.0
Publish release binaries / Publish for macos-arm64 (push) Has been cancelled
Publish release binaries / Publish for macos-x86_64 (push) Has been cancelled
Publish release binaries / Publish for linux (push) Has been cancelled
Publish release binaries / Publish for windows (push) Has been cancelled
Publish release binaries / Debian linux (push) Has been cancelled
Release 0.5.0
2024-08-04 04:29:40 +01:00
Jack Grigg 0699991f2b v0.5.0 2024-08-04 03:17:15 +00:00
Jack Grigg 76143524ef cargo update 2024-08-04 03:16:48 +00:00
Jack Grigg fec9dcc994 Merge pull request #183 from str4d/update-deps-0.5.0
Update dependencies for 0.5.0
2024-08-04 02:58:41 +01:00
Jack Grigg 8aeb9f3da7 CI: Test on both MSRV and latest stable 2024-07-30 05:54:36 +00:00
Jack Grigg 34011088a0 Fix 1.67 clippy lints 2024-07-30 05:42:54 +00:00
Jack Grigg 24e6e6ffa6 which 5, test-with 0.11 2024-07-30 05:36:19 +00:00
Jack Grigg a44859d6b2 sysinfo 0.29 2024-07-30 05:33:42 +00:00
Jack Grigg 4921cbf6ed i18n-embed 0.14 2024-07-30 05:31:19 +00:00
Jack Grigg d6729e99ba dialoguer 0.11 2024-07-30 05:27:06 +00:00
Jack Grigg 6452fa0540 age-plugin 0.5 2024-07-30 05:19:27 +00:00
Jack Grigg 71eb71d9c6 cargo update 2024-07-30 05:19:23 +00:00
Jack Grigg f0d82245ea time 0.3.36
Closes str4d/age-plugin-yubikey#182.
2024-07-30 05:19:23 +00:00
Jack Grigg c7e6fdf58a Bump MSRV to 1.67
`time 0.3.35` has MSRV 1.67, and is a required update in order to fix
breakage on Rust 1.80 and above.
2024-07-30 05:05:09 +00:00
Jack Grigg 4a44fb9025 CI: Migrate to codecov-action@4.5.0 2024-07-30 04:59:00 +00:00
Jack Grigg c4256dddba CI: Migrate to cargo-tarpaulin container for code coverage 2024-07-30 04:56:43 +00:00
str4d 5159577135 Merge pull request #163 from str4d/dependabot/github_actions/codecov/codecov-action-3.1.5
Bump codecov/codecov-action from 3.1.1 to 3.1.5
2024-01-28 06:38:11 +00:00
dependabot[bot] e0b944a524 Bump codecov/codecov-action from 3.1.1 to 3.1.5
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3.1.1 to 3.1.5.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v3.1.1...v3.1.5)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-28 05:07:06 +00:00
str4d eadebfa2f6 Merge pull request #162 from str4d/ci-updates
CI updates
2024-01-28 05:06:21 +00:00
Jack Grigg 137df751fe CI: Fix test job 2024-01-28 04:21:51 +00:00
Jack Grigg a24de089e0 CI: Remove pointless timeouts 2024-01-28 04:21:44 +00:00
Jack Grigg 982b9d2f95 CI: actions/checkout@v4 2024-01-28 04:21:44 +00:00
str4d 0ebbc31890 Merge pull request #161 from str4d/packages
Add entries for existing packages to README
2024-01-28 03:58:20 +00:00
Jack Grigg d373d531e5 Add entries for existing packages to README 2024-01-28 03:45:04 +00:00
str4d 72da2b46c7 Merge pull request #149 from str4d/dependabot/github_actions/svenstaro/upload-release-action-2.6.1
Bump svenstaro/upload-release-action from 2.5.0 to 2.6.1
2024-01-28 03:32:14 +00:00
str4d d31c60f733 Merge pull request #158 from robinp/patch-1
Add Arch linux notes
2024-01-22 20:02:51 +00:00
str4d d7d47e861d Merge pull request #151 from pierreprinetti/readme_fedora
Add installation instructions for Fedora Linux
2024-01-22 20:02:20 +00:00
Robin Palotai 9bb39a7b95 Add Arch linux notes
I had `pcscd` already installed, but age-plugin-yubikey didn't work initially.

I installed `pcsc-tools` so I could do `pcsc_scan`, which also found nothing. Then I installed `yubikey-manager` so I could `ykman info`, which worked, but after that magically pcsc_scan and age-plugin-yubikey were working too.

Not sure if installing `yubikey-manager` had to do with it, but anyway.
2023-12-21 14:54:08 +01:00
Pierre Prinetti 7c512d283c Add installation instructions for Fedora Linux
Add entries in the README to get the PC/SC dependency ready under
Fedora.
2023-06-21 16:25:36 +02:00
dependabot[bot] 351d40e0c7 Bump svenstaro/upload-release-action from 2.5.0 to 2.6.1
Bumps [svenstaro/upload-release-action](https://github.com/svenstaro/upload-release-action) from 2.5.0 to 2.6.1.
- [Release notes](https://github.com/svenstaro/upload-release-action/releases)
- [Changelog](https://github.com/svenstaro/upload-release-action/blob/master/CHANGELOG.md)
- [Commits](https://github.com/svenstaro/upload-release-action/compare/2.5.0...2.6.1)

---
updated-dependencies:
- dependency-name: svenstaro/upload-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-01 09:01:22 +00:00
str4d acc783d0d3 Merge pull request #142 from str4d/update-release-workflow
Update release workflow
2023-04-09 10:34:52 +01:00
Jack Grigg 379adcb909 Update release workflow
- `ubuntu-18.04` runner has been deprecated and removed by GitHub. We
  now use `ubuntu-20.04`.
- `actions-rs/toolchain` is replaced by `dtolnay/rust-toolchain`.
2023-04-09 09:16:42 +00:00
str4d e77f00ff48 Merge pull request #141 from str4d/release-0.4.0
CI checks / Test on linux (push) Has been cancelled
CI checks / Test on macos (push) Has been cancelled
CI checks / Test on windows (push) Has been cancelled
CI checks / Code coverage (push) Has been cancelled
CI checks / Intra-doc links (push) Has been cancelled
CI checks / Rustfmt (push) Has been cancelled
Publish release binaries / Publish for macos-arm64 (push) Has been cancelled
Publish release binaries / Publish for macos-x86_64 (push) Has been cancelled
Publish release binaries / Publish for linux (push) Has been cancelled
Publish release binaries / Publish for windows (push) Has been cancelled
Publish release binaries / Debian linux (push) Has been cancelled
Release 0.4.0
2023-04-09 09:20:57 +01:00
Jack Grigg 3d8a5e9076 v0.4.0 2023-04-09 08:08:39 +00:00
Jack Grigg 00db2d1948 cargo update 2023-04-09 08:08:25 +00:00
str4d d7111594a7 Merge pull request #140 from str4d/improve-age-identity-docs
Clarify significance of the age identity file
2023-04-09 09:03:16 +01:00
Jack Grigg 20b84b9d4e Clarify significance of the age identity file
Replaces str4d/age-plugin-yubikey#122.
2023-04-09 07:38:23 +00:00
str4d 1182f472dd Merge pull request #139 from str4d/135-better-mgmt-key-auth-error
Provide a better error message when management key authentication fails
2023-04-09 08:13:12 +01:00
Jack Grigg 62f237f859 Provide a better error message when management key authentication fails
We now indicate to the user that AES management key algorithms are not
yet supported, and tell them how to change their management key to use
TDES.

Closes str4d/age-plugin-yubikey#135.
2023-04-09 06:53:25 +00:00
str4d 22fd00bd22 Merge pull request #138 from str4d/refactor-installation-docs
Refactor installation docs
2023-03-23 09:19:31 +00:00
Jack Grigg b6030ec4bd Note libpcsclite-dev dependency for Cargo builds in readme 2023-03-23 17:43:26 +09:00
Jack Grigg 9730e3da74 Clean up "Installation" readme section with tables 2023-03-23 17:38:17 +09:00
str4d 95657fd844 Merge pull request #130 from VlkrS/VlkrS-bsd-ccid
Explicitly mention CCID packages for the two BSDs
2023-03-23 08:30:07 +00:00
str4d a7bfeb9c3f Merge pull request #129 from str4d/78-ignore-readers-without-piv-applet
Ignore smart cards that don't have a PIV applet
2023-03-23 06:40:39 +00:00
Jack Grigg ac04615219 Ignore smart cards that don't have a PIV applet
Closes str4d/age-plugin-yubikey#78.
2023-03-23 14:33:13 +09:00
str4d cddb00ab95 Merge pull request #127 from str4d/update-deps
Update dependencies
2023-03-23 05:31:44 +00:00
Jack Grigg 7c532639d4 Fix clippy lints 2023-03-23 14:20:20 +09:00
Jack Grigg d2a856dd48 sysinfo 0.28 2023-03-23 14:13:21 +09:00
Jack Grigg d5395ea4e5 yubikey 0.8.0-pre.0 2023-03-23 14:07:13 +09:00
Jack Grigg 0d0f64ff1b base64 0.21 2023-03-23 14:07:13 +09:00
Jack Grigg edf4c5a45d cargo update 2023-03-23 13:42:51 +09:00
Jack Grigg ae39e136de Bump MSRV to 1.65.0
`yubikey 0.8.0` will have this MSRV, and it includes changes we need.
2023-03-23 13:33:06 +09:00
str4d defc1c1131 Merge pull request #133 from str4d/dependabot/github_actions/svenstaro/upload-release-action-2.5.0
Bump svenstaro/upload-release-action from 2.4.0 to 2.5.0
2023-03-23 04:09:30 +00:00
str4d af71a17f51 Merge pull request #137 from str4d/ci-updates
Update CI
2023-03-21 07:38:56 +00:00
Jack Grigg 02a81adfeb Update CI 2023-03-21 15:14:15 +08:00
dependabot[bot] 956d3bf28a Bump svenstaro/upload-release-action from 2.4.0 to 2.5.0
Bumps [svenstaro/upload-release-action](https://github.com/svenstaro/upload-release-action) from 2.4.0 to 2.5.0.
- [Release notes](https://github.com/svenstaro/upload-release-action/releases)
- [Changelog](https://github.com/svenstaro/upload-release-action/blob/master/CHANGELOG.md)
- [Commits](https://github.com/svenstaro/upload-release-action/compare/2.4.0...2.5.0)

---
updated-dependencies:
- dependency-name: svenstaro/upload-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-22 08:18:32 +00:00
str4d d9c5abaa15 Merge pull request #128 from str4d/115-yubikey-4-no-pin-cache
Document and warn that PIN policy "Once" doesn't work for YubiKey 4
2023-02-16 18:34:11 +00:00
str4d c5ca61a37c Merge pull request #131 from str4d/improve-puk-errors
Intercept PIN errors and replace with PUK errors as necessary
2023-02-16 18:33:05 +00:00
Jack Grigg e86cd8113c Intercept PIN errors and replace with PUK errors as necessary
Once iqlusioninc/yubikey.rs#479 is part of a `yubikey` release we
can migrate to, this will mean that users get correctly notified
of incorrect PUK entry, instead of being told it is an incorrect
PIN issue.
2023-02-12 20:47:58 +00:00
VlkrS e037c1c883 Mention ccid packages for {Open,Free}BSD
Addresses #112
2023-02-12 16:10:43 +01:00
VlkrS 051cace1fd Mention ccid packages for {Open,Free}BSD
Addresses #112
2023-02-12 16:08:47 +01:00
Jack Grigg 4e053b5efc TUI: Warn YubiKey 4 users of issue with PIN policy "Once" 2023-02-11 22:04:14 +00:00
Jack Grigg 762adfe098 Document that PIN cache preservation doesn't work for YubiKey 4 2023-02-11 21:26:44 +00:00
str4d 70c109aa1d Merge pull request #126 from str4d/integration-tests
Add some integration tests
2023-02-11 18:52:41 +00:00
Jack Grigg 355ce1cfde Add integration tests that require a live YubiKey slot 2023-02-11 18:40:09 +00:00
Jack Grigg 3408998283 Add encryption test with rage 2023-02-11 18:40:09 +00:00
str4d bf437663af Merge pull request #116 from str4d/avoid-resetting-unused-yubikeys
Avoid resetting unused YubiKeys
2023-02-11 04:57:23 +00:00
Jack Grigg 665aedbbba Merge branch 'version-0.3.3' back into main 2023-02-11 04:51:58 +00:00
str4d 307f5396a8 Merge pull request #124 from str4d/release-0.3.3
CI checks / Test on linux (push) Has been cancelled
CI checks / Test on macos (push) Has been cancelled
CI checks / Test on windows (push) Has been cancelled
CI checks / Clippy (1.56.0) (push) Has been cancelled
CI checks / Clippy (nightly) (push) Has been cancelled
CI checks / Code coverage (push) Has been cancelled
CI checks / Intra-doc links (push) Has been cancelled
CI checks / Rustfmt (push) Has been cancelled
Publish release binaries / Publish for macos-arm64 (push) Has been cancelled
Publish release binaries / Publish for macos-x86_64 (push) Has been cancelled
Publish release binaries / Publish for linux (push) Has been cancelled
Publish release binaries / Publish for windows (push) Has been cancelled
Publish release binaries / Debian linux (push) Has been cancelled
Release 0.3.3
2023-02-11 04:37:09 +00:00
Jack Grigg cd03e7bda3 Release 0.3.3 2023-02-11 04:28:16 +00:00
str4d 54ad666c73 Merge pull request #123 from str4d/120-prevent-default-pin
Prevent changing the default PIN to itself
2023-02-11 03:00:31 +00:00
Jack Grigg d2132b4ac2 Prevent changing the default PIN to itself
Closes str4d/age-plugin-yubikey#120.
2023-02-11 02:47:55 +00:00
str4d 80e8072624 Merge pull request #117 from str4d/more-smartcard-errors
Treat `pcsc::Error::NoSmartcard` as a "YubiKey disconnected" error
2023-02-11 02:18:34 +00:00
Jack Grigg ff3e8e37c9 Treat pcsc::Error::NoSmartcard as a "YubiKey disconnected" error
Some SmartCard readers report this error when no SmartCard is inserted,
so we need to check for it when filtering for connected YubiKeys (along
with `pcsc::Error::RemovedCard` which some _other_ SmartCard readers
report instead).

Closes str4d/age-plugin-yubikey#81.
2023-01-30 00:39:08 +00:00
str4d a5178bb16e Merge pull request #118 from str4d/correctly-handle-short-pins
Enforce correct PIN lengths during YubiKey setup
2023-01-30 00:37:44 +00:00
Jack Grigg b1710e8d69 Enforce correct PIN lengths during YubiKey setup
The behaviour of `age-plugin-yubikey` during setup now matches its
behaviour during plugin usage.
2023-01-29 23:00:46 +00:00
str4d 8483010393 Merge pull request #108 from str4d/dependabot/github_actions/svenstaro/upload-release-action-2.4.0
Bump svenstaro/upload-release-action from 2.3.0 to 2.4.0
2023-01-29 15:38:18 +00:00
Jack Grigg 55bfa5dafb Avoid resetting YubiKeys that don't match the desired serial
If multiple YubiKeys were connected, and the one we needed for plugin
encryption or decryption was not first in the list of readers, any
YubiKeys before it were being reset upon drop. We now explicitly
disconnect without resetting, since we only access these YubiKeys as a
side-effect of finding the one we need.
2023-01-29 14:16:35 +00:00
Jack Grigg 90b61682bd Don't reset tested YubiKeys in key::filter_connected
This method only connects to YubiKeys in order to confirm it can do so
(i.e. as a side-effect). We therefore want to explicitly disconnect
without resetting the YubiKeys, to avoid clearing PIN caches.
2023-01-29 14:16:35 +00:00
dependabot[bot] 97ddfc3bea Bump svenstaro/upload-release-action from 2.3.0 to 2.4.0
Bumps [svenstaro/upload-release-action](https://github.com/svenstaro/upload-release-action) from 2.3.0 to 2.4.0.
- [Release notes](https://github.com/svenstaro/upload-release-action/releases)
- [Changelog](https://github.com/svenstaro/upload-release-action/blob/master/CHANGELOG.md)
- [Commits](https://github.com/svenstaro/upload-release-action/compare/2.3.0...2.4.0)

---
updated-dependencies:
- dependency-name: svenstaro/upload-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-09 08:13:17 +00:00
str4d f34c534e84 Merge pull request #102 from tekumara/patch-1
docs: add brew install instructions
2023-01-03 02:31:27 +00:00
str4d 681cd06087 Merge pull request #103 from str4d/101-fix-gen-pin-always
Request PIN before certificate generation if PIN policy is "always"
2023-01-03 02:25:21 +00:00
Jack Grigg 45f6580be4 Request PIN before certificate generation if PIN policy is "always"
We also correctly ask for a PIN touch after the key is generated (which
does not need it) but before certificate generation (which does if the
touch policy is not "none").

Closes str4d/age-plugin-yubikey#101.
2023-01-03 02:20:51 +00:00
Oliver Mannion f5c8f7a559 docs: add brew install instructions 2023-01-03 10:10:45 +11:00
str4d e26ed3a163 Merge pull request #100 from str4d/pin-caching
Enable PIN caching
2023-01-02 19:12:11 +00:00
Jack Grigg 04c0418c02 Update README and CHANGELOG for PIN cache changes 2023-01-02 19:06:37 +00:00
Jack Grigg 00ab2c756e Don't re-request a cached PIN for identities with PIN policy "once" 2023-01-02 19:06:37 +00:00
Jack Grigg 9418921dab Disconnect without resetting YubiKeys if it is safe to do so
This enables the PIN caches to be preserved across age-plugin-yubikey
processes, allowing PIN policies of "once" to become meaningful.
2023-01-02 19:06:37 +00:00
str4d 87541510ad Merge pull request #99 from VlkrS/main
Add pcscd recommentation for {Open,Free}BSD
2023-01-01 14:43:41 +00:00
vlkrs 9ac72cd66f Add recommendations for {Open,Free}BSD when pcscd isn't running. 2023-01-01 15:30:40 +01:00
VlkrS 093a35733f Add pcscd instructions for FreeBSD and OpenBSD 2023-01-01 15:16:42 +01:00
str4d 082a4f976c Merge pull request #88 from str4d/msrv-1.60
Bump MSRV to 1.60
2023-01-01 14:12:31 +00:00
Jack Grigg 3e1f3b45f5 sysinfo 0.27 2023-01-01 14:07:23 +00:00
Jack Grigg a6a5ad109e Fix clippy lints 2023-01-01 14:07:23 +00:00
Jack Grigg 25fcd353f3 dialoguer 0.10 2023-01-01 14:07:22 +00:00
Jack Grigg d8ab6e373e base64 0.20 2023-01-01 14:06:35 +00:00
Jack Grigg 0490dd3529 env_logger 0.10 2023-01-01 14:06:35 +00:00
Jack Grigg f45ff653b8 Bump cryptographic dependencies
- age-plugin 0.4
- bech32 0.9
- p256 0.11
- sha2 0.10
- x509-parser 0.14
- yubikey 0.7
2023-01-01 14:06:34 +00:00
Jack Grigg e78871d6f3 cargo update 2023-01-01 14:04:28 +00:00
Jack Grigg ec83a8c9cc Bump MSRV to 1.60.0 2023-01-01 14:04:27 +00:00
str4d fc2081c216 Merge pull request #98 from str4d/release-0.3.2
CI checks / Test on linux (push) Has been cancelled
CI checks / Test on macos (push) Has been cancelled
CI checks / Test on windows (push) Has been cancelled
CI checks / Clippy (1.56.0) (push) Has been cancelled
CI checks / Clippy (nightly) (push) Has been cancelled
CI checks / Code coverage (push) Has been cancelled
CI checks / Intra-doc links (push) Has been cancelled
CI checks / Rustfmt (push) Has been cancelled
Publish release binaries / Publish for macos-arm64 (push) Has been cancelled
Publish release binaries / Publish for macos-x86_64 (push) Has been cancelled
Publish release binaries / Publish for linux (push) Has been cancelled
Publish release binaries / Publish for windows (push) Has been cancelled
Publish release binaries / Debian linux (push) Has been cancelled
Release 0.3.2
2023-01-01 13:53:55 +00:00
Jack Grigg 367a081eea Release 0.3.2 2023-01-01 13:45:21 +00:00
str4d cfb1e5e3d5 Merge pull request #97 from str4d/more-cleanups
More cleanups
2023-01-01 13:44:15 +00:00
Jack Grigg 1dfadc7e27 Clean up key::filter_connected 2023-01-01 13:29:30 +00:00
Jack Grigg fc66d9f6fd Add helper methods for filtering available keys 2023-01-01 13:27:10 +00:00
Jack Grigg d8eb198e97 Move certificate parsing into Metadata::extract 2023-01-01 13:27:10 +00:00
str4d c8f9df1b45 Merge pull request #95 from str4d/94-yubikey-agent-sighup
Extend "sharing violation" logic to send SIGHUP to `yubikey-agent` processes
2023-01-01 13:24:57 +00:00
Jack Grigg 3597d96332 Correctly hunt agents in plugin mode 2023-01-01 13:18:41 +00:00
Jack Grigg 1913838f8e Hunt for yubikey-agent 2023-01-01 12:52:17 +00:00
Jack Grigg 6e47448560 Generalise code for hunting agents that may be holding YubiKeys 2023-01-01 12:52:17 +00:00
str4d 4d4d8cc183 Merge pull request #96 from str4d/refactors-and-cleanups
Refactors and cleanups
2022-12-31 16:41:21 +00:00
Jack Grigg ac7b04a61d Add keyword argument support to fl! and wlnfl! macros 2022-12-31 14:31:25 +00:00
Jack Grigg 493479344c De-duplicate parsing recipients from SubjectPublicKeyInfo 2022-12-31 12:49:44 +00:00
str4d d4f8993988 Merge pull request #93 from str4d/release-0.3.1
CI checks / Test on linux (push) Has been cancelled
CI checks / Test on macos (push) Has been cancelled
CI checks / Test on windows (push) Has been cancelled
CI checks / Clippy (1.56.0) (push) Has been cancelled
CI checks / Clippy (nightly) (push) Has been cancelled
CI checks / Code coverage (push) Has been cancelled
CI checks / Intra-doc links (push) Has been cancelled
CI checks / Rustfmt (push) Has been cancelled
Publish release binaries / Publish for macos-arm64 (push) Has been cancelled
Publish release binaries / Publish for macos-x86_64 (push) Has been cancelled
Publish release binaries / Publish for linux (push) Has been cancelled
Publish release binaries / Publish for windows (push) Has been cancelled
Publish release binaries / Debian linux (push) Has been cancelled
Release 0.3.1
2022-12-30 12:04:50 +00:00
Jack Grigg 876afecc5c Release 0.3.1 2022-12-30 11:57:17 +00:00
str4d 539111c30c Merge pull request #91 from str4d/tdes-mgmkey-advice
Clarify that non-TDES management keys are unsupported
2022-12-30 10:51:52 +00:00
Jack Grigg 647a620a9c Clarify that non-TDES management keys are unsupported
Supporting them is blocked on iqlusioninc/yubikey.rs#330.
2022-12-30 10:39:34 +00:00
str4d 0eee944c64 Merge pull request #90 from str4d/21-mgmkey-advice
Give guidance on reconfiguring YubiKeys with unprotected management keys
2022-12-30 10:23:51 +00:00
Jack Grigg e4ef700263 Give guidance on reconfiguring YubiKeys with unprotected management keys
Closes str4d/age-plugin-yubikey#21.
2022-12-30 10:18:17 +00:00
str4d 492612fc8b Merge pull request #89 from str4d/82-stop-scdaemon
Stop scdaemon if it is holding exclusive access to a YubiKey
2022-12-30 09:36:47 +00:00
Jack Grigg 15c53e42df Stop scdaemon if it is holding exclusive access to a YubiKey
Closes str4d/age-plugin-yubikey#82.
2022-12-30 09:28:24 +00:00
str4d 5d6b618d5f Merge pull request #87 from str4d/71-m1-binaries
CI: Build release binaries for Apple ARM64
2022-12-30 03:44:24 +00:00
Jack Grigg 0ee618cdfd CI: Build release binaries for Apple ARM64
Closes str4d/age-plugin-yubikey#71.
2022-12-30 03:38:40 +00:00
str4d ed6273d781 Merge pull request #86 from str4d/83-improve-missing-service-error
Inform users when `pcscd` is required
2022-12-29 10:10:42 +00:00
Jack Grigg d38743a2fc Inform users when pcscd is required
Closes str4d/age-plugin-yubikey#83.
2022-12-29 05:09:47 +00:00
str4d aaa445c4ac Merge pull request #74 from str4d/dependabot/github_actions/svenstaro/upload-release-action-2.3.0
Bump svenstaro/upload-release-action from 2.2.1 to 2.3.0
2022-12-28 14:01:29 +00:00
Jack Grigg e415ce4ae9 CI: Remove upload-release-action fields that match defaults 2022-12-28 13:53:56 +00:00
str4d 145237003e Merge pull request #79 from str4d/dependabot/github_actions/codecov/codecov-action-3.1.1
Bump codecov/codecov-action from 3.1.0 to 3.1.1
2022-12-28 13:48:15 +00:00
dependabot[bot] 9338b320a4 Bump codecov/codecov-action from 3.1.0 to 3.1.1
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3.1.0 to 3.1.1.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/master/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v3.1.0...v3.1.1)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-20 08:29:52 +00:00
dependabot[bot] aae48c4f6c Bump svenstaro/upload-release-action from 2.2.1 to 2.3.0
Bumps [svenstaro/upload-release-action](https://github.com/svenstaro/upload-release-action) from 2.2.1 to 2.3.0.
- [Release notes](https://github.com/svenstaro/upload-release-action/releases)
- [Changelog](https://github.com/svenstaro/upload-release-action/blob/master/CHANGELOG.md)
- [Commits](https://github.com/svenstaro/upload-release-action/compare/2.2.1...2.3.0)

---
updated-dependencies:
- dependency-name: svenstaro/upload-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-06 08:56:16 +00:00
21 changed files with 2935 additions and 1062 deletions
+65 -99
View File
@@ -1,10 +1,13 @@
name: CI checks name: CI checks
on: [push, pull_request] on:
pull_request:
push:
branches: main
jobs: jobs:
test: test-msrv:
name: Test on ${{ matrix.name }} name: Test MSRV on ${{ matrix.name }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
@@ -22,131 +25,94 @@ jobs:
os: macos-latest os: macos-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.56.0
override: true
- name: Install build dependencies - name: Install build dependencies
run: sudo apt install ${{ matrix.build_deps }} run: sudo apt install ${{ matrix.build_deps }}
if: matrix.build_deps != '' if: matrix.build_deps != ''
- name: cargo fetch - uses: dtolnay/rust-toolchain@stable
uses: actions-rs/cargo@v1 id: stable-toolchain
with: - name: Install test dependencies using latest stable Rust
command: fetch run: cargo +${{steps.stable-toolchain.outputs.name}} install rage
- name: Build tests
uses: actions-rs/cargo@v1
with:
command: build
args: --verbose --tests
- name: Run tests - name: Run tests
uses: actions-rs/cargo@v1 run: cargo test
with: - name: Verify working directory is clean
command: test run: git diff --exit-code
args: --verbose
clippy: test-latest:
name: Clippy (1.56.0) name: Test latest stable on ${{ matrix.name }}
timeout-minutes: 30 runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest strategy:
steps: matrix:
- uses: actions/checkout@v3 name: [linux, windows, macos]
- uses: actions-rs/toolchain@v1 include:
with: - name: linux
toolchain: 1.56.0 os: ubuntu-latest
components: clippy build_deps: >
override: true libpcsclite-dev
- name: Install build dependencies
run: sudo apt install libpcsclite-dev - name: windows
- name: Run clippy os: windows-latest
uses: actions-rs/clippy-check@v1
with: - name: macos
name: Clippy (1.56.0) os: macos-latest
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -D warnings
clippy-nightly:
name: Clippy (nightly)
timeout-minutes: 30
runs-on: ubuntu-latest
continue-on-error: true
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy
override: true
- name: Install build dependencies - name: Install build dependencies
run: sudo apt install libpcsclite-dev run: sudo apt install ${{ matrix.build_deps }}
- name: Run Clippy (nightly) if: matrix.build_deps != ''
uses: actions-rs/clippy-check@v1 - uses: dtolnay/rust-toolchain@stable
continue-on-error: true - uses: dtolnay/rust-toolchain@stable
with: id: toolchain
name: Clippy (nightly) - run: rustup override set ${{steps.toolchain.outputs.name}}
token: ${{ secrets.GITHUB_TOKEN }} - name: Install test dependencies
args: --all-features --all-targets run: cargo install rage
- name: Remove lockfile to build with latest dependencies
run: rm Cargo.lock
- name: Run tests
run: cargo test
- name: Verify working directory is clean (excluding lockfile)
run: git diff --exit-code ':!Cargo.lock'
codecov: codecov:
name: Code coverage name: Code coverage
runs-on: ubuntu-latest runs-on: ubuntu-latest
container:
image: xd009642/tarpaulin:develop-nightly
options: --security-opt seccomp=unconfined
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
# Use stable for this to ensure that cargo-tarpaulin can be built.
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Install build dependencies - name: Install build dependencies
run: sudo apt install libpcsclite-dev run: apt update && apt install -y libpcsclite-dev
- name: Generate coverage report - name: Generate coverage report
uses: actions-rs/tarpaulin@v0.1 run: >
with: cargo tarpaulin
args: --release --timeout 180 --out Xml --engine llvm
--timeout 180
--out xml
- name: Upload coverage to Codecov - name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.1.0 uses: codecov/codecov-action@v4.5.0
with: with:
token: ${{secrets.CODECOV_TOKEN}} fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
doc-links: doc-links:
name: Intra-doc links name: Intra-doc links
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.56.0
override: true
- name: Install build dependencies - name: Install build dependencies
run: sudo apt install libpcsclite-dev run: sudo apt install libpcsclite-dev
- name: cargo fetch - run: cargo fetch
uses: actions-rs/cargo@v1 # Requires #![deny(rustdoc::broken_intra_doc_links)] in crates.
with:
command: fetch
# Ensure intra-documentation links all resolve correctly
# Requires #![deny(intra_doc_link_resolution_failure)] in crates.
- name: Check intra-doc links - name: Check intra-doc links
uses: actions-rs/cargo@v1 run: cargo doc --document-private-items
with:
command: doc
args: --document-private-items
fmt: fmt:
name: Rustfmt name: Rustfmt
timeout-minutes: 30
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.56.0
components: rustfmt
override: true
- name: Check formatting - name: Check formatting
uses: actions-rs/cargo@v1 run: cargo fmt -- --check
with:
command: fmt
args: -- --check
+22
View File
@@ -0,0 +1,22 @@
name: Beta lints
# We only run these lints on trial-merges of PRs to reduce noise.
on: pull_request
jobs:
clippy-beta:
name: Clippy (beta)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@beta
id: toolchain
- run: rustup override set ${{steps.toolchain.outputs.name}}
- name: Install build dependencies
run: sudo apt install libpcsclite-dev
- name: Clippy (beta)
uses: actions-rs/clippy-check@v1
with:
name: Clippy (beta)
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -W clippy::all
+19
View File
@@ -0,0 +1,19 @@
name: Stable lints
# We only run these lints on trial-merges of PRs to reduce noise.
on: pull_request
jobs:
clippy:
name: Clippy (MSRV)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install build dependencies
run: sudo apt install libpcsclite-dev
- name: Run clippy
uses: actions-rs/clippy-check@v1
with:
name: Clippy (MSRV)
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -D warnings
+25 -20
View File
@@ -17,10 +17,14 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
name: [linux, windows, macos] name:
- linux
- macos-arm64
- macos-x86_64
- windows
include: include:
- name: linux - name: linux
os: ubuntu-18.04 os: ubuntu-20.04
build_deps: > build_deps: >
libpcsclite-dev libpcsclite-dev
archive_name: age-plugin-yubikey.tar.gz archive_name: age-plugin-yubikey.tar.gz
@@ -31,17 +35,23 @@ jobs:
archive_name: age-plugin-yubikey.zip archive_name: age-plugin-yubikey.zip
asset_suffix: x86_64-windows.zip asset_suffix: x86_64-windows.zip
- name: macos - name: macos-arm64
os: macos-latest
target: aarch64-apple-darwin
build_flags: --target aarch64-apple-darwin
archive_name: age-plugin-yubikey.tar.gz
asset_suffix: arm64-darwin.tar.gz
- name: macos-x86_64
os: macos-latest os: macos-latest
archive_name: age-plugin-yubikey.tar.gz archive_name: age-plugin-yubikey.tar.gz
asset_suffix: x86_64-darwin.tar.gz asset_suffix: x86_64-darwin.tar.gz
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1 - uses: dtolnay/rust-toolchain@stable
with: id: toolchain
toolchain: stable - run: rustup override set ${{steps.toolchain.outputs.name}}
override: true
- name: Add target - name: Add target
run: rustup target add ${{ matrix.target }} run: rustup target add ${{ matrix.target }}
if: matrix.target != '' if: matrix.target != ''
@@ -76,18 +86,16 @@ jobs:
if: matrix.name == 'windows' if: matrix.name == 'windows'
- name: Upload archive to release - name: Upload archive to release
uses: svenstaro/upload-release-action@2.2.1 uses: svenstaro/upload-release-action@2.6.1
with: with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ matrix.archive_name }} file: ${{ matrix.archive_name }}
asset_name: age-plugin-yubikey-$tag-${{ matrix.asset_suffix }} asset_name: age-plugin-yubikey-$tag-${{ matrix.asset_suffix }}
tag: ${{ github.ref }}
prerelease: true prerelease: true
if: github.event.inputs.test != 'true' if: github.event.inputs.test != 'true'
deb: deb:
name: Debian ${{ matrix.name }} name: Debian ${{ matrix.name }}
runs-on: ubuntu-18.04 runs-on: ubuntu-20.04
strategy: strategy:
matrix: matrix:
name: [linux] name: [linux]
@@ -98,11 +106,10 @@ jobs:
libpcsclite-dev libpcsclite-dev
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1 - uses: dtolnay/rust-toolchain@stable
with: id: toolchain
toolchain: stable - run: rustup override set ${{steps.toolchain.outputs.name}}
override: true
- name: Add target - name: Add target
run: rustup target add ${{ matrix.target }} run: rustup target add ${{ matrix.target }}
- name: cargo install cargo-deb - name: cargo install cargo-deb
@@ -137,11 +144,9 @@ jobs:
args: --package age-plugin-yubikey --no-build --target ${{ matrix.target }} args: --package age-plugin-yubikey --no-build --target ${{ matrix.target }}
- name: Upload Debian package to release - name: Upload Debian package to release
uses: svenstaro/upload-release-action@2.2.1 uses: svenstaro/upload-release-action@2.6.1
with: with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/${{ matrix.target }}/debian/*.deb file: target/${{ matrix.target }}/debian/*.deb
tag: ${{ github.ref }}
file_glob: true file_glob: true
prerelease: true prerelease: true
if: github.event.inputs.test != 'true' if: github.event.inputs.test != 'true'
+60
View File
@@ -8,6 +8,66 @@ to 0.3.0 are beta releases.
## [Unreleased] ## [Unreleased]
## [0.3.4], [0.4.1], [0.5.1] - 2026-04-08
### Fixed
- `age-plugin-yubikey` now completely ignores any identity that has unrecognised
critical extensions in its certificate, to ensure it doesn't misuse a newer
identity type.
## [0.5.0] - 2024-08-04
### Fixed
- `age-plugin-yubikey` can now be compiled with Rust 1.80 and above.
### Changed
- MSRV is now 1.67.0.
## [0.4.0] - 2023-04-09
### Changed
- MSRV is now 1.65.0.
- The YubiKey PIV PIN and touch caches are now preserved across processes in
most cases. See [README.md](README.md#agent-support) for exceptions. This has
several usability effects (not applicable to YubiKey 4 series):
- If a YubiKey's PIN is cached by an agent like `yubikey-agent`, and then
`age-plugin-yubikey` is run (either directly or as a plugin), the agent
won't request a PIN entry on its next use.
- If a YubiKey's PIN was requested by either a previous invocation of
`age-plugin-yubikey` or an agent like `yubikey-agent`, subsequent calls to
`age-plugin-yubikey` won't request a PIN entry to decrypt a file with an
identity that has a PIN policy of `once`.
### Fixed
- Identities can now be generated with a PIN policy of "always" (in previous
versions of `age-plugin-yubikey` this would cause an error).
## [0.3.3] - 2023-02-11
### Fixed
- When `age-plugin-yubikey` assists the user in changing their PIN from the
default PIN, it no longer tells the user that PINs shorter than 6 characters
are allowed, and instead loops until the user enters a PIN of valid length.
It also now prevents the user from setting their PIN to the default PIN, to
avoid creating a cycle.
- More kinds of SmartCard readers are ignored when they have no SmartCard
inserted.
## [0.3.2] - 2023-01-01
### Changed
- The "sharing violation" logic now also sends SIGHUP to any `yubikey-agent`
that is running, to have them release any YubiKey locks they are holding.
### Fixed
- The "sharing violation" logic now runs during plugin mode as intended. In the
previous release it only ran during direct `age-plugin-yubikey` usage.
## [0.3.1] - 2022-12-30
### Changed
- If a "sharing violation" error is encountered while opening a connection to a
YubiKey, and `scdaemon` is running (which can hold exclusive access to a
YubiKey indefinitely), `age-plugin-yubikey` now attempts to stop `scdaemon` by
interrupting it (or killing it on Windows), and then tries again to open the
connection.
- Several error messages were enhanced with guidance on how to resolve their
respective issue.
## [0.3.0] - 2022-05-02 ## [0.3.0] - 2022-05-02
First non-beta release! First non-beta release!
Generated
+1769 -474
View File
File diff suppressed because it is too large Load Diff
+22 -15
View File
@@ -1,7 +1,7 @@
[package] [package]
name = "age-plugin-yubikey" name = "age-plugin-yubikey"
description = "YubiKey plugin for age clients" description = "YubiKey plugin for age clients"
version = "0.3.0" version = "0.5.1"
authors = ["Jack Grigg <thestr4d@gmail.com>"] authors = ["Jack Grigg <thestr4d@gmail.com>"]
repository = "https://github.com/str4d/age-plugin-yubikey" repository = "https://github.com/str4d/age-plugin-yubikey"
readme = "README.md" readme = "README.md"
@@ -9,6 +9,7 @@ keywords = ["age", "cli", "encryption", "yubikey"]
categories = ["command-line-utilities", "cryptography"] categories = ["command-line-utilities", "cryptography"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
edition = "2021" edition = "2021"
rust-version = "1.67" # MSRV
[package.metadata.deb] [package.metadata.deb]
extended-description = """\ extended-description = """\
@@ -21,31 +22,37 @@ assets = [
] ]
[dependencies] [dependencies]
age-core = "0.8" age-core = "0.10"
age-plugin = "0.3" age-plugin = "0.5"
base64 = "0.13" base64 = "0.21"
bech32 = "0.8" bech32 = "0.9"
console = { version = "0.15", default-features = false } console = { version = "0.15", default-features = false }
dialoguer = { version = "0.9", default-features = false, features = ["password"] } dialoguer = { version = "0.11", default-features = false, features = ["password"] }
env_logger = "0.9" env_logger = "0.10"
gumdrop = "0.8" gumdrop = "0.8"
hex = "0.4" hex = "0.4"
log = "0.4" log = "0.4"
p256 = { version = "0.9", features = ["ecdh"] } p256 = { version = "0.13", features = ["ecdh"] }
pcsc = "2.4" pcsc = "2.4"
rand = "0.8" rand = "0.8"
sha2 = "0.9" sha2 = "0.10"
which = "4.1" which = "5"
x509 = "0.2" x509 = "0.2"
x509-parser = "0.12" x509-parser = "0.14"
yubikey = { version = "0.5", features = ["untested"] } yubikey = { version = "=0.8.0-pre.0", features = ["untested"] }
# Translations # Translations
i18n-embed = { version = "0.13", features = ["desktop-requester", "fluent-system"] } i18n-embed = { version = "0.14", features = ["desktop-requester", "fluent-system"] }
i18n-embed-fl = "0.6" i18n-embed-fl = "0.8"
lazy_static = "1" lazy_static = "1"
rust-embed = "6" rust-embed = "8"
# GnuPG coexistence
sysinfo = "0.29"
[dev-dependencies] [dev-dependencies]
flate2 = "1" flate2 = "1"
man = "0.3" man = "0.3"
tempfile = "3"
test-with = "0.11"
which = "5"
+66 -14
View File
@@ -6,18 +6,43 @@ which enables files to be encrypted to age identities stored on YubiKeys.
## Installation ## Installation
| Environment | CLI command |
|-------------|-------------|
| Cargo (Rust 1.67+) | `cargo install age-plugin-yubikey` |
| Homebrew (macOS or Linux) | `brew install age-plugin-yubikey` |
| Arch Linux | `pacman -S age-plugin-yubikey` |
| Debian | [Debian package](https://github.com/str4d/age-plugin-yubikey/releases) |
| NixOS | Add to config:<br>`environment.systemPackages = [`<br>` pkgs.age-plugin-yubikey`<br>`];`<br>Or run `nix-env -i age-plugin-yubikey` |
| Ubuntu 20.04+ | [Debian package](https://github.com/str4d/age-plugin-yubikey/releases) |
| OpenBSD | `pkg_add age-plugin-yubikey` (security/age-plugin-yubikey) |
On Windows, Linux, and macOS, you can use the On Windows, Linux, and macOS, you can use the
[pre-built binaries](https://github.com/str4d/age-plugin-yubikey/releases). [pre-built binaries](https://github.com/str4d/age-plugin-yubikey/releases).
If your system has Rust 1.56+ installed (either via `rustup` or a system
package), you can build directly from source:
```
cargo install age-plugin-yubikey
```
Help from new packagers is very welcome. Help from new packagers is very welcome.
### Linux, BSD, etc.
On non-Windows, non-macOS systems, you need to ensure that the `pcscd` service
is installed and running.
| Environment | CLI command |
|-------------|-------------|
| Debian or Ubuntu | `sudo apt-get install pcscd` |
| Fedora | `sudo dnf install pcsc-lite` |
| OpenBSD | As ```root``` do:<br>`pkg_add pcsc-lite ccid`<br>`rcctl enable pcscd`<br>`rcctl start pcscd` |
| FreeBSD | As ```root``` do:<br>`pkg install pcsc-lite libccid`<br>`service pcscd enable`<br>`service pcscd start` |
| Arch | `sudo pacman -S pcsclite pcsc-tools yubikey-manager`<br>`sudo systemctl enable pcscd`<br>`sudo systemctl start pcscd`|
When installing via Cargo, you also need to ensure that the development headers
for the `pcsc-lite` library are available, so that the `pcsc-sys` crate can be
compiled.
| Environment | CLI command |
|-------------|-------------|
| Debian or Ubuntu | `sudo apt-get install libpcsclite-dev` |
| Fedora | `sudo dnf install pcsc-lite-devel` |
### Windows Subsystem for Linux (WSL) ### Windows Subsystem for Linux (WSL)
WSL does not currently provide native support for USB devices. However, Windows WSL does not currently provide native support for USB devices. However, Windows
@@ -35,7 +60,12 @@ YubiKey:
## Configuration ## Configuration
There are two ways to configure a YubiKey as an `age` identity. You can run the `age-plugin-yubikey` identities have two parts:
- The secret key material, which is stored inside a YubiKey.
- An age identity file, which contains information that an age client can use to
figure out which YubiKey secret key should be used.
There are two ways to configure a YubiKey as an age identity. You can run the
plugin binary directly to use a simple text interface, which will create an age plugin binary directly to use a simple text interface, which will create an age
identity file: identity file:
@@ -61,6 +91,14 @@ Once an identity has been created, you can regenerate it later:
$ age-plugin-yubikey --identity [--serial SERIAL] --slot SLOT $ age-plugin-yubikey --identity [--serial SERIAL] --slot SLOT
``` ```
To use the identity with an age client, it needs to be stored in a file. When
using the above programmatic flags, you can do this by redirecting standard
output to a file. On a Unix system like macOS or Ubuntu:
```
$ age-plugin-yubikey --identity --slot SLOT > yubikey-identity.txt
```
## Usage ## Usage
The age recipients contained in all connected YubiKeys can be printed on The age recipients contained in all connected YubiKeys can be printed on
@@ -85,13 +123,27 @@ age client as normal (e.g. `rage -d -i yubikey-identity.txt`).
### Agent support ### Agent support
`age-plugin-yubikey` does not provide or interact with an agent for decryption. `age-plugin-yubikey` does not provide or interact with an agent for decryption.
As age plugin binaries have short lifetimes (they only run while the age client It does however attempt to preserve the PIN cache by not soft-resetting the
is running), this means that YubiKey identities configured with a PIN policy of YubiKey after a decryption or read-only operation, which enables YubiKey
`once` will actually prompt for the PIN on every decryption. identities configured with a PIN policy of `once` to not prompt for the PIN on
every decryption. **This does not work for YubiKey 4 series.**
A decryption agent will most likely be implemented as a separate age plugin that The session that corresponds to the `once` policy can be ended in several ways,
interacts with [`yubikey-agent`](https://github.com/FiloSottile/yubikey-agent), not all of which are necessarily intuitive:
enabling YubiKeys to be used simultaneously with age and SSH.
- Unplugging the YubiKey (the obvious way).
- Using a different applet (e.g. FIDO2). This causes the PIV applet to be closed
which clears its state.
- This is why the YubiKey 4 series does not support PIN cache preservation:
their serial can only be obtained by switching to the OTP applet.
- Generating a new age identity via `age-plugin-yubikey --generate` or the CLI
interface. This is to avoid leaving the YubiKey authenticated with the
management key.
If the current PIN UX proves to be insufficient, a decryption agent will most
likely be implemented as a separate age plugin that interacts with
[`yubikey-agent`](https://github.com/FiloSottile/yubikey-agent), enabling
YubiKeys to be used simultaneously with age and SSH.
### Manual setup and technical details ### Manual setup and technical details
+1 -1
View File
@@ -6,7 +6,7 @@ use std::io::prelude::*;
const MANPAGES_DIR: &str = "./target/manpages"; const MANPAGES_DIR: &str = "./target/manpages";
fn generate_manpage(page: String, name: &str) { fn generate_manpage(page: String, name: &str) {
let file = File::create(format!("{}/{}.1.gz", MANPAGES_DIR, name)) let file = File::create(format!("{MANPAGES_DIR}/{name}.1.gz"))
.expect("Should be able to open file in target directory"); .expect("Should be able to open file in target directory");
let mut encoder = GzEncoder::new(file, Compression::best()); let mut encoder = GzEncoder::new(file, Compression::best());
encoder encoder
+60 -4
View File
@@ -12,6 +12,7 @@
-yubikey = YubiKey -yubikey = YubiKey
-yubikeys = YubiKeys -yubikeys = YubiKeys
-age-plugin-yubikey = age-plugin-yubikey -age-plugin-yubikey = age-plugin-yubikey
-pcscd = pcscd
## CLI commands and flags ## CLI commands and flags
@@ -75,6 +76,14 @@ cli-setup-name-identity = 📛 Name this identity
cli-setup-select-pin-policy = 🔤 Select a PIN policy cli-setup-select-pin-policy = 🔤 Select a PIN policy
cli-setup-select-touch-policy = 👆 Select a touch policy cli-setup-select-touch-policy = 👆 Select a touch policy
cli-setup-yk4-pin-policy =
⚠️ Your {-yubikey} is a {-yubikey} 4 series. With ephemeral applications like
{-age-plugin-yubikey}, a PIN policy of "Once" behaves like a PIN policy of
"Always", and your PIN will be requested for every decryption. However, you
might still benefit from a PIN policy of "Once" in long-running applications
like agents.
cli-setup-yk4-pin-policy-confirm = Use PIN policy of "Once" with {-yubikey} 4?
cli-setup-generate-new = Generate new identity in slot {$slot_index}? cli-setup-generate-new = Generate new identity in slot {$slot_index}?
cli-setup-use-existing = Use existing identity in slot {$slot_index}? cli-setup-use-existing = Use existing identity in slot {$slot_index}?
@@ -111,6 +120,7 @@ cli-setup-finished =
open-yk-with-serial = ⏳ Please insert the {-yubikey} with serial {$yubikey_serial}. open-yk-with-serial = ⏳ Please insert the {-yubikey} with serial {$yubikey_serial}.
open-yk-without-serial = ⏳ Please insert the {-yubikey}. open-yk-without-serial = ⏳ Please insert the {-yubikey}.
warn-yk-not-connected = Ignoring {$yubikey_name}: not connected warn-yk-not-connected = Ignoring {$yubikey_name}: not connected
warn-yk-missing-applet = Ignoring {$yubikey_name}: Missing {$applet_name} applet
print-recipient = Recipient: {$recipient} print-recipient = Recipient: {$recipient}
@@ -126,13 +136,15 @@ mgr-change-default-pin =
✨ Your {-yubikey} is using the default PIN. Let's change it! ✨ Your {-yubikey} is using the default PIN. Let's change it!
✨ We'll also set the PUK equal to the PIN. ✨ We'll also set the PUK equal to the PIN.
🔐 The PIN is up to 8 numbers, letters, or symbols. Not just numbers! 🔐 The PIN can be numbers, letters, or symbols. Not just numbers!
📏 The PIN must be at least 6 and at most 8 characters in length.
❌ Your keys will be lost if the PIN and PUK are locked after 3 incorrect tries. ❌ Your keys will be lost if the PIN and PUK are locked after 3 incorrect tries.
mgr-enter-current-puk = Enter current PUK (default is {$default_puk}) mgr-enter-current-puk = Enter current PUK (default is {$default_puk})
mgr-choose-new-pin = Choose a new PIN/PUK mgr-choose-new-pin = Choose a new PIN/PUK
mgr-repeat-new-pin = Repeat the PIN/PUK mgr-repeat-new-pin = Repeat the PIN/PUK
mgr-pin-mismatch = PINs don't match mgr-pin-mismatch = PINs don't match
mgr-nope-default-pin = You entered the default PIN again. You need to change it.
mgr-changing-mgmt-key = mgr-changing-mgmt-key =
✨ Your {-yubikey} is using the default management key. ✨ Your {-yubikey} is using the default management key.
@@ -143,6 +155,12 @@ mgr-changing-mgmt-key-error =
{" "}{$management_key} {" "}{$management_key}
mgr-changing-mgmt-key-success = Success! mgr-changing-mgmt-key-success = Success!
## YubiKey keygen
builder-gen-key = 🎲 Generating key...
builder-gen-cert = 🔏 Generating certificate...
builder-touch-yk = 👆 Please touch the {-yubikey}
## Plugin usage ## Plugin usage
plugin-err-invalid-recipient = Invalid recipient plugin-err-invalid-recipient = Invalid recipient
@@ -169,13 +187,24 @@ plugin-err-pin-required = A PIN is required for {-yubikey} with serial {$yub
## Errors ## Errors
err-custom-mgmt-key = Custom unprotected management keys are not supported. err-mgmt-key-auth = Failed to authenticate with the PIN-protected management key.
rec-mgmt-key-auth =
Check whether your management key is using the TDES algorithm.
AES is not supported yet: {$aes_url}
err-custom-mgmt-key = Custom unprotected non-TDES management keys are not supported.
rec-change-mgmt-key =
You can use the {-yubikey} Manager CLI to change to a protected management key:
{" "}{$cmd}
See here for more information about {-yubikey} Manager:
{" "}{$url}
err-invalid-flag-command = Flag '{$flag}' cannot be used with '{$command}'. err-invalid-flag-command = Flag '{$flag}' cannot be used with '{$command}'.
err-invalid-flag-tui = Flag '{$flag}' cannot be used with the interactive interface. err-invalid-flag-tui = Flag '{$flag}' cannot be used with the interactive interface.
err-invalid-pin-length = The PIN needs to be 1-8 characters.
err-invalid-pin-policy = Invalid PIN policy '{$policy}' (expected [{$expected}]). err-invalid-pin-policy = Invalid PIN policy '{$policy}' (expected [{$expected}]).
err-invalid-slot = Invalid slot '{$slot}' (expected number between 1 and 20). err-invalid-slot = Invalid slot '{$slot}' (expected number between 1 and 20).
err-invalid-touch-policy = Invalid touch policy '{$policy}' (expected [{$expected}]). err-invalid-touch-policy = Invalid touch policy '{$policy}' (expected [{$expected}]).
err-io-user = Failed to get input from user: {$err}
err-io = Failed to set up {-yubikey}: {$err} err-io = Failed to set up {-yubikey}: {$err}
err-multiple-commands = Only one of {-cmd-generate}, {-cmd-identity}, {-cmd-list}, {-cmd-list-all} can be specified. err-multiple-commands = Only one of {-cmd-generate}, {-cmd-identity}, {-cmd-list}, {-cmd-list-all} can be specified.
err-multiple-yubikeys = Multiple {-yubikeys} are plugged in. Use {-flag-serial} to select a single {-yubikey}. err-multiple-yubikeys = Multiple {-yubikeys} are plugged in. Use {-flag-serial} to select a single {-yubikey}.
@@ -185,11 +214,38 @@ err-slot-has-no-identity = Slot {$slot} does not contain an {-age} identity or c
err-slot-is-not-empty = Slot {$slot} is not empty. Use {-flag-force} to overwrite the slot. err-slot-is-not-empty = Slot {$slot} is not empty. Use {-flag-force} to overwrite the slot.
err-timed-out = Timed out while waiting for a {-yubikey} to be inserted. err-timed-out = Timed out while waiting for a {-yubikey} to be inserted.
err-use-list-for-single = Use {-cmd-list} to print the recipient for a single slot. err-use-list-for-single = Use {-cmd-list} to print the recipient for a single slot.
err-yk-no-service-macos = The Crypto Token Kit service is not running.
rec-yk-no-service-macos =
You may need to restart it. See this Stack Exchange answer for more help:
{" "}{$url}
err-yk-no-service-pcscd = {-pcscd} is not running.
rec-yk-no-service-pcscd =
If you are on Debian or Ubuntu, you can install it with:
{" "}{$apt}
rec-yk-no-service-pcscd-bsd =
You can install and run it as root with:
{" "}{$pkg}
{" "}{$service_enable}
{" "}{$service_start}
err-yk-no-service-win = The Smart Cards for Windows service is not running.
rec-yk-no-service-win =
See this troubleshooting guide for more help:
{" "}{$url}
err-yk-not-found = Please insert the {-yubikey} you want to set up err-yk-not-found = Please insert the {-yubikey} you want to set up
err-yk-wrong-pin = Invalid PIN ({$tries} tries remaining before it is blocked)
err-yk-general = Error while communicating with {-yubikey}: {$err} err-yk-general = Error while communicating with {-yubikey}: {$err}
err-yk-general-cause = Cause: {$inner_err} err-yk-general-cause = Cause: {$inner_err}
err-yk-wrong-pin = Invalid {$pin_kind} ({$tries ->
[one] {$tries} try remaining
*[other] {$tries} tries remaining
} before it is blocked)
err-yk-pin-locked = {$pin_kind} locked
err-ux-A = Did this not do what you expected? Could an error be more useful? err-ux-A = Did this not do what you expected? Could an error be more useful?
err-ux-B = Tell us err-ux-B = Tell us
# Put (len(A) - len(B) - 46) spaces here. # Put (len(A) - len(B) - 46) spaces here.
-1
View File
@@ -1 +0,0 @@
1.56.0
+3
View File
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.67.0"
components = ["clippy", "rustfmt"]
+26 -14
View File
@@ -1,13 +1,15 @@
use dialoguer::Password;
use rand::{rngs::OsRng, RngCore}; use rand::{rngs::OsRng, RngCore};
use x509::RelativeDistinguishedName; use x509::RelativeDistinguishedName;
use yubikey::{ use yubikey::{
certificate::{Certificate, PublicKeyInfo}, certificate::Certificate,
piv::{generate as yubikey_generate, AlgorithmId, RetiredSlotId, SlotId}, piv::{generate as yubikey_generate, AlgorithmId, RetiredSlotId, SlotId},
Key, PinPolicy, TouchPolicy, YubiKey, Key, PinPolicy, TouchPolicy, YubiKey,
}; };
use crate::{ use crate::{
error::Error, error::Error,
fl,
key::{self, Stub}, key::{self, Stub},
p256::Recipient, p256::Recipient,
util::{Metadata, POLICY_EXTENSION_OID}, util::{Metadata, POLICY_EXTENSION_OID},
@@ -86,17 +88,13 @@ impl IdentityBuilder {
let pin_policy = self.pin_policy.unwrap_or(DEFAULT_PIN_POLICY); let pin_policy = self.pin_policy.unwrap_or(DEFAULT_PIN_POLICY);
let touch_policy = self.touch_policy.unwrap_or(DEFAULT_TOUCH_POLICY); let touch_policy = self.touch_policy.unwrap_or(DEFAULT_TOUCH_POLICY);
eprintln!("{}", fl!("builder-gen-key"));
// No need to ask for users to enter their PIN if the PIN policy requires it, // No need to ask for users to enter their PIN if the PIN policy requires it,
// because here we _always_ require them to enter their PIN in order to access the // because here we _always_ require them to enter their PIN in order to access the
// protected management key (which is necessary in order to generate identities). // protected management key (which is necessary in order to generate identities).
key::manage(yubikey)?; key::manage(yubikey)?;
if let TouchPolicy::Never = touch_policy {
// No need to touch YubiKey
} else {
eprintln!("👆 Please touch the YubiKey");
}
// Generate a new key in the selected slot. // Generate a new key in the selected slot.
let generated = yubikey_generate( let generated = yubikey_generate(
yubikey, yubikey,
@@ -106,14 +104,12 @@ impl IdentityBuilder {
touch_policy, touch_policy,
)?; )?;
let recipient = match &generated { let recipient = Recipient::from_spki(&generated).expect("YubiKey generates a valid pubkey");
PublicKeyInfo::EcP256(pubkey) => {
Recipient::from_encoded(pubkey).expect("YubiKey generates a valid pubkey")
}
_ => unreachable!(),
};
let stub = Stub::new(yubikey.serial(), slot, &recipient); let stub = Stub::new(yubikey.serial(), slot, &recipient);
eprintln!();
eprintln!("{}", fl!("builder-gen-cert"));
// Pick a random serial for the new self-signed certificate. // Pick a random serial for the new self-signed certificate.
let mut serial = [0; 20]; let mut serial = [0; 20];
OsRng.fill_bytes(&mut serial); OsRng.fill_bytes(&mut serial);
@@ -122,6 +118,23 @@ impl IdentityBuilder {
.name .name
.unwrap_or(format!("age identity {}", hex::encode(stub.tag))); .unwrap_or(format!("age identity {}", hex::encode(stub.tag)));
if let PinPolicy::Always = pin_policy {
// We need to enter the PIN again.
let pin = Password::new()
.with_prompt(fl!(
"plugin-enter-pin",
yubikey_serial = yubikey.serial().to_string(),
))
.report(true)
.interact()?;
yubikey.verify_pin(pin.as_bytes())?;
}
if let TouchPolicy::Never = touch_policy {
// No need to touch YubiKey
} else {
eprintln!("{}", fl!("builder-touch-yk"));
}
let cert = Certificate::generate_self_signed( let cert = Certificate::generate_self_signed(
yubikey, yubikey,
SlotId::Retired(slot), SlotId::Retired(slot),
@@ -139,7 +152,6 @@ impl IdentityBuilder {
)], )],
)?; )?;
let (_, cert) = x509_parser::parse_x509_certificate(cert.as_ref()).unwrap();
let metadata = Metadata::extract(yubikey, slot, &cert, false).unwrap(); let metadata = Metadata::extract(yubikey, slot, &cert, false).unwrap();
Ok(( Ok((
+105 -95
View File
@@ -1,4 +1,3 @@
use i18n_embed_fl::fl;
use std::fmt; use std::fmt;
use std::io; use std::io;
use yubikey::{piv::RetiredSlotId, Serial}; use yubikey::{piv::RetiredSlotId, Serial};
@@ -9,28 +8,40 @@ macro_rules! wlnfl {
($f:ident, $message_id:literal) => { ($f:ident, $message_id:literal) => {
writeln!($f, "{}", $crate::fl!($message_id)) writeln!($f, "{}", $crate::fl!($message_id))
}; };
($f:ident, $message_id:literal, $($kwarg:expr),* $(,)*) => {{
writeln!($f, "{}", $crate::fl!($message_id, $($kwarg,)*))
}};
} }
pub enum Error { pub enum Error {
CustomManagementKey, CustomManagementKey,
Dialog(dialoguer::Error),
InvalidFlagCommand(String, String), InvalidFlagCommand(String, String),
InvalidFlagTui(String), InvalidFlagTui(String),
InvalidPinLength,
InvalidPinPolicy(String), InvalidPinPolicy(String),
InvalidSlot(u8), InvalidSlot(u8),
InvalidTouchPolicy(String), InvalidTouchPolicy(String),
Io(io::Error), Io(io::Error),
ManagementKeyAuth,
MultipleCommands, MultipleCommands,
MultipleYubiKeys, MultipleYubiKeys,
NoEmptySlots(Serial), NoEmptySlots(Serial),
NoMatchingSerial(Serial), NoMatchingSerial(Serial),
PukLocked,
SlotHasNoIdentity(RetiredSlotId), SlotHasNoIdentity(RetiredSlotId),
SlotIsNotEmpty(RetiredSlotId), SlotIsNotEmpty(RetiredSlotId),
TimedOut, TimedOut,
UseListForSingleSlot, UseListForSingleSlot,
WrongPuk(u8),
YubiKey(yubikey::Error), YubiKey(yubikey::Error),
} }
impl From<dialoguer::Error> for Error {
fn from(e: dialoguer::Error) -> Self {
Error::Dialog(e)
}
}
impl From<io::Error> for Error { impl From<io::Error> for Error {
fn from(e: io::Error) -> Self { fn from(e: io::Error) -> Self {
Error::Io(e) Error::Io(e)
@@ -47,126 +58,125 @@ impl From<yubikey::Error> for Error {
// manually to provide the error output we want. // manually to provide the error output we want.
impl fmt::Debug for Error { impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
const CHANGE_MGMT_KEY_CMD: &str =
"ykman piv access change-management-key -a TDES --protect";
const CHANGE_MGMT_KEY_URL: &str = "https://developers.yubico.com/yubikey-manager/";
match self { match self {
Error::CustomManagementKey => wlnfl!(f, "err-custom-mgmt-key")?, Error::CustomManagementKey => {
Error::InvalidFlagCommand(flag, command) => writeln!( wlnfl!(f, "err-custom-mgmt-key")?;
wlnfl!(
f,
"rec-change-mgmt-key",
cmd = CHANGE_MGMT_KEY_CMD,
url = CHANGE_MGMT_KEY_URL
)?;
}
Error::Dialog(e) => wlnfl!(f, "err-io-user", err = e.to_string())?,
Error::InvalidFlagCommand(flag, command) => wlnfl!(
f, f,
"{}",
fl!(
crate::LANGUAGE_LOADER,
"err-invalid-flag-command", "err-invalid-flag-command",
flag = flag.as_str(), flag = flag.as_str(),
command = command.as_str(), command = command.as_str(),
),
)?, )?,
Error::InvalidFlagTui(flag) => writeln!( Error::InvalidFlagTui(flag) => wlnfl!(f, "err-invalid-flag-tui", flag = flag.as_str())?,
Error::InvalidPinPolicy(s) => wlnfl!(
f, f,
"{}",
fl!(
crate::LANGUAGE_LOADER,
"err-invalid-flag-tui",
flag = flag.as_str(),
),
)?,
Error::InvalidPinLength => wlnfl!(f, "err-invalid-pin-length")?,
Error::InvalidPinPolicy(s) => writeln!(
f,
"{}",
fl!(
crate::LANGUAGE_LOADER,
"err-invalid-pin-policy", "err-invalid-pin-policy",
policy = s.as_str(), policy = s.as_str(),
expected = "always, once, never", expected = "always, once, never",
),
)?, )?,
Error::InvalidSlot(slot) => writeln!( Error::InvalidSlot(slot) => wlnfl!(f, "err-invalid-slot", slot = slot)?,
Error::InvalidTouchPolicy(s) => wlnfl!(
f, f,
"{}",
fl!(crate::LANGUAGE_LOADER, "err-invalid-slot", slot = slot),
)?,
Error::InvalidTouchPolicy(s) => writeln!(
f,
"{}",
fl!(
crate::LANGUAGE_LOADER,
"err-invalid-touch-policy", "err-invalid-touch-policy",
policy = s.as_str(), policy = s.as_str(),
expected = "always, cached, never", expected = "always, cached, never",
),
)?, )?,
Error::Io(e) => writeln!( Error::Io(e) => wlnfl!(f, "err-io", err = e.to_string())?,
Error::ManagementKeyAuth => {
let aes_url = "https://github.com/str4d/age-plugin-yubikey/issues/92";
wlnfl!(f, "err-mgmt-key-auth")?;
wlnfl!(f, "rec-mgmt-key-auth", aes_url = aes_url)?;
wlnfl!(
f, f,
"{}", "rec-change-mgmt-key",
fl!(crate::LANGUAGE_LOADER, "err-io", err = e.to_string()), cmd = CHANGE_MGMT_KEY_CMD,
)?, url = CHANGE_MGMT_KEY_URL
)?;
}
Error::MultipleCommands => wlnfl!(f, "err-multiple-commands")?, Error::MultipleCommands => wlnfl!(f, "err-multiple-commands")?,
Error::MultipleYubiKeys => wlnfl!(f, "err-multiple-yubikeys")?, Error::MultipleYubiKeys => wlnfl!(f, "err-multiple-yubikeys")?,
Error::NoEmptySlots(serial) => writeln!( Error::NoEmptySlots(serial) => {
f, wlnfl!(f, "err-no-empty-slots", serial = serial.to_string())?
"{}", }
fl!( Error::NoMatchingSerial(serial) => {
crate::LANGUAGE_LOADER, wlnfl!(f, "err-no-matching-serial", serial = serial.to_string())?
"err-no-empty-slots", }
serial = serial.to_string(), Error::PukLocked => wlnfl!(f, "err-yk-pin-locked", pin_kind = "PUK")?,
), Error::SlotHasNoIdentity(slot) => {
)?, wlnfl!(f, "err-slot-has-no-identity", slot = slot_to_ui(slot))?
Error::NoMatchingSerial(serial) => writeln!( }
f, Error::SlotIsNotEmpty(slot) => {
"{}", wlnfl!(f, "err-slot-is-not-empty", slot = slot_to_ui(slot))?
fl!( }
crate::LANGUAGE_LOADER,
"err-no-matching-serial",
serial = serial.to_string(),
),
)?,
Error::SlotHasNoIdentity(slot) => writeln!(
f,
"{}",
fl!(
crate::LANGUAGE_LOADER,
"err-slot-has-no-identity",
slot = slot_to_ui(slot),
),
)?,
Error::SlotIsNotEmpty(slot) => writeln!(
f,
"{}",
fl!(
crate::LANGUAGE_LOADER,
"err-slot-is-not-empty",
slot = slot_to_ui(slot),
),
)?,
Error::TimedOut => wlnfl!(f, "err-timed-out")?, Error::TimedOut => wlnfl!(f, "err-timed-out")?,
Error::UseListForSingleSlot => wlnfl!(f, "err-use-list-for-single")?, Error::UseListForSingleSlot => wlnfl!(f, "err-use-list-for-single")?,
Error::WrongPuk(tries) => {
wlnfl!(f, "err-yk-wrong-pin", pin_kind = "PUK", tries = tries)?
}
Error::YubiKey(e) => match e { Error::YubiKey(e) => match e {
yubikey::Error::NotFound => wlnfl!(f, "err-yk-not-found")?, yubikey::Error::NotFound => wlnfl!(f, "err-yk-not-found")?,
yubikey::Error::WrongPin { tries } => writeln!( yubikey::Error::PcscError {
inner: Some(pcsc::Error::NoService),
} => {
if cfg!(windows) {
wlnfl!(f, "err-yk-no-service-win")?;
let url = "https://learn.microsoft.com/en-us/windows/security/identity-protection/smart-cards/smart-card-debugging-information#smart-card-service";
wlnfl!(f, "rec-yk-no-service-win", url = url)?;
} else if cfg!(target_os = "macos") {
wlnfl!(f, "err-yk-no-service-macos")?;
let url = "https://apple.stackexchange.com/a/438198";
wlnfl!(f, "rec-yk-no-service-macos", url = url)?;
} else if cfg!(target_os = "openbsd") {
wlnfl!(f, "err-yk-no-service-pcscd")?;
let pkg = "pkg_add pcsc-lite ccid";
let service_enable = "rcctl enable pcscd";
let service_start = "rcctl start pcscd";
wlnfl!(
f, f,
"{}", "rec-yk-no-service-pcscd-bsd",
fl!(crate::LANGUAGE_LOADER, "err-yk-wrong-pin", tries = tries), pkg = pkg,
)?, service_enable = service_enable,
e => { service_start = service_start
writeln!(
f,
"{}",
fl!(
crate::LANGUAGE_LOADER,
"err-yk-general",
err = e.to_string(),
),
)?; )?;
} else if cfg!(target_os = "freebsd") {
wlnfl!(f, "err-yk-no-service-pcscd")?;
let pkg = "pkg install pcsc-lite libccid";
let service_enable = "service pcscd enable";
let service_start = "service pcscd start";
wlnfl!(
f,
"rec-yk-no-service-pcscd-bsd",
pkg = pkg,
service_enable = service_enable,
service_start = service_start
)?;
} else {
wlnfl!(f, "err-yk-no-service-pcscd")?;
let apt = "sudo apt-get install pcscd";
wlnfl!(f, "rec-yk-no-service-pcscd", apt = apt)?;
}
}
yubikey::Error::PinLocked => wlnfl!(f, "err-yk-pin-locked", pin_kind = "PIN")?,
yubikey::Error::WrongPin { tries } => {
wlnfl!(f, "err-yk-wrong-pin", pin_kind = "PIN", tries = tries)?
}
e => {
wlnfl!(f, "err-yk-general", err = e.to_string())?;
use std::error::Error; use std::error::Error;
if let Some(inner) = e.source() { if let Some(inner) = e.source() {
writeln!( wlnfl!(f, "err-yk-general-cause", inner_err = inner.to_string())?;
f,
"{}",
fl!(
crate::LANGUAGE_LOADER,
"err-yk-general-cause",
inner_err = inner.to_string(),
),
)?;
} }
} }
}, },
+30 -13
View File
@@ -1,10 +1,15 @@
use age_core::{ use age_core::{
format::{FileKey, Stanza}, format::{FileKey, Stanza},
primitives::{aead_encrypt, hkdf}, primitives::aead_encrypt,
secrecy::ExposeSecret, secrecy::ExposeSecret,
}; };
use p256::{ecdh::EphemeralSecret, elliptic_curve::sec1::ToEncodedPoint}; use base64::{prelude::BASE64_STANDARD_NO_PAD, Engine};
use p256::{
ecdh::EphemeralSecret,
elliptic_curve::sec1::{FromEncodedPoint, ToEncodedPoint},
};
use rand::rngs::OsRng; use rand::rngs::OsRng;
use sha2::Sha256;
use crate::{p256::Recipient, STANZA_TAG}; use crate::{p256::Recipient, STANZA_TAG};
@@ -22,8 +27,12 @@ pub(crate) struct EphemeralKeyBytes(p256::EncodedPoint);
impl EphemeralKeyBytes { impl EphemeralKeyBytes {
fn from_bytes(bytes: [u8; EPK_BYTES]) -> Option<Self> { fn from_bytes(bytes: [u8; EPK_BYTES]) -> Option<Self> {
let encoded = p256::EncodedPoint::from_bytes(&bytes).ok()?; let encoded = p256::EncodedPoint::from_bytes(bytes).ok()?;
if encoded.is_compressed() && encoded.decompress().is_some() { if encoded.is_compressed()
&& p256::PublicKey::from_encoded_point(&encoded)
.is_some()
.into()
{
Some(EphemeralKeyBytes(encoded)) Some(EphemeralKeyBytes(encoded))
} else { } else {
None None
@@ -39,9 +48,9 @@ impl EphemeralKeyBytes {
} }
pub(crate) fn decompress(&self) -> p256::EncodedPoint { pub(crate) fn decompress(&self) -> p256::EncodedPoint {
self.0 // EphemeralKeyBytes is a valid compressed encoding by construction.
.decompress() let p = p256::PublicKey::from_encoded_point(&self.0).unwrap();
.expect("EphemeralKeyBytes is a valid compressed encoding by construction") p.to_encoded_point(false)
} }
} }
@@ -57,8 +66,8 @@ impl From<RecipientLine> for Stanza {
Stanza { Stanza {
tag: STANZA_TAG.to_owned(), tag: STANZA_TAG.to_owned(),
args: vec![ args: vec![
base64::encode_config(&r.tag, base64::STANDARD_NO_PAD), BASE64_STANDARD_NO_PAD.encode(r.tag),
base64::encode_config(r.epk_bytes.as_bytes(), base64::STANDARD_NO_PAD), BASE64_STANDARD_NO_PAD.encode(r.epk_bytes.as_bytes()),
], ],
body: r.encrypted_file_key.to_vec(), body: r.encrypted_file_key.to_vec(),
} }
@@ -76,9 +85,10 @@ impl RecipientLine {
return None; return None;
} }
base64::decode_config_slice(arg, base64::STANDARD_NO_PAD, buf.as_mut()) BASE64_STANDARD_NO_PAD
.decode_slice_unchecked(arg, buf.as_mut())
.ok() .ok()
.map(|_| buf) .and_then(|len| (len == buf.as_mut().len()).then_some(buf))
} }
let (tag, epk_bytes) = match &s.args[..] { let (tag, epk_bytes) = match &s.args[..] {
@@ -101,7 +111,7 @@ impl RecipientLine {
} }
pub(crate) fn wrap_file_key(file_key: &FileKey, pk: &Recipient) -> Self { pub(crate) fn wrap_file_key(file_key: &FileKey, pk: &Recipient) -> Self {
let esk = EphemeralSecret::random(OsRng); let esk = EphemeralSecret::random(&mut OsRng);
let epk = esk.public_key(); let epk = esk.public_key();
let epk_bytes = EphemeralKeyBytes::from_public_key(&epk); let epk_bytes = EphemeralKeyBytes::from_public_key(&epk);
@@ -111,7 +121,14 @@ impl RecipientLine {
salt.extend_from_slice(epk_bytes.as_bytes()); salt.extend_from_slice(epk_bytes.as_bytes());
salt.extend_from_slice(pk.to_encoded().as_bytes()); salt.extend_from_slice(pk.to_encoded().as_bytes());
let enc_key = hkdf(&salt, STANZA_KEY_LABEL, shared_secret.as_bytes()); let enc_key = {
let mut okm = [0; 32];
shared_secret
.extract::<Sha256>(Some(&salt))
.expand(STANZA_KEY_LABEL, &mut okm)
.expect("okm is the correct length");
okm
};
let encrypted_file_key = { let encrypted_file_key = {
let mut key = [0; ENCRYPTED_FILE_KEY_BYTES]; let mut key = [0; ENCRYPTED_FILE_KEY_BYTES];
+332 -101
View File
@@ -3,22 +3,24 @@
use age_core::{ use age_core::{
format::{FileKey, FILE_KEY_BYTES}, format::{FileKey, FILE_KEY_BYTES},
primitives::{aead_decrypt, hkdf}, primitives::{aead_decrypt, hkdf},
secrecy::ExposeSecret, secrecy::{ExposeSecret, SecretString},
}; };
use age_plugin::{identity, Callbacks}; use age_plugin::{identity, Callbacks};
use bech32::{ToBase32, Variant}; use bech32::{ToBase32, Variant};
use dialoguer::Password; use dialoguer::Password;
use log::warn; use log::{debug, error, warn};
use std::convert::Infallible;
use std::fmt; use std::fmt;
use std::io; use std::io;
use std::iter; use std::iter;
use std::thread::sleep; use std::thread::sleep;
use std::time::{Duration, Instant, SystemTime}; use std::time::{Duration, Instant, SystemTime};
use x509_parser::der_parser::oid::Oid;
use yubikey::{ use yubikey::{
certificate::{Certificate, PublicKeyInfo}, certificate::Certificate,
piv::{decrypt_data, AlgorithmId, RetiredSlotId, SlotId}, piv::{decrypt_data, AlgorithmId, RetiredSlotId, SlotId},
reader::{Context, Reader}, reader::{Context, Reader},
MgmKey, PinPolicy, Serial, TouchPolicy, YubiKey, Key, MgmKey, PinPolicy, Serial, TouchPolicy, YubiKey,
}; };
use crate::{ use crate::{
@@ -26,37 +28,48 @@ use crate::{
fl, fl,
format::{RecipientLine, STANZA_KEY_LABEL}, format::{RecipientLine, STANZA_KEY_LABEL},
p256::{Recipient, TAG_BYTES}, p256::{Recipient, TAG_BYTES},
util::{otp_serial_prefix, Metadata}, util::{otp_serial_prefix, Metadata, POLICY_EXTENSION_OID},
IDENTITY_PREFIX, IDENTITY_PREFIX,
}; };
const ONE_SECOND: Duration = Duration::from_secs(1); const ONE_SECOND: Duration = Duration::from_secs(1);
const FIFTEEN_SECONDS: Duration = Duration::from_secs(15); const FIFTEEN_SECONDS: Duration = Duration::from_secs(15);
/// The set of OIDs that we understand and use when parsing YubiKey slot certificates.
const KNOWN_OIDS: &[&[u64]] = &[POLICY_EXTENSION_OID];
pub(crate) fn is_connected(reader: Reader) -> bool { pub(crate) fn is_connected(reader: Reader) -> bool {
filter_connected(&reader) filter_connected(&reader)
} }
pub(crate) fn filter_connected(reader: &Reader) -> bool { pub(crate) fn filter_connected(reader: &Reader) -> bool {
match reader.open() { match reader.open() {
Ok(_) => true, Err(yubikey::Error::PcscError {
Err(e) => { inner: Some(pcsc::Error::NoSmartcard | pcsc::Error::RemovedCard),
use std::error::Error; }) => {
if let Some(pcsc::Error::RemovedCard) =
e.source().and_then(|inner| inner.downcast_ref())
{
warn!( warn!(
"{}", "{}",
i18n_embed_fl::fl!( fl!("warn-yk-not-connected", yubikey_name = reader.name())
crate::LANGUAGE_LOADER,
"warn-yk-not-connected",
yubikey_name = reader.name(),
)
); );
false false
} else {
true
} }
Err(yubikey::Error::AppletNotFound { applet_name }) => {
warn!(
"{}",
fl!(
"warn-yk-missing-applet",
yubikey_name = reader.name(),
applet_name = applet_name,
),
);
false
}
Err(_) => true,
Ok(yubikey) => {
// We only connected as a side-effect of confirming that we can connect, so
// avoid resetting the YubiKey.
disconnect_without_reset(yubikey);
true
} }
} }
} }
@@ -77,16 +90,139 @@ pub(crate) fn wait_for_readers() -> Result<Context, Error> {
} }
} }
/// Looks for agent processes that might be holding exclusive access to a YubiKey, and
/// asks them as nicely as possible to release it.
///
/// Returns `true` if any known agent was running and was successfully interrupted (or
/// killed if the platform doesn't support interrupts).
fn hunt_agents() -> bool {
debug!("Sharing violation encountered, looking for agent processes");
use sysinfo::{ProcessExt, ProcessRefreshKind, RefreshKind, Signal, System, SystemExt};
let mut interrupted = false;
let sys =
System::new_with_specifics(RefreshKind::new().with_processes(ProcessRefreshKind::new()));
for process in sys.processes().values() {
match process.name() {
"scdaemon" | "scdaemon.exe" => {
// gpg-agent runs scdaemon to interact with smart cards. The canonical way
// to reload it is `gpgconf --reload scdaemon`, which kills and restarts
// the process. We emulate that here with SIGINT (which it listens to).
if process
.kill_with(Signal::Interrupt)
.unwrap_or_else(|| process.kill())
{
debug!("Stopped scdaemon (PID {})", process.pid());
interrupted = true;
}
}
"yubikey-agent" | "yubikey-agent.exe" => {
// yubikey-agent releases all YubiKey locks when it receives a SIGHUP.
match process.kill_with(Signal::Hangup) {
Some(true) => {
debug!("Sent SIGHUP to yubikey-agent (PID {})", process.pid());
interrupted = true;
}
Some(false) => (),
None => debug!(
"Found yubikey-agent (PID {}) but platform doesn't support SIGHUP",
process.pid(),
),
}
}
_ => (),
}
}
// If we did interrupt an agent, pause briefly to allow it to finish up.
if interrupted {
sleep(Duration::from_millis(100));
}
interrupted
}
fn open_sesame(
op: impl Fn() -> Result<YubiKey, yubikey::Error>,
) -> Result<YubiKey, yubikey::Error> {
op().or_else(|e| match e {
yubikey::Error::PcscError {
inner: Some(pcsc::Error::SharingViolation),
} if hunt_agents() => op(),
_ => Err(e),
})
}
/// Opens a connection to this reader, returning a `YubiKey` if successful.
///
/// This is equivalent to [`Reader::open`], but additionally handles the presence of
/// agents (which can indefinitely hold exclusive access to a YubiKey).
pub(crate) fn open_connection(reader: &Reader) -> Result<YubiKey, yubikey::Error> {
open_sesame(|| reader.open())
}
/// Opens a YubiKey with a specific serial number.
///
/// This is equivalent to [`YubiKey::open_by_serial`], but additionally handles the
/// presence of agents (which can indefinitely hold exclusive access to a YubiKey).
fn open_by_serial(serial: Serial) -> Result<YubiKey, yubikey::Error> {
// `YubiKey::open_by_serial` has a bug where it ignores all opening errors, even if
// it potentially could have found a matching YubiKey if not for an error, and thus
// returns `Error::NotFound` if another agent is holding exclusive access to the
// required YubiKey. This gives misleading UX behaviour where age-plugin-yubikey asks
// the user to insert a YubiKey they have already inserted.
//
// For now, we instead implement the correct behaviour manually. Once MSRV has been
// raised to 1.60, we can upstream this into the `yubikey` crate.
open_sesame(|| {
let mut readers = Context::open()?;
let mut open_error = None;
for reader in readers.iter()? {
let yubikey = match reader.open() {
Ok(yk) => yk,
Err(e) => {
// Save the first error we see that indicates we might have been able
// to find a matching YubiKey.
if open_error.is_none() {
if let yubikey::Error::PcscError {
inner: Some(pcsc::Error::SharingViolation),
} = e
{
open_error = Some(e);
}
}
continue;
}
};
if serial == yubikey.serial() {
return Ok(yubikey);
} else {
// We didn't want this YubiKey; don't reset it.
disconnect_without_reset(yubikey);
}
}
Err(if let Some(e) = open_error {
e
} else {
error!("no YubiKey detected with serial: {}", serial);
yubikey::Error::NotFound
})
})
}
pub(crate) fn open(serial: Option<Serial>) -> Result<YubiKey, Error> { pub(crate) fn open(serial: Option<Serial>) -> Result<YubiKey, Error> {
if !Context::open()?.iter()?.any(is_connected) { if !Context::open()?.iter()?.any(is_connected) {
if let Some(serial) = serial { if let Some(serial) = serial {
eprintln!( eprintln!(
"{}", "{}",
i18n_embed_fl::fl!( fl!("open-yk-with-serial", yubikey_serial = serial.to_string())
crate::LANGUAGE_LOADER,
"open-yk-with-serial",
yubikey_serial = serial.to_string(),
)
); );
} else { } else {
eprintln!("{}", fl!("open-yk-without-serial")); eprintln!("{}", fl!("open-yk-without-serial"));
@@ -99,9 +235,9 @@ pub(crate) fn open(serial: Option<Serial>) -> Result<YubiKey, Error> {
// connected, an error is returned. // connected, an error is returned.
let yubikey = match (readers_iter.next(), readers_iter.next(), serial) { let yubikey = match (readers_iter.next(), readers_iter.next(), serial) {
(None, _, _) => unreachable!(), (None, _, _) => unreachable!(),
(Some(reader), None, None) => reader.open()?, (Some(reader), None, None) => open_connection(&reader)?,
(Some(reader), None, Some(serial)) => { (Some(reader), None, Some(serial)) => {
let yubikey = reader.open()?; let yubikey = open_connection(&reader)?;
if yubikey.serial() != serial { if yubikey.serial() != serial {
return Err(Error::NoMatchingSerial(serial)); return Err(Error::NoMatchingSerial(serial));
} }
@@ -112,12 +248,12 @@ pub(crate) fn open(serial: Option<Serial>) -> Result<YubiKey, Error> {
.chain(Some(a)) .chain(Some(a))
.chain(Some(b)) .chain(Some(b))
.chain(readers_iter) .chain(readers_iter)
.find(|reader| match reader.open() { .find(|reader| match open_connection(reader) {
Ok(yk) => yk.serial() == serial, Ok(yk) => yk.serial() == serial,
_ => false, _ => false,
}) })
.ok_or(Error::NoMatchingSerial(serial))?; .ok_or(Error::NoMatchingSerial(serial))?;
reader.open()? open_connection(&reader)?
} }
(Some(_), Some(_), None) => return Err(Error::MultipleYubiKeys), (Some(_), Some(_), None) => return Err(Error::MultipleYubiKeys),
}; };
@@ -125,18 +261,60 @@ pub(crate) fn open(serial: Option<Serial>) -> Result<YubiKey, Error> {
Ok(yubikey) Ok(yubikey)
} }
/// Disconnect from the YubiKey without resetting it.
///
/// This can be used to preserve the YubiKey's PIN and touch caches. There are two cases
/// where we want to do this:
///
/// - We connected to this YubiKey in a read-only context, so we have not made any changes
/// to the YubiKey's state. However, we might have asked an agent to release the YubiKey
/// in `key::open_connection`, and we want to allow any state it may have left behind
/// (such as cached PINs or touches) to persist beyond our execution, for usability.
/// - We opened this connection in a decryption context, so the only changes to the
/// YubiKey's state were to potentially cache the PIN and/or touch (depending on the
/// policies of the slot). We want to allow these to persist beyond our execution, for
/// usability.
pub(crate) fn disconnect_without_reset(yubikey: YubiKey) {
let _ = yubikey.disconnect(pcsc::Disposition::LeaveCard);
}
fn request_pin<E, E2>(
mut prompt: impl FnMut(Option<String>) -> Result<Result<SecretString, E>, E2>,
serial: Serial,
) -> Result<Result<SecretString, E>, E2> {
let mut prev_error = None;
loop {
prev_error = Some(match prompt(prev_error)? {
Ok(pin) => match pin.expose_secret().len() {
// A PIN must be between 6 and 8 characters.
6..=8 => break Ok(Ok(pin)),
// If the string is 44 bytes and starts with the YubiKey's serial
// encoded as 12-byte modhex, the user probably touched the YubiKey
// early and "typed" an OTP.
44 if pin.expose_secret().starts_with(&otp_serial_prefix(serial)) => {
fl!("plugin-err-accidental-touch")
}
// Otherwise, the PIN is either too short or too long.
0..=5 => fl!("plugin-err-pin-too-short"),
_ => fl!("plugin-err-pin-too-long"),
},
Err(e) => break Ok(Err(e)),
});
}
}
pub(crate) fn manage(yubikey: &mut YubiKey) -> Result<(), Error> { pub(crate) fn manage(yubikey: &mut YubiKey) -> Result<(), Error> {
const DEFAULT_PIN: &str = "123456"; const DEFAULT_PIN: &str = "123456";
const DEFAULT_PUK: &str = "12345678"; const DEFAULT_PUK: &str = "12345678";
eprintln!(); eprintln!();
let pin = Password::new() let pin = Password::new()
.with_prompt(i18n_embed_fl::fl!( .with_prompt(fl!(
crate::LANGUAGE_LOADER,
"mgr-enter-pin", "mgr-enter-pin",
yubikey_serial = yubikey.serial().to_string(), yubikey_serial = yubikey.serial().to_string(),
default_pin = DEFAULT_PIN, default_pin = DEFAULT_PIN,
)) ))
.report(true)
.interact()?; .interact()?;
yubikey.verify_pin(pin.as_bytes())?; yubikey.verify_pin(pin.as_bytes())?;
@@ -146,26 +324,47 @@ pub(crate) fn manage(yubikey: &mut YubiKey) -> Result<(), Error> {
eprintln!("{}", fl!("mgr-change-default-pin")); eprintln!("{}", fl!("mgr-change-default-pin"));
eprintln!(); eprintln!();
let current_puk = Password::new() let current_puk = Password::new()
.with_prompt(i18n_embed_fl::fl!( .with_prompt(fl!("mgr-enter-current-puk", default_puk = DEFAULT_PUK))
crate::LANGUAGE_LOADER,
"mgr-enter-current-puk",
default_puk = DEFAULT_PUK,
))
.interact()?; .interact()?;
let new_pin = Password::new() let new_pin = loop {
let pin = request_pin(
|prev_error| {
if let Some(err) = prev_error {
eprintln!("{err}");
}
Password::new()
.with_prompt(fl!("mgr-choose-new-pin")) .with_prompt(fl!("mgr-choose-new-pin"))
.with_confirmation(fl!("mgr-repeat-new-pin"), fl!("mgr-pin-mismatch")) .with_confirmation(fl!("mgr-repeat-new-pin"), fl!("mgr-pin-mismatch"))
.interact()?; .interact()
if new_pin.len() > 8 { .map(|pin| Result::<_, Infallible>::Ok(SecretString::new(pin)))
return Err(Error::InvalidPinLength); },
yubikey.serial(),
)?
.unwrap();
if pin.expose_secret() == DEFAULT_PIN {
eprintln!("{}", fl!("mgr-nope-default-pin"));
} else {
break pin;
} }
yubikey.change_puk(current_puk.as_bytes(), new_pin.as_bytes())?; };
let new_pin = new_pin.expose_secret();
yubikey
.change_puk(current_puk.as_bytes(), new_pin.as_bytes())
.map_err(|e| match e {
yubikey::Error::PinLocked => Error::PukLocked,
yubikey::Error::WrongPin { tries } => Error::WrongPuk(tries),
_ => Error::YubiKey(e),
})?;
yubikey.change_pin(pin.as_bytes(), new_pin.as_bytes())?; yubikey.change_pin(pin.as_bytes(), new_pin.as_bytes())?;
} }
if let Ok(mgm_key) = MgmKey::get_protected(yubikey) { match MgmKey::get_protected(yubikey) {
yubikey.authenticate(mgm_key)?; Ok(mgm_key) => yubikey.authenticate(mgm_key).map_err(|e| match e {
} else { yubikey::Error::AuthenticationError => Error::ManagementKeyAuth,
_ => e.into(),
})?,
Err(yubikey::Error::AuthenticationError) => Err(Error::ManagementKeyAuth)?,
_ => {
// Try to authenticate with the default management key. // Try to authenticate with the default management key.
yubikey yubikey
.authenticate(MgmKey::default()) .authenticate(MgmKey::default())
@@ -179,8 +378,7 @@ pub(crate) fn manage(yubikey: &mut YubiKey) -> Result<(), Error> {
mgm_key.set_protected(yubikey).map_err(|e| { mgm_key.set_protected(yubikey).map_err(|e| {
eprintln!( eprintln!(
"{}", "{}",
i18n_embed_fl::fl!( fl!(
crate::LANGUAGE_LOADER,
"mgr-changing-mgmt-key-error", "mgr-changing-mgmt-key-error",
management_key = hex::encode(mgm_key.as_ref()), management_key = hex::encode(mgm_key.as_ref()),
) )
@@ -189,10 +387,60 @@ pub(crate) fn manage(yubikey: &mut YubiKey) -> Result<(), Error> {
})?; })?;
eprintln!("{}", fl!("mgr-changing-mgmt-key-success")); eprintln!("{}", fl!("mgr-changing-mgmt-key-success"));
} }
}
Ok(()) Ok(())
} }
/// Parses the certificate to identify the preferred recipient type it corresponds to.
pub(crate) fn identify_recipient(cert: &Certificate) -> Option<Recipient> {
let known_oids = KNOWN_OIDS
.iter()
.map(|oid| Oid::from(oid).unwrap())
.collect::<Vec<_>>();
// If the certificate contains any unrecognised critical extensions, reject it: we
// don't know how to correctly use the identity. In particular, some identities store
// parts of their private key material in certificate extensions to work around
// hardware limitations. Not understanding these extensions could lead to encrypting
// with the wrong protocol and violating security assumptions.
let (_, c) = x509_parser::parse_x509_certificate(cert.as_ref()).ok()?;
if c.tbs_certificate
.extensions()
.iter()
.any(|ext| ext.critical && !known_oids.contains(&ext.oid))
{
return None;
}
Recipient::from_certificate(cert)
}
/// Returns an iterator of keys that are occupying plugin-compatible slots, along with the
/// corresponding recipient if the key is compatible with this plugin.
pub(crate) fn list_slots(
yubikey: &mut YubiKey,
) -> Result<impl Iterator<Item = (Key, RetiredSlotId, Option<Recipient>)>, Error> {
Ok(Key::list(yubikey)?.into_iter().filter_map(|key| {
// We only use the retired slots.
match key.slot() {
SlotId::Retired(slot) => {
let recipient = identify_recipient(key.certificate());
Some((key, slot, recipient))
}
_ => None,
}
}))
}
/// Returns an iterator of keys that are compatible with this plugin.
pub(crate) fn list_compatible(
yubikey: &mut YubiKey,
) -> Result<impl Iterator<Item = (Key, RetiredSlotId, Recipient)>, Error> {
list_slots(yubikey)
.map(|iter| iter.filter_map(|(key, slot, res)| res.map(|recipient| (key, slot, recipient))))
}
/// A reference to an age key stored in a YubiKey. /// A reference to an age key stored in a YubiKey.
#[derive(Debug)] #[derive(Debug)]
pub struct Stub { pub struct Stub {
@@ -272,14 +520,10 @@ impl Stub {
&self, &self,
callbacks: &mut dyn Callbacks<E>, callbacks: &mut dyn Callbacks<E>,
) -> io::Result<Result<Option<Connection>, identity::Error>> { ) -> io::Result<Result<Option<Connection>, identity::Error>> {
let mut yubikey = match YubiKey::open_by_serial(self.serial) { let mut yubikey = match open_by_serial(self.serial) {
Ok(yk) => yk, Ok(yk) => yk,
Err(yubikey::Error::NotFound) => { Err(yubikey::Error::NotFound) => {
let mut message = i18n_embed_fl::fl!( let mut message = fl!("plugin-insert-yk", yubikey_serial = self.serial.to_string());
crate::LANGUAGE_LOADER,
"plugin-insert-yk",
yubikey_serial = self.serial.to_string(),
);
// If the `confirm` command is available, we loop until either the YubiKey // If the `confirm` command is available, we loop until either the YubiKey
// we want is inserted, or the used explicitly skips. // we want is inserted, or the used explicitly skips.
@@ -294,14 +538,13 @@ impl Stub {
// User told us to skip this key. // User told us to skip this key.
Ok(false) => return Ok(Ok(None)), Ok(false) => return Ok(Ok(None)),
// User said they plugged it in; try it. // User said they plugged it in; try it.
Ok(true) => match YubiKey::open_by_serial(self.serial) { Ok(true) => match open_by_serial(self.serial) {
Ok(yubikey) => break Some(yubikey), Ok(yubikey) => break Some(yubikey),
Err(yubikey::Error::NotFound) => (), Err(yubikey::Error::NotFound) => (),
Err(_) => { Err(_) => {
return Ok(Err(identity::Error::Identity { return Ok(Err(identity::Error::Identity {
index: self.identity_index, index: self.identity_index,
message: i18n_embed_fl::fl!( message: fl!(
crate::LANGUAGE_LOADER,
"plugin-err-yk-opening", "plugin-err-yk-opening",
yubikey_serial = self.serial.to_string(), yubikey_serial = self.serial.to_string(),
), ),
@@ -312,8 +555,7 @@ impl Stub {
Err(age_core::plugin::Error::Fail) => { Err(age_core::plugin::Error::Fail) => {
return Ok(Err(identity::Error::Identity { return Ok(Err(identity::Error::Identity {
index: self.identity_index, index: self.identity_index,
message: i18n_embed_fl::fl!( message: fl!(
crate::LANGUAGE_LOADER,
"plugin-err-yk-opening", "plugin-err-yk-opening",
yubikey_serial = self.serial.to_string(), yubikey_serial = self.serial.to_string(),
), ),
@@ -323,8 +565,7 @@ impl Stub {
// We're going to loop around, meaning that the first attempt failed. // We're going to loop around, meaning that the first attempt failed.
// Change the message to indicate this to the user. // Change the message to indicate this to the user.
message = i18n_embed_fl::fl!( message = fl!(
crate::LANGUAGE_LOADER,
"plugin-insert-yk-retry", "plugin-insert-yk-retry",
yubikey_serial = self.serial.to_string(), yubikey_serial = self.serial.to_string(),
); );
@@ -337,8 +578,7 @@ impl Stub {
if callbacks.message(&message)?.is_err() { if callbacks.message(&message)?.is_err() {
return Ok(Err(identity::Error::Identity { return Ok(Err(identity::Error::Identity {
index: self.identity_index, index: self.identity_index,
message: i18n_embed_fl::fl!( message: fl!(
crate::LANGUAGE_LOADER,
"plugin-err-yk-not-found", "plugin-err-yk-not-found",
yubikey_serial = self.serial.to_string(), yubikey_serial = self.serial.to_string(),
), ),
@@ -348,14 +588,13 @@ impl Stub {
// Start a 15-second timer waiting for the YubiKey to be inserted // Start a 15-second timer waiting for the YubiKey to be inserted
let start = SystemTime::now(); let start = SystemTime::now();
loop { loop {
match YubiKey::open_by_serial(self.serial) { match open_by_serial(self.serial) {
Ok(yubikey) => break yubikey, Ok(yubikey) => break yubikey,
Err(yubikey::Error::NotFound) => (), Err(yubikey::Error::NotFound) => (),
Err(_) => { Err(_) => {
return Ok(Err(identity::Error::Identity { return Ok(Err(identity::Error::Identity {
index: self.identity_index, index: self.identity_index,
message: i18n_embed_fl::fl!( message: fl!(
crate::LANGUAGE_LOADER,
"plugin-err-yk-opening", "plugin-err-yk-opening",
yubikey_serial = self.serial.to_string(), yubikey_serial = self.serial.to_string(),
), ),
@@ -367,8 +606,7 @@ impl Stub {
Ok(end) if end >= FIFTEEN_SECONDS => { Ok(end) if end >= FIFTEEN_SECONDS => {
return Ok(Err(identity::Error::Identity { return Ok(Err(identity::Error::Identity {
index: self.identity_index, index: self.identity_index,
message: i18n_embed_fl::fl!( message: fl!(
crate::LANGUAGE_LOADER,
"plugin-err-yk-timed-out", "plugin-err-yk-timed-out",
yubikey_serial = self.serial.to_string(), yubikey_serial = self.serial.to_string(),
), ),
@@ -382,8 +620,7 @@ impl Stub {
Err(_) => { Err(_) => {
return Ok(Err(identity::Error::Identity { return Ok(Err(identity::Error::Identity {
index: self.identity_index, index: self.identity_index,
message: i18n_embed_fl::fl!( message: fl!(
crate::LANGUAGE_LOADER,
"plugin-err-yk-opening", "plugin-err-yk-opening",
yubikey_serial = self.serial.to_string(), yubikey_serial = self.serial.to_string(),
), ),
@@ -394,11 +631,10 @@ impl Stub {
// Read the pubkey from the YubiKey slot and check it still matches. // Read the pubkey from the YubiKey slot and check it still matches.
let (cert, pk) = match Certificate::read(&mut yubikey, SlotId::Retired(self.slot)) let (cert, pk) = match Certificate::read(&mut yubikey, SlotId::Retired(self.slot))
.ok() .ok()
.and_then(|cert| match cert.subject_pki() { .and_then(|cert| {
PublicKeyInfo::EcP256(pubkey) => Recipient::from_encoded(pubkey) identify_recipient(&cert)
.filter(|pk| pk.tag() == self.tag) .filter(|recipient| recipient.tag() == self.tag)
.map(|pk| (cert, pk)), .map(|r| (cert, r))
_ => None,
}) { }) {
Some(pk) => pk, Some(pk) => pk,
None => { None => {
@@ -444,9 +680,8 @@ impl Connection {
) -> io::Result<Result<(), identity::Error>> { ) -> io::Result<Result<(), identity::Error>> {
// Check if we can skip requesting a PIN. // Check if we can skip requesting a PIN.
if self.cached_metadata.is_none() { if self.cached_metadata.is_none() {
let (_, cert) = x509_parser::parse_x509_certificate(self.cert.as_ref()).unwrap();
self.cached_metadata = self.cached_metadata =
match Metadata::extract(&mut self.yubikey, self.slot, &cert, true) { match Metadata::extract(&mut self.yubikey, self.slot, &self.cert, true) {
None => { None => {
return Ok(Err(identity::Error::Identity { return Ok(Err(identity::Error::Identity {
index: self.identity_index, index: self.identity_index,
@@ -456,49 +691,38 @@ impl Connection {
metadata => metadata, metadata => metadata,
}; };
} }
if let Some(PinPolicy::Never) = self.cached_metadata.as_ref().and_then(|m| m.pin_policy) { match self.cached_metadata.as_ref().and_then(|m| m.pin_policy) {
return Ok(Ok(())); Some(PinPolicy::Never) => return Ok(Ok(())),
Some(PinPolicy::Once) if self.yubikey.verify_pin(&[]).is_ok() => return Ok(Ok(())),
_ => (),
} }
// The policy requires a PIN, so request it. // The policy requires a PIN, so request it.
// Note that we can't distinguish between PinPolicy::Once and PinPolicy::Always let pin = match request_pin(
// because this plugin is ephemeral, so we always request the PIN. |prev_error| {
let enter_pin_msg = i18n_embed_fl::fl!( callbacks.request_secret(&format!(
crate::LANGUAGE_LOADER, "{}{}{}",
prev_error.as_deref().unwrap_or(""),
prev_error.as_deref().map(|_| " ").unwrap_or(""),
fl!(
"plugin-enter-pin", "plugin-enter-pin",
yubikey_serial = self.yubikey.serial().to_string(), yubikey_serial = self.yubikey.serial().to_string(),
); )
let mut message = enter_pin_msg.clone(); ))
let pin = loop {
message = match callbacks.request_secret(&message)? {
Ok(pin) => match pin.expose_secret().len() {
// A PIN must be between 6 and 8 characters.
6..=8 => break pin,
// If the string is 44 bytes and starts with the YubiKey's serial
// encoded as 12-byte modhex, the user probably touched the YubiKey
// early and "typed" an OTP.
44 if pin
.expose_secret()
.starts_with(&otp_serial_prefix(self.yubikey.serial())) =>
{
format!("{} {}", fl!("plugin-err-accidental-touch"), enter_pin_msg)
}
// Otherwise, the PIN is either too short or too long.
0..=5 => format!("{} {}", fl!("plugin-err-pin-too-short"), enter_pin_msg),
_ => format!("{} {}", fl!("plugin-err-pin-too-long"), enter_pin_msg),
}, },
self.yubikey.serial(),
)? {
Ok(pin) => pin,
Err(_) => { Err(_) => {
return Ok(Err(identity::Error::Identity { return Ok(Err(identity::Error::Identity {
index: self.identity_index, index: self.identity_index,
message: i18n_embed_fl::fl!( message: fl!(
crate::LANGUAGE_LOADER,
"plugin-err-pin-required", "plugin-err-pin-required",
yubikey_serial = self.yubikey.serial().to_string(), yubikey_serial = self.yubikey.serial().to_string(),
), ),
})) }))
} }
}; };
};
if let Err(e) = self.yubikey.verify_pin(pin.expose_secret().as_bytes()) { if let Err(e) = self.yubikey.verify_pin(pin.expose_secret().as_bytes()) {
return Ok(Err(identity::Error::Identity { return Ok(Err(identity::Error::Identity {
index: self.identity_index, index: self.identity_index,
@@ -557,6 +781,13 @@ impl Connection {
Err(_) => Err(()), Err(_) => Err(()),
} }
} }
/// Close this connection without resetting the YubiKey.
///
/// This can be used to preserve the YubiKey's PIN and touch caches.
pub(crate) fn disconnect_without_reset(self) {
disconnect_without_reset(self.yubikey);
}
} }
#[cfg(test)] #[cfg(test)]
+91 -112
View File
@@ -12,12 +12,7 @@ use i18n_embed::{
}; };
use lazy_static::lazy_static; use lazy_static::lazy_static;
use rust_embed::RustEmbed; use rust_embed::RustEmbed;
use yubikey::{ use yubikey::{piv::RetiredSlotId, reader::Context, PinPolicy, Serial, TouchPolicy};
certificate::PublicKeyInfo,
piv::{RetiredSlotId, SlotId},
reader::Context,
Key, PinPolicy, Serial, TouchPolicy,
};
mod builder; mod builder;
mod error; mod error;
@@ -73,6 +68,9 @@ macro_rules! fl {
($message_id:literal) => {{ ($message_id:literal) => {{
i18n_embed_fl::fl!($crate::LANGUAGE_LOADER, $message_id) i18n_embed_fl::fl!($crate::LANGUAGE_LOADER, $message_id)
}}; }};
($message_id:literal, $($kwarg:expr),* $(,)*) => {{
i18n_embed_fl::fl!($crate::LANGUAGE_LOADER, $message_id, $($kwarg,)*)
}};
} }
#[derive(Debug, Options)] #[derive(Debug, Options)]
@@ -183,6 +181,13 @@ fn generate(flags: PluginFlags) -> Result<(), Error> {
util::print_identity(stub, recipient, metadata); util::print_identity(stub, recipient, metadata);
// We have written to the YubiKey, which means we've authenticated with the management
// key. Out of an abundance of caution, we let the YubiKey be reset on disconnect,
// which will clear its PIN and touch caches. This has as small negative UX effect,
// but identity generation is a relatively infrequent occurrence, and users are more
// likely to see their cached PINs reset due to switching applets (e.g. from PIV to
// FIDO2).
Ok(()) Ok(())
} }
@@ -193,29 +198,17 @@ fn print_single(
) -> Result<(), Error> { ) -> Result<(), Error> {
let mut yubikey = key::open(serial)?; let mut yubikey = key::open(serial)?;
let mut keys = Key::list(&mut yubikey)?.into_iter().filter_map(|key| { let (key, slot, recipient) = key::list_compatible(&mut yubikey)?
// - We only use the retired slots.
// - Only P-256 keys are compatible with us.
match (key.slot(), key.certificate().subject_pki()) {
(SlotId::Retired(slot), PublicKeyInfo::EcP256(pubkey)) => {
p256::Recipient::from_encoded(pubkey).map(|r| (key, slot, r))
}
_ => None,
}
});
let (key, slot, recipient) = keys
.find(|(_, s, _)| s == &slot) .find(|(_, s, _)| s == &slot)
.ok_or(Error::SlotHasNoIdentity(slot))?; .ok_or(Error::SlotHasNoIdentity(slot))?;
let stub = key::Stub::new(yubikey.serial(), slot, &recipient); let stub = key::Stub::new(yubikey.serial(), slot, &recipient);
let metadata = x509_parser::parse_x509_certificate(key.certificate().as_ref()) let metadata = util::Metadata::extract(&mut yubikey, slot, key.certificate(), true).unwrap();
.ok()
.and_then(|(_, cert)| util::Metadata::extract(&mut yubikey, slot, &cert, true))
.unwrap();
printer(stub, recipient, metadata); printer(stub, recipient, metadata);
key::disconnect_without_reset(yubikey);
Ok(()) Ok(())
} }
@@ -229,33 +222,16 @@ fn print_multiple(
let mut printed = 0; let mut printed = 0;
for reader in readers.iter()?.filter(key::filter_connected) { for reader in readers.iter()?.filter(key::filter_connected) {
let mut yubikey = reader.open()?; let mut yubikey = key::open_connection(&reader)?;
if let Some(serial) = serial { if let Some(serial) = serial {
if yubikey.serial() != serial { if yubikey.serial() != serial {
continue; continue;
} }
} }
for key in Key::list(&mut yubikey)? { for (key, slot, recipient) in key::list_compatible(&mut yubikey)? {
// We only use the retired slots.
let slot = match key.slot() {
SlotId::Retired(slot) => slot,
_ => continue,
};
// Only P-256 keys are compatible with us.
let recipient = match key.certificate().subject_pki() {
PublicKeyInfo::EcP256(pubkey) => match p256::Recipient::from_encoded(pubkey) {
Some(recipient) => recipient,
None => continue,
},
_ => continue,
};
let stub = key::Stub::new(yubikey.serial(), slot, &recipient); let stub = key::Stub::new(yubikey.serial(), slot, &recipient);
let metadata = match x509_parser::parse_x509_certificate(key.certificate().as_ref()) let metadata = match util::Metadata::extract(&mut yubikey, slot, key.certificate(), all)
.ok()
.and_then(|(_, cert)| util::Metadata::extract(&mut yubikey, slot, &cert, all))
{ {
Some(res) => res, Some(res) => res,
None => continue, None => continue,
@@ -266,17 +242,11 @@ fn print_multiple(
println!(); println!();
} }
println!(); println!();
key::disconnect_without_reset(yubikey);
} }
if printed > 1 { if printed > 1 {
eprintln!( eprintln!("{}", fl!("printed-multiple", kind = kind, count = printed));
"{}",
i18n_embed_fl::fl!(
LANGUAGE_LOADER,
"printed-multiple",
kind = kind,
count = printed,
)
);
} }
Ok(()) Ok(())
@@ -326,8 +296,8 @@ fn list(flags: PluginFlags, all: bool) -> Result<(), Error> {
flags, flags,
all, all,
|_, recipient, metadata| { |_, recipient, metadata| {
println!("{}", metadata); println!("{metadata}");
println!("{}", recipient.to_string()); println!("{recipient}");
}, },
) )
} }
@@ -359,8 +329,8 @@ fn main() -> Result<(), Error> {
if let Some(state_machine) = opts.age_plugin { if let Some(state_machine) = opts.age_plugin {
run_state_machine( run_state_machine(
&state_machine, &state_machine,
plugin::RecipientPlugin::default, Some(plugin::RecipientPlugin::default),
plugin::IdentityPlugin::default, Some(plugin::IdentityPlugin::default),
)?; )?;
Ok(()) Ok(())
} else if opts.version { } else if opts.version {
@@ -382,8 +352,7 @@ fn main() -> Result<(), Error> {
eprintln!( eprintln!(
"{}", "{}",
i18n_embed_fl::fl!( fl!(
LANGUAGE_LOADER,
"cli-setup-intro", "cli-setup-intro",
generate_usage = "age-plugin-yubikey --generate", generate_usage = "age-plugin-yubikey --generate",
) )
@@ -401,13 +370,14 @@ fn main() -> Result<(), Error> {
let reader_names = readers_list let reader_names = readers_list
.iter() .iter()
.map(|reader| { .map(|reader| {
reader.open().map(|yk| { key::open_connection(reader).map(|yk| {
i18n_embed_fl::fl!( let name = fl!(
LANGUAGE_LOADER,
"cli-setup-yk-name", "cli-setup-yk-name",
yubikey_name = reader.name(), yubikey_name = reader.name(),
yubikey_serial = yk.serial().to_string(), yubikey_serial = yk.serial().to_string(),
) );
key::disconnect_without_reset(yk);
name
}) })
}) })
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;
@@ -415,34 +385,36 @@ fn main() -> Result<(), Error> {
.with_prompt(fl!("cli-setup-select-yk")) .with_prompt(fl!("cli-setup-select-yk"))
.items(&reader_names) .items(&reader_names)
.default(0) .default(0)
.report(true)
.interact_opt()? .interact_opt()?
{ {
Some(yk) => readers_list[yk].open()?, Some(yk) => readers_list[yk].open()?,
None => return Ok(()), None => return Ok(()),
}; };
let keys = Key::list(&mut yubikey)?; let keys = key::list_slots(&mut yubikey)?.collect::<Vec<_>>();
// Identify slots that we can't allow the user to select. // Identify slots that we can't allow the user to select.
let slot_details: Vec<_> = USABLE_SLOTS let slot_details: Vec<_> = USABLE_SLOTS
.iter() .iter()
.map(|&slot| { .map(|&slot| {
keys.iter() keys.iter()
.find(|key| key.slot() == SlotId::Retired(slot)) .find(|(_, s, _)| s == &slot)
.map(|key| match key.certificate().subject_pki() { .map(|(key, _, recipient)| {
PublicKeyInfo::EcP256(pubkey) => { recipient.as_ref().map(|_| {
p256::Recipient::from_encoded(pubkey).map(|_| {
// Cache the details we need to display to the user. // Cache the details we need to display to the user.
let (_, cert) = let (_, cert) =
x509_parser::parse_x509_certificate(key.certificate().as_ref()) x509_parser::parse_x509_certificate(key.certificate().as_ref())
.unwrap(); .unwrap();
let (name, _) = util::extract_name(&cert, true).unwrap(); let (name, _) = util::extract_name(&cert, true).unwrap();
let created = cert.validity().not_before.to_rfc2822(); let created = cert
.validity()
.not_before
.to_rfc2822()
.unwrap_or_else(|e| format!("Invalid date: {e}"));
format!("{}, created: {}", name, created) format!("{name}, created: {created}")
}) })
}
_ => None,
}) })
}) })
.collect(); .collect();
@@ -455,20 +427,13 @@ fn main() -> Result<(), Error> {
let i = i + 1; let i = i + 1;
match occupied { match occupied {
Some(Some(name)) => i18n_embed_fl::fl!( Some(Some(name)) => fl!(
LANGUAGE_LOADER,
"cli-setup-slot-usable", "cli-setup-slot-usable",
slot_index = i, slot_index = i,
slot_name = name.as_str(), slot_name = name.as_str(),
), ),
Some(None) => i18n_embed_fl::fl!( Some(None) => fl!("cli-setup-slot-unusable", slot_index = i),
LANGUAGE_LOADER, None => fl!("cli-setup-slot-empty", slot_index = i),
"cli-setup-slot-unusable",
slot_index = i,
),
None => {
i18n_embed_fl::fl!(LANGUAGE_LOADER, "cli-setup-slot-empty", slot_index = i)
}
} }
}) })
.collect(); .collect();
@@ -479,6 +444,7 @@ fn main() -> Result<(), Error> {
.with_prompt(fl!("cli-setup-select-slot")) .with_prompt(fl!("cli-setup-select-slot"))
.items(&slots) .items(&slots)
.default(0) .default(0)
.report(true)
.interact_opt()? .interact_opt()?
{ {
Some(slot) => { Some(slot) => {
@@ -491,30 +457,23 @@ fn main() -> Result<(), Error> {
} }
}; };
if let Some(key) = keys.iter().find(|key| key.slot() == SlotId::Retired(slot)) { if let Some((key, _, recipient)) = keys.into_iter().find(|(_, s, _)| s == &slot) {
let recipient = match key.certificate().subject_pki() { let recipient = recipient.expect("We checked this above");
PublicKeyInfo::EcP256(pubkey) => {
p256::Recipient::from_encoded(pubkey).expect("We checked this above")
}
_ => unreachable!(),
};
if Confirm::new() if Confirm::new()
.with_prompt(i18n_embed_fl::fl!( .with_prompt(fl!("cli-setup-use-existing", slot_index = slot_index))
LANGUAGE_LOADER, .report(true)
"cli-setup-use-existing",
slot_index = slot_index,
))
.interact()? .interact()?
{ {
let stub = key::Stub::new(yubikey.serial(), slot, &recipient); let stub = key::Stub::new(yubikey.serial(), slot, &recipient);
let (_, cert) =
x509_parser::parse_x509_certificate(key.certificate().as_ref()).unwrap();
let metadata = let metadata =
util::Metadata::extract(&mut yubikey, slot, &cert, true).unwrap(); util::Metadata::extract(&mut yubikey, slot, key.certificate(), true)
.unwrap();
key::disconnect_without_reset(yubikey);
((stub, recipient, metadata), false) ((stub, recipient, metadata), false)
} else { } else {
key::disconnect_without_reset(yubikey);
return Ok(()); return Ok(());
} }
} else { } else {
@@ -525,8 +484,11 @@ fn main() -> Result<(), Error> {
flags.name.as_deref().unwrap_or("age identity TAG_HEX") flags.name.as_deref().unwrap_or("age identity TAG_HEX")
)) ))
.allow_empty(true) .allow_empty(true)
.report(true)
.interact_text()?; .interact_text()?;
let mut displayed_yk4_warning = false;
let pin_policy = loop {
let pin_policy = match Select::new() let pin_policy = match Select::new()
.with_prompt(fl!("cli-setup-select-pin-policy")) .with_prompt(fl!("cli-setup-select-pin-policy"))
.items(&[ .items(&[
@@ -542,6 +504,7 @@ fn main() -> Result<(), Error> {
}) })
.unwrap(), .unwrap(),
) )
.report(true)
.interact_opt()? .interact_opt()?
{ {
Some(0) => PinPolicy::Always, Some(0) => PinPolicy::Always,
@@ -551,6 +514,29 @@ fn main() -> Result<(), Error> {
None => return Ok(()), None => return Ok(()),
}; };
// We can't preserve the PIN cache for YubiKey 4 series, because to
// retrieve the serial we switch to the OTP applet.
match (pin_policy, yubikey.version().major) {
(PinPolicy::Once, 4) => {
if !displayed_yk4_warning {
eprintln!();
eprintln!("{}", fl!("cli-setup-yk4-pin-policy"));
eprintln!();
displayed_yk4_warning = true;
}
if Confirm::new()
.with_prompt(fl!("cli-setup-yk4-pin-policy-confirm"))
.report(true)
.interact()?
{
break pin_policy;
}
}
_ => break pin_policy,
}
};
let touch_policy = match Select::new() let touch_policy = match Select::new()
.with_prompt(fl!("cli-setup-select-touch-policy")) .with_prompt(fl!("cli-setup-select-touch-policy"))
.items(&[ .items(&[
@@ -566,6 +552,7 @@ fn main() -> Result<(), Error> {
}) })
.unwrap(), .unwrap(),
) )
.report(true)
.interact_opt()? .interact_opt()?
{ {
Some(0) => TouchPolicy::Always, Some(0) => TouchPolicy::Always,
@@ -576,11 +563,8 @@ fn main() -> Result<(), Error> {
}; };
if Confirm::new() if Confirm::new()
.with_prompt(i18n_embed_fl::fl!( .with_prompt(fl!("cli-setup-generate-new", slot_index = slot_index))
LANGUAGE_LOADER, .report(true)
"cli-setup-generate-new",
slot_index = slot_index,
))
.interact()? .interact()?
{ {
eprintln!(); eprintln!();
@@ -596,6 +580,7 @@ fn main() -> Result<(), Error> {
true, true,
) )
} else { } else {
key::disconnect_without_reset(yubikey);
return Ok(()); return Ok(());
} }
} }
@@ -608,6 +593,7 @@ fn main() -> Result<(), Error> {
"age-yubikey-identity-{}.txt", "age-yubikey-identity-{}.txt",
hex::encode(stub.tag) hex::encode(stub.tag)
)) ))
.report(true)
.interact_text()?; .interact_text()?;
let mut file = match OpenOptions::new() let mut file = match OpenOptions::new()
@@ -619,6 +605,7 @@ fn main() -> Result<(), Error> {
Err(e) if e.kind() == io::ErrorKind::AlreadyExists => { Err(e) if e.kind() == io::ErrorKind::AlreadyExists => {
if Confirm::new() if Confirm::new()
.with_prompt(fl!("cli-setup-identity-file-exists")) .with_prompt(fl!("cli-setup-identity-file-exists"))
.report(true)
.interact()? .interact()?
{ {
File::create(&file_name)? File::create(&file_name)?
@@ -632,8 +619,7 @@ fn main() -> Result<(), Error> {
writeln!( writeln!(
file, file,
"{}", "{}",
i18n_embed_fl::fl!( fl!(
LANGUAGE_LOADER,
"yubikey-identity", "yubikey-identity",
yubikey_metadata = metadata.to_string(), yubikey_metadata = metadata.to_string(),
recipient = recipient.to_string(), recipient = recipient.to_string(),
@@ -645,14 +631,8 @@ fn main() -> Result<(), Error> {
// If `rage` binary is installed, use it in examples. Otherwise default to `age`. // If `rage` binary is installed, use it in examples. Otherwise default to `age`.
let age_binary = which::which("rage").map(|_| "rage").unwrap_or("age"); let age_binary = which::which("rage").map(|_| "rage").unwrap_or("age");
let encrypt_usage = format!( let encrypt_usage = format!("$ cat foo.txt | {age_binary} -r {recipient} -o foo.txt.age");
"$ cat foo.txt | {} -r {} -o foo.txt.age", let decrypt_usage = format!("$ cat foo.txt.age | {age_binary} -d -i {file_name} > foo.txt");
age_binary, recipient
);
let decrypt_usage = format!(
"$ cat foo.txt.age | {} -d -i {} > foo.txt",
age_binary, file_name
);
let identity_usage = format!( let identity_usage = format!(
"$ age-plugin-yubikey -i --serial {} --slot {} > {}", "$ age-plugin-yubikey -i --serial {} --slot {} > {}",
stub.serial, stub.serial,
@@ -668,8 +648,7 @@ fn main() -> Result<(), Error> {
eprintln!(); eprintln!();
eprintln!( eprintln!(
"{}", "{}",
i18n_embed_fl::fl!( fl!(
LANGUAGE_LOADER,
"cli-setup-finished", "cli-setup-finished",
is_new = if is_new { "true" } else { "false" }, is_new = if is_new { "true" } else { "false" },
recipient = recipient.to_string(), recipient = recipient.to_string(),
+15 -2
View File
@@ -1,6 +1,8 @@
use bech32::{ToBase32, Variant}; use bech32::{ToBase32, Variant};
use p256::elliptic_curve::sec1::{FromEncodedPoint, ToEncodedPoint}; use p256::elliptic_curve::sec1::{FromEncodedPoint, ToEncodedPoint};
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
use yubikey::{certificate::PublicKeyInfo, Certificate};
use std::fmt; use std::fmt;
use crate::RECIPIENT_PREFIX; use crate::RECIPIENT_PREFIX;
@@ -42,12 +44,23 @@ impl Recipient {
} }
} }
pub(crate) fn from_certificate(cert: &Certificate) -> Option<Self> {
Self::from_spki(cert.subject_pki())
}
pub(crate) fn from_spki(spki: &PublicKeyInfo) -> Option<Self> {
match spki {
PublicKeyInfo::EcP256(pubkey) => Self::from_encoded(pubkey),
_ => None,
}
}
/// Attempts to parse a valid YubiKey recipient from its SEC-1 encoding. /// Attempts to parse a valid YubiKey recipient from its SEC-1 encoding.
/// ///
/// This accepts both compressed (as used by the plugin) and uncompressed (as used in /// This accepts both compressed (as used by the plugin) and uncompressed (as used in
/// the YubiKey certificate) encodings. /// the YubiKey certificate) encodings.
pub(crate) fn from_encoded(encoded: &p256::EncodedPoint) -> Option<Self> { fn from_encoded(encoded: &p256::EncodedPoint) -> Option<Self> {
p256::PublicKey::from_encoded_point(encoded).map(Recipient) Option::from(p256::PublicKey::from_encoded_point(encoded)).map(Recipient)
} }
/// Returns the compressed SEC-1 encoding of this recipient. /// Returns the compressed SEC-1 encoding of this recipient.
+3 -2
View File
@@ -71,8 +71,7 @@ impl RecipientPluginV1 for RecipientPlugin {
Ok(Some(conn)) => yk_recipients.push(conn.recipient().clone()), Ok(Some(conn)) => yk_recipients.push(conn.recipient().clone()),
Ok(None) => yk_errors.push(recipient::Error::Identity { Ok(None) => yk_errors.push(recipient::Error::Identity {
index: stub.identity_index, index: stub.identity_index,
message: i18n_embed_fl::fl!( message: fl!(
crate::LANGUAGE_LOADER,
"plugin-err-yk-opening", "plugin-err-yk-opening",
yubikey_serial = stub.serial.to_string(), yubikey_serial = stub.serial.to_string(),
), ),
@@ -250,6 +249,8 @@ impl IdentityPluginV1 for IdentityPlugin {
} }
} }
} }
conn.disconnect_without_reset();
} }
Ok(file_keys) Ok(file_keys)
} }
+19 -18
View File
@@ -4,7 +4,7 @@ use std::iter;
use x509_parser::{certificate::X509Certificate, der_parser::oid::Oid}; use x509_parser::{certificate::X509Certificate, der_parser::oid::Oid};
use yubikey::{ use yubikey::{
piv::{RetiredSlotId, SlotId}, piv::{RetiredSlotId, SlotId},
PinPolicy, Serial, TouchPolicy, YubiKey, Certificate, PinPolicy, Serial, TouchPolicy, YubiKey,
}; };
use crate::fl; use crate::fl;
@@ -112,15 +112,20 @@ impl Metadata {
pub(crate) fn extract( pub(crate) fn extract(
yubikey: &mut YubiKey, yubikey: &mut YubiKey,
slot: RetiredSlotId, slot: RetiredSlotId,
cert: &X509Certificate, cert: &Certificate,
all: bool, all: bool,
) -> Option<Self> { ) -> Option<Self> {
let (_, cert) = x509_parser::parse_x509_certificate(cert.as_ref()).ok()?;
// We store the PIN and touch policies for identities in their certificates // We store the PIN and touch policies for identities in their certificates
// using the same certificate extension as PIV attestations. // using the same certificate extension as PIV attestations.
// https://developers.yubico.com/PIV/Introduction/PIV_attestation.html // https://developers.yubico.com/PIV/Introduction/PIV_attestation.html
let policies = |c: &X509Certificate| { let policies = |c: &X509Certificate| {
c.tbs_certificate c.tbs_certificate
.find_extension(&Oid::from(POLICY_EXTENSION_OID).unwrap()) .get_extension_unique(&Oid::from(POLICY_EXTENSION_OID).unwrap())
// If the extension is duplicated, we assume it is invalid.
.ok()
.flatten()
// If the encoded extension doesn't have 2 bytes, we assume it is invalid. // If the encoded extension doesn't have 2 bytes, we assume it is invalid.
.filter(|policy| policy.value.len() >= 2) .filter(|policy| policy.value.len() >= 2)
.map(|policy| { .map(|policy| {
@@ -143,10 +148,10 @@ impl Metadata {
.unwrap_or((None, None)) .unwrap_or((None, None))
}; };
extract_name(cert, all) extract_name(&cert, all)
.map(|(name, ours)| { .map(|(name, ours)| {
if ours { if ours {
let (pin_policy, touch_policy) = policies(cert); let (pin_policy, touch_policy) = policies(&cert);
(name, pin_policy, touch_policy) (name, pin_policy, touch_policy)
} else { } else {
// We can extract the PIN and touch policies via an attestation. This // We can extract the PIN and touch policies via an attestation. This
@@ -168,7 +173,11 @@ impl Metadata {
serial: yubikey.serial(), serial: yubikey.serial(),
slot, slot,
name, name,
created: cert.validity().not_before.to_rfc2822(), created: cert
.validity()
.not_before
.to_rfc2822()
.unwrap_or_else(|e| format!("Invalid date: {e}")),
pin_policy, pin_policy,
touch_policy, touch_policy,
}) })
@@ -180,8 +189,7 @@ impl fmt::Display for Metadata {
write!( write!(
f, f,
"{}", "{}",
i18n_embed_fl::fl!( fl!(
crate::LANGUAGE_LOADER,
"yubikey-metadata", "yubikey-metadata",
serial = self.serial.to_string(), serial = self.serial.to_string(),
slot = slot_to_ui(&self.slot), slot = slot_to_ui(&self.slot),
@@ -197,20 +205,13 @@ impl fmt::Display for Metadata {
pub(crate) fn print_identity(stub: Stub, recipient: Recipient, metadata: Metadata) { pub(crate) fn print_identity(stub: Stub, recipient: Recipient, metadata: Metadata) {
let recipient = recipient.to_string(); let recipient = recipient.to_string();
if !console::user_attended() { if !console::user_attended() {
eprintln!( let recipient = recipient.as_str();
"{}", eprintln!("{}", fl!("print-recipient", recipient = recipient));
i18n_embed_fl::fl!(
crate::LANGUAGE_LOADER,
"print-recipient",
recipient = recipient.as_str(),
)
);
} }
println!( println!(
"{}", "{}",
i18n_embed_fl::fl!( fl!(
crate::LANGUAGE_LOADER,
"yubikey-identity", "yubikey-identity",
yubikey_metadata = metadata.to_string(), yubikey_metadata = metadata.to_string(),
recipient = recipient, recipient = recipient,
+125
View File
@@ -0,0 +1,125 @@
use std::env;
use std::io::Write;
use std::path::Path;
use std::process::{Command, Stdio};
const PLUGIN_BIN: &str = env!("CARGO_BIN_EXE_age-plugin-yubikey");
#[test_with::env(YUBIKEY_SERIAL, YUBIKEY_SLOT)]
#[cfg_attr(all(unix, not(target_os = "macos")), test_with::executable(pcscd))]
#[test]
fn recipient_and_identity_match() {
let recipient = Command::new(PLUGIN_BIN)
.arg("--list")
.arg("--serial")
.arg(env::var("YUBIKEY_SERIAL").unwrap())
.arg("--slot")
.arg(env::var("YUBIKEY_SLOT").unwrap())
.output()
.unwrap();
assert_eq!(recipient.status.code(), Some(0));
let identity = Command::new(PLUGIN_BIN)
.arg("--identity")
.arg("--serial")
.arg(env::var("YUBIKEY_SERIAL").unwrap())
.arg("--slot")
.arg(env::var("YUBIKEY_SLOT").unwrap())
.output()
.unwrap();
assert_eq!(identity.status.code(), Some(0));
let recipient_file = String::from_utf8_lossy(&recipient.stdout);
let recipient = recipient_file.lines().last().unwrap();
let identity = String::from_utf8_lossy(&identity.stdout);
assert!(identity.contains(recipient));
}
#[test_with::executable(rage)]
#[test]
fn plugin_encrypt() {
let enc_file = tempfile::NamedTempFile::new_in(env!("CARGO_TARGET_TMPDIR")).unwrap();
let mut process = Command::new(which::which("rage").unwrap())
.arg("-r")
.arg("age1yubikey1q2w7u3vpya839jxxuq8g0sedh3d740d4xvn639sqhr95ejj8vu3hyfumptt")
.arg("-o")
.arg(enc_file.path())
.stdin(Stdio::piped())
.env("PATH", Path::new(PLUGIN_BIN).parent().unwrap())
.spawn()
.unwrap();
// Scope to ensure stdin is closed.
{
let mut stdin = process.stdin.take().unwrap();
stdin.write_all(b"Testing YubiKey encryption").unwrap();
stdin.flush().unwrap();
}
let status = process.wait().unwrap();
assert_eq!(status.code(), Some(0));
}
#[test_with::env(YUBIKEY_SERIAL, YUBIKEY_SLOT)]
#[test_with::executable(rage)]
#[cfg_attr(all(unix, not(target_os = "macos")), test_with::executable(pcscd))]
#[test]
fn plugin_decrypt() {
let mut identity_file = tempfile::NamedTempFile::new_in(env!("CARGO_TARGET_TMPDIR")).unwrap();
let enc_file = tempfile::NamedTempFile::new_in(env!("CARGO_TARGET_TMPDIR")).unwrap();
let plaintext = "Testing YubiKey encryption";
// Write an identity file corresponding to this YubiKey slot.
let identity = Command::new(PLUGIN_BIN)
.arg("--identity")
.arg("--serial")
.arg(env::var("YUBIKEY_SERIAL").unwrap())
.arg("--slot")
.arg(env::var("YUBIKEY_SLOT").unwrap())
.output()
.unwrap();
assert_eq!(identity.status.code(), Some(0));
identity_file.write_all(&identity.stdout).unwrap();
identity_file.flush().unwrap();
// Encrypt to the YubiKey slot.
let mut enc_process = Command::new(which::which("rage").unwrap())
.arg("-e")
.arg("-i")
.arg(identity_file.path())
.arg("-o")
.arg(enc_file.path())
.stdin(Stdio::piped())
.env("PATH", Path::new(PLUGIN_BIN).parent().unwrap())
.spawn()
.unwrap();
// Scope to ensure stdin is closed.
{
let mut stdin = enc_process.stdin.take().unwrap();
stdin.write_all(plaintext.as_bytes()).unwrap();
stdin.flush().unwrap();
}
let enc_status = enc_process.wait().unwrap();
assert_eq!(enc_status.code(), Some(0));
// Decrypt with the YubiKey.
let dec_process = Command::new(which::which("rage").unwrap())
.arg("-d")
.arg("-i")
.arg(identity_file.path())
.arg(enc_file.path())
.stdin(Stdio::piped())
.env("PATH", Path::new(PLUGIN_BIN).parent().unwrap())
.output()
.unwrap();
let stderr = String::from_utf8_lossy(&dec_process.stderr);
if !stderr.is_empty() {
assert!(stderr.contains("age-plugin-yubikey"));
assert!(stderr.ends_with("...\n"));
}
assert_eq!(String::from_utf8_lossy(&dec_process.stdout), plaintext);
}