From 9de79477b9bbd68e5f17eddd18ec65f1589eeaff Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Tue, 23 Nov 2021 19:52:06 +0100 Subject: [PATCH] Implement get_firmware_version (probably YubiKey specific) --- openpgp-card-sequoia/src/card.rs | 5 +++++ openpgp-card/src/apdu/commands.rs | 5 +++++ openpgp-card/src/card_app.rs | 11 +++++++++++ tools/src/bin/opgpcard/main.rs | 11 ++++++++++- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/openpgp-card-sequoia/src/card.rs b/openpgp-card-sequoia/src/card.rs index 9ea38d6..e6585d7 100644 --- a/openpgp-card-sequoia/src/card.rs +++ b/openpgp-card-sequoia/src/card.rs @@ -267,6 +267,11 @@ impl<'a> Open<'a> { self.card_app.get_algo_info() } + /// Firmware Version, YubiKey specific (?) + pub fn firmware_version(&mut self) -> Result> { + self.card_app.get_firmware_version() + } + // ---------- pub fn get_pub_key( diff --git a/openpgp-card/src/apdu/commands.rs b/openpgp-card/src/apdu/commands.rs index f277a7e..b352e8d 100644 --- a/openpgp-card/src/apdu/commands.rs +++ b/openpgp-card/src/apdu/commands.rs @@ -66,6 +66,11 @@ pub(crate) fn get_algo_list() -> Command { get_data(&[0xFA]) } +/// GET Firmware Version (yubikey specific?) +pub(crate) fn get_firmware_version() -> Command { + Command::new(0x00, 0xF1, 0x00, 0x00, vec![]) +} + /// GET RESPONSE pub(crate) fn get_response() -> Command { Command::new(0x00, 0xC0, 0x00, 0x00, vec![]) diff --git a/openpgp-card/src/card_app.rs b/openpgp-card/src/card_app.rs index 68f0863..9ea262d 100644 --- a/openpgp-card/src/card_app.rs +++ b/openpgp-card/src/card_app.rs @@ -233,6 +233,17 @@ impl CardApp { Ok(Some(ai)) } + /// Firmware Version (YubiKey specific (?)) + pub fn get_firmware_version(&mut self) -> Result> { + let resp = apdu::send_command( + self.card_client(), + commands::get_firmware_version(), + true, + )?; + + Ok(resp.data()?.into()) + } + /// SELECT DATA "select a DO in the current template" /// (e.g. for cardholder certificate) pub fn select_data( diff --git a/tools/src/bin/opgpcard/main.rs b/tools/src/bin/opgpcard/main.rs index 08fa487..89b96ac 100644 --- a/tools/src/bin/opgpcard/main.rs +++ b/tools/src/bin/opgpcard/main.rs @@ -283,11 +283,20 @@ fn print_status(ident: Option, verbose: bool) -> Result<()> { // FIXME: add General key info; login data; KDF setting if verbose { - if let Some(ai) = open.algorithm_information()? { + // Algorithm information (list of supported algorithms) + if let Ok(Some(ai)) = open.algorithm_information() { println!(); println!("Supported algorithms:"); println!("{}", ai); } + + // YubiKey specific (?) firmware version + if let Ok(ver) = open.firmware_version() { + let ver = + ver.iter().map(u8::to_string).collect::>().join("."); + + println!("Firmware Version: {}", ver); + } } Ok(())