feat: update yubikey to v0.8

This commit is contained in:
2023-08-20 15:24:28 +08:00
parent 9fb0da7d33
commit 7f5a5a7d3c
7 changed files with 470 additions and 641 deletions

View File

@@ -6,10 +6,12 @@ use digest::Digest;
use rust_util::util_clap::{Command, CommandError};
use rust_util::XResult;
use sha2::Sha256;
use spki::der::Encode;
use x509_parser::parse_x509_certificate;
use yubikey::{Certificate, YubiKey};
use yubikey::piv::SlotId;
use crate::pivutil::get_algorithm_id;
use crate::pkiutil::{bytes_to_pem, get_pki_algorithm};
pub struct CommandImpl;
@@ -78,13 +80,17 @@ fn print_cert_info(yubikey: &mut YubiKey, slot: SlotId, detail_output: bool) ->
return simple_error!("error reading certificate in slot {:?}: {}", slot, e);
}
};
let buf = cert.as_ref();
let buf_vec = cert.cert.to_der()?;
let buf: &[u8] = buf_vec.as_ref();
if !buf.is_empty() {
information!("{}", "-".repeat(88));
let certificate_fingerprint_sha256 = Sha256::digest(buf);
let slot_id: u8 = slot.into();
success!("Slot: {:?}, id: {:x}, algorithm: {:?}", slot, slot_id, cert.subject_pki().algorithm());
let algorithm_id = get_algorithm_id(&cert.cert.tbs_certificate.subject_public_key_info)
.map(|aid| format!("{:?}", aid))
.unwrap_or_else(|e| format!("Error: {}", e));
success!("Slot: {:?}, id: {:x}, algorithm: {}", slot, slot_id, algorithm_id);
if detail_output {
information!("{}", bytes_to_pem("CERTIFICATE", buf));