From 1602edf7363f9a675c50faef9e898787cff3e498 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 18 Jul 2021 11:27:19 +0800 Subject: [PATCH] feat: add url, card holder, supported algo for pgp card list --- src/pgpcarddecrypt.rs | 2 +- src/pgpcardlist.rs | 20 +++++++++++++++++++- src/pgpcardsign.rs | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/pgpcarddecrypt.rs b/src/pgpcarddecrypt.rs index ba7e109..4a79f68 100644 --- a/src/pgpcarddecrypt.rs +++ b/src/pgpcarddecrypt.rs @@ -9,7 +9,7 @@ impl Command for CommandImpl { fn name(&self) -> &str { "pgp-card-decrypt" } fn subcommand<'a>(&self) -> App<'a, 'a> { - SubCommand::with_name(self.name()).about("OpenPGP Card List subcommand") + SubCommand::with_name(self.name()).about("OpenPGP Card Decrypt subcommand") .arg(Arg::with_name("pass").short("p").long("pass").takes_value(true).default_value("123456").help("OpenPGP card password")) .arg(Arg::with_name("cipher").short("c").long("cipher").takes_value(true).help("Cipher text HEX")) .arg(Arg::with_name("cipher-base64").short("b").long("cipher-base64").takes_value(true).help("Cipher text base64")) diff --git a/src/pgpcardlist.rs b/src/pgpcardlist.rs index cbdd5be..e4d79cb 100644 --- a/src/pgpcardlist.rs +++ b/src/pgpcardlist.rs @@ -1,6 +1,6 @@ use clap::{ArgMatches, SubCommand, App, Arg}; use crate::cmd::{Command, CommandError}; -use openpgp_card::{OpenPGPCard, DecryptMe, Hash}; +use openpgp_card::{OpenPGPCard, DecryptMe, Hash, KeyType}; use std::collections::BTreeMap; pub struct CommandImpl; @@ -26,20 +26,38 @@ impl Command for CommandImpl { information!("Found {} card(s)", list.len()); for (i, card) in list.iter().enumerate() { success!("Found card {}: {:?}", i, card.get_aid()); + if let Ok(url) = card.get_url() { + information!("URL: {}", iff!(url.is_empty(), "", &url)); + } + if let Ok(card_holder) = card.get_cardholder_related_data() { + information!("Card holder: {:?}", card_holder); + } + if let Ok(supported_algo) = card.list_supported_algo() { + information!("Supported algo: {:?}", supported_algo); + } if let Ok(fingerprints) = card.get_fingerprints() { if let Some(a) = fingerprints.authentication() { + if let Ok(algo) = card.get_algorithm_attributes(KeyType::Authentication) { + information!("Authentication algo: {:?}", algo); + } information!("Authentication fingerprint: {}", a); if json_output { json.insert("authentication_fingerprint", a.to_string()); } } if let Some(d) = fingerprints.decryption() { + if let Ok(algo) = card.get_algorithm_attributes(KeyType::Decryption) { + information!("Encryption algo: {:?}", algo); + } information!("Encryption fingerprint: {}", d); if json_output { json.insert("encryption_fingerprint", d.to_string()); } } if let Some(s) = fingerprints.signature() { + if let Ok(algo) = card.get_algorithm_attributes(KeyType::Signing) { + information!("Signature algo: {:?}", algo); + } information!("Signature fingerprint: {}", s); if json_output { json.insert("signature_fingerprint", s.to_string()); diff --git a/src/pgpcardsign.rs b/src/pgpcardsign.rs index 3f2917f..f528c5d 100644 --- a/src/pgpcardsign.rs +++ b/src/pgpcardsign.rs @@ -10,7 +10,7 @@ impl Command for CommandImpl { fn name(&self) -> &str { "pgp-card-sign" } fn subcommand<'a>(&self) -> App<'a, 'a> { - SubCommand::with_name(self.name()).about("OpenPGP Card List subcommand") + SubCommand::with_name(self.name()).about("OpenPGP Card Sign subcommand") .arg(Arg::with_name("pass").short("p").long("pass").takes_value(true).default_value("123456").help("OpenPGP card password")) .arg(Arg::with_name("sha256").short("2").long("sha256").takes_value(true).help("Digest SHA256 HEX")) .arg(Arg::with_name("sha384").short("3").long("sha384").takes_value(true).help("Digest SHA384 HEX"))