list: Ignore PIV devices we can't read from

This commit is contained in:
Jack Grigg
2021-03-29 18:51:21 +13:00
parent b6d70ba1f0
commit acac62660c
+14 -1
View File
@@ -1,5 +1,6 @@
use age_plugin::run_state_machine; use age_plugin::run_state_machine;
use gumdrop::Options; use gumdrop::Options;
use log::warn;
use yubikey_piv::{ use yubikey_piv::{
certificate::PublicKeyInfo, certificate::PublicKeyInfo,
key::{RetiredSlotId, SlotId}, key::{RetiredSlotId, SlotId},
@@ -142,7 +143,19 @@ fn list(all: bool) -> Result<(), Error> {
let mut readers = Readers::open()?; let mut readers = Readers::open()?;
for reader in readers.iter()? { for reader in readers.iter()? {
let mut yubikey = reader.open()?; let mut yubikey = match reader.open() {
Ok(yk) => yk,
Err(e) => {
use std::error::Error;
let reason = if let Some(inner) = e.source() {
format!("{}: {}", e, inner)
} else {
e.to_string()
};
warn!("Ignoring {}: {}", reader.name(), reason);
continue;
}
};
for key in Key::list(&mut yubikey)? { for key in Key::list(&mut yubikey)? {
// We only use the retired slots. // We only use the retired slots.