feat: piv summary
This commit is contained in:
@@ -6,9 +6,9 @@ use tabled::{Table, Tabled};
|
||||
use tabled::settings::Style;
|
||||
use x509_parser::parse_x509_certificate;
|
||||
use yubikey::{Certificate, YubiKey};
|
||||
use yubikey::piv::SlotId;
|
||||
use yubikey::piv::{metadata, SlotId};
|
||||
|
||||
use crate::pivutil::get_algorithm_id;
|
||||
use crate::pivutil::{get_algorithm_id, ToStr};
|
||||
|
||||
#[derive(Tabled)]
|
||||
struct PivSlot {
|
||||
@@ -16,6 +16,8 @@ struct PivSlot {
|
||||
id: String,
|
||||
algorithm: String,
|
||||
subject: String,
|
||||
pin_policy: String,
|
||||
touch_policy: String,
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +75,14 @@ impl Command for CommandImpl {
|
||||
|
||||
fn print_summary_info(yubikey: &mut YubiKey, slot: SlotId, piv_slots: &mut Vec<PivSlot>, show_all: bool, show_table: bool) -> XResult<()> {
|
||||
let slot_id: u8 = slot.into();
|
||||
let mut pin_policy = Some("N/A".to_string());
|
||||
let mut touch_policy = Some("N/A".to_string());
|
||||
if let Ok(metadata) = metadata(yubikey, slot) {
|
||||
if let Some((p_policy, t_policy)) = &metadata.policy {
|
||||
pin_policy = Some(p_policy.to_str().to_string());
|
||||
touch_policy = Some(t_policy.to_str().to_string());
|
||||
}
|
||||
}
|
||||
let cert = match Certificate::read(yubikey, slot) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
@@ -83,6 +93,8 @@ fn print_summary_info(yubikey: &mut YubiKey, slot: SlotId, piv_slots: &mut Vec<P
|
||||
id: format!("{:x}", slot_id),
|
||||
algorithm: "N/A".to_string(),
|
||||
subject: "N/A".to_string(),
|
||||
pin_policy: pin_policy.as_ref().unwrap().to_string(),
|
||||
touch_policy: touch_policy.as_ref().unwrap().to_string(),
|
||||
});
|
||||
} else {
|
||||
warning!("Slot: {:?}, id: {:x}, certificate not found", slot, slot_id);
|
||||
@@ -105,6 +117,8 @@ fn print_summary_info(yubikey: &mut YubiKey, slot: SlotId, piv_slots: &mut Vec<P
|
||||
id: format!("{:x}", slot_id),
|
||||
algorithm: algorithm_id,
|
||||
subject: cert_subject,
|
||||
pin_policy: pin_policy.as_ref().unwrap().to_string(),
|
||||
touch_policy: touch_policy.as_ref().unwrap().to_string(),
|
||||
});
|
||||
} else {
|
||||
success!("Slot: {:x}, algorithm: {}, name: {:?},subject: {}", slot_id, algorithm_id, slot, cert_subject);
|
||||
|
||||
Reference in New Issue
Block a user