Conversation
* Port x509/mod.rs * WIP PIV verification * Revert x509-parser -> x509-cert migration * Create nongeneric yk::provision variants * Add generate csr example * Resolve conflict * cargo * undo * Update API * First attempt at keytype * fmt * Remove macro * Fix test * Fix generate csr test fail * Minimize diff * Remove debug * New CTAP2 API * Check all PRs * Support AES * Use API to fetch mgm key algorithm * breaking yk.unlock * unbreak * unbreak
There was a problem hiding this comment.
Pull request overview
This PR upgrades the crate’s YubiKey PIV integration to newer YubiKey library APIs (skipping the prior “Yk8” step) and adds support for selecting the management key algorithm explicitly, which is needed for newer YubiKeys that default to AES management keys.
Changes:
- Bump YubiKey-related dependencies and adjust PIV code to the new certificate/SPKI APIs.
- Add
ManagementKeyAlgorithmplusunlock_with_management_key_algorithm, and expose default management key algorithm detection. - Add a new
KeyTypeimplementation layer (keytype.rs) and update examples/bench to the new APIs (including a new CSR example).
Reviewed changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
src/yubikey/piv/mod.rs |
Exposes new keytype module and re-exports types/enums for callers. |
src/yubikey/piv/management.rs |
Updates PIV management/signing/provisioning logic to new yubikey/x509-cert APIs; adds management key algorithm support. |
src/yubikey/piv/keytype.rs |
Introduces KeyType impls and supporting signature/key wrappers for P-256/P-384. |
src/fido/generate/ctap2_hid.rs |
Adapts to updated attestation flag field layout. |
examples/yk-provision.rs |
Adds CLI support for explicit management key algorithm and updated provisioning methods. |
examples/yk-generate-csr.rs |
New example for CSR generation and signature verification. |
examples/sign-cert-with-yubikey.rs |
Adds PIN/mgmt key CLI options and unlock path before signing. |
benches/certs_per_second.rs |
Updates imports to match the new yubikey APIs. |
Cargo.toml |
Version bump + dependency/feature updates for yubikey 0.9 pre and related crates. |
Cargo.lock |
Adds lockfile content corresponding to the dependency updates. |
.gitignore |
Stops ignoring Cargo.lock. |
.github/workflows/rust.yml |
Adjusts PR workflow trigger scope/formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Updates the YubiKey PIV integration to support newer YubiKey firmware defaults (AES management keys) by detecting/overriding the management key algorithm, and adapts the code to newer yubikey crate APIs.
Changes:
- Bump YubiKey/RustCrypto-related dependencies and wire in new PIV certificate/key handling (
yubikey0.9 pre). - Add
ManagementKeyAlgorithm+unlock_with_management_key_algorithmand update examples to accept--mgmkey-alg. - Introduce a
KeyTypeimplementation module and adjust provisioning/CSR generation accordingly.
Reviewed changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/yubikey/piv/mod.rs |
Exposes new keytype module and additional error variants / re-exports. |
src/yubikey/piv/management.rs |
Core PIV API changes: management key algorithm handling, CSR generation updates, provisioning refactor. |
src/yubikey/piv/keytype.rs |
New KeyType implementations for P-256/P-384 to support YubiKey certificate signing integration. |
src/fido/generate/ctap2_hid.rs |
Updates to new CTAP2 attestation flag field layout. |
examples/yk-provision.rs |
Adds CLI option for management key algorithm and switches provisioning calls to curve-specific helpers. |
examples/yk-generate-csr.rs |
New example for generating/verifying a CSR using a YubiKey-backed key. |
examples/sign-cert-with-yubikey.rs |
Adds PIN/mgmt key CLI args and optional management key algorithm selection for signing flow. |
benches/certs_per_second.rs |
Adjusts imports for updated YubiKey module layout. |
Cargo.toml |
Dependency/feature updates for new YubiKey + RustCrypto ecosystem crates. |
Cargo.lock |
New lockfile committed to repo. |
.gitignore |
Stops ignoring Cargo.lock so it can be checked in. |
.github/workflows/rust.yml |
Small workflow trigger/formatting adjustment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let mut yk = super::Yubikey::open(serial) | ||
| .map_err(|e| Error::InternalYubiKeyError(e.to_string()))?; |
| SerialNumber::new(&[0; 20]).unwrap(), | ||
| Validity::from_now(std::time::Duration::new(3600 * 24 * 3650, 0)).unwrap(), | ||
| Name::from_str(&format!("CN={}", common_name)).unwrap(), |
| Ok(_) => (AlgorithmId::Rsa2048, &digest::SHA256), // RSAish | ||
| Err(_) => return Err(Error::Unprovisioned), | ||
| let cert = self.configured(&slot) | ||
| .map_err(|e| Error::InternalYubiKeyError(format!("failed to read certificate for CSR generation: {}", e)))?; |
Building on top of #27.
The bump to 8 was blocked due to conflicting RustCrypto crates. That issue is gone in Yk8 so we are skipping Yk8.
By default, Yubikey unlock will read the firmware to derive the default management key algorithm. But we will also expose
unlock_with_management_key_algorithmto allow caller to specify a custom key algorithm if the default doesn't work.TLDR: If your management key algorithm is not the factory default, you need to specify it.
Tests
Firmware 5.4.3 using TDES (default)
Pass
Firmware 5.7.1 using AES192 (default)
Pass
Firmware 5.7.1 using TDES (non-default)
Pass