From 9fb0da7d3358b8d4b13023b3c64711d15279830a Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Wed, 17 May 2023 00:53:17 +0800 Subject: [PATCH] feat: v1.5.8, opt piv-meta --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cmd_pivmeta.rs | 3 ++- src/pivutil.rs | 4 ++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55dafe3..a22b13c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -342,7 +342,7 @@ dependencies = [ [[package]] name = "card-cli" -version = "1.5.7" +version = "1.5.8" dependencies = [ "authenticator", "base64 0.13.1", diff --git a/Cargo.toml b/Cargo.toml index 882fca4..a8a32e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "card-cli" -version = "1.5.7" +version = "1.5.8" authors = ["Hatter Jiang "] edition = "2018" diff --git a/src/cmd_pivmeta.rs b/src/cmd_pivmeta.rs index 5889614..ee0c94c 100644 --- a/src/cmd_pivmeta.rs +++ b/src/cmd_pivmeta.rs @@ -12,6 +12,7 @@ use yubikey::certificate::PublicKeyInfo; use yubikey::piv::{AlgorithmId, ManagementAlgorithmId, metadata, Origin}; use crate::pivutil; +use crate::pivutil::slot_equals; use crate::pkiutil::bytes_to_pem; pub struct CommandImpl; @@ -116,7 +117,7 @@ impl Command for CommandImpl { Err(e) => warning!("List keys failed: {}", e), Ok(keys) => for k in &keys { let slot_str = format!("{:x}", Into::::into(k.slot())); - if slot_str == slot { + if slot_equals(&slot_id, &slot_str) { if !json.contains_key("pk_point_hex") { let public_key_hex = &k.certificate().subject_pki().public_key(); json.insert("pk_point_hex", hex::encode(&public_key_hex)); diff --git a/src/pivutil.rs b/src/pivutil.rs index 3611f03..a5bd0af 100644 --- a/src/pivutil.rs +++ b/src/pivutil.rs @@ -4,6 +4,10 @@ use rust_util::XResult; use yubikey::piv::RetiredSlotId; use yubikey::piv::SlotId; +pub fn slot_equals(slot_id: &SlotId, slot: &str) -> bool { + get_slot_id(slot).map(|sid| &sid == slot_id).unwrap_or(false) +} + pub fn get_slot_id(slot: &str) -> XResult { Ok(match slot { "9a" => SlotId::Authentication,