From 0f94dae70a712b5177edad21ca6b61fb512e207d Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 11 Mar 2023 11:50:07 +0800 Subject: [PATCH] feat: read flot meta --- __crypto/yubikey-rs-demo/src/main.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/__crypto/yubikey-rs-demo/src/main.rs b/__crypto/yubikey-rs-demo/src/main.rs index 2a7d179..1b3f78b 100644 --- a/__crypto/yubikey-rs-demo/src/main.rs +++ b/__crypto/yubikey-rs-demo/src/main.rs @@ -1,9 +1,9 @@ use p256::{ecdh::EphemeralSecret, EncodedPoint, PublicKey}; use p256::elliptic_curve::sec1::{FromEncodedPoint, ToEncodedPoint}; use rand::rngs::OsRng; -use rust_util::{failure_and_exit, information, XResult}; +use rust_util::{failure_and_exit, information, warning, XResult}; use yubikey::Context; -use yubikey::piv::{AlgorithmId, decrypt_data, RetiredSlotId, SlotId}; +use yubikey::piv::{AlgorithmId, decrypt_data, metadata, RetiredSlotId, SlotId}; // const EPK_BYTES: usize = 33; @@ -57,7 +57,14 @@ fn main() -> XResult<()> { let shared_secret = esk.diffie_hellman(&public_key); information!("Shared secret: {}", hex::encode(shared_secret.raw_secret_bytes())); - // yubikey.verify_pin(b"123456").expect("Verify pin!"); + let meta_result = metadata(&mut yubikey, SlotId::Retired(RetiredSlotId::R1)); + match meta_result { + Ok(meta) => { + information!("{:?}", meta) + } + Err(e) => warning!("Get slot meta failed: {}", e) + } + yubikey.verify_pin(b"123456").expect("Verify pin!"); let decrypted_shared_secret = decrypt_data( &mut yubikey, epk_bytes.decompress().as_bytes(),