diff --git a/Cargo.lock b/Cargo.lock index 77a7267..734111f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -508,7 +508,7 @@ dependencies = [ [[package]] name = "card-cli" -version = "1.13.6" +version = "1.13.7" dependencies = [ "aes-gcm-stream", "authenticator 0.3.1", diff --git a/Cargo.toml b/Cargo.toml index 599ce5b..b310552 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "card-cli" -version = "1.13.6" +version = "1.13.7" authors = ["Hatter Jiang "] edition = "2018" diff --git a/src/cmd_hmac_decrypt.rs b/src/cmd_hmac_decrypt.rs index 83edc20..1caf379 100644 --- a/src/cmd_hmac_decrypt.rs +++ b/src/cmd_hmac_decrypt.rs @@ -15,9 +15,9 @@ impl Command for CommandImpl { fn subcommand<'a>(&self) -> App<'a, 'a> { SubCommand::with_name(self.name()) .about("YubiKey HMAC decrypt") - .arg(Arg::with_name("ciphertext").long("ciphertext").takes_value(true).required(true).help("Ciphertext"), ) + .arg(Arg::with_name("ciphertext").long("ciphertext").short("t").takes_value(true).required(true).help("Ciphertext"), ) .arg(Arg::with_name("auto-pbe").long("auto-pbe").help("Auto PBE decryption")) - .arg(Arg::with_name("password").long("password").takes_value(true).help("Password")) + .arg(Arg::with_name("password").long("password").short("P").takes_value(true).help("Password")) .arg(Arg::with_name("outputs-password").long("outputs-password").help("Outputs password")) .arg(cmdutil::build_json_arg()) } diff --git a/src/cmd_hmac_encrypt.rs b/src/cmd_hmac_encrypt.rs index f7aab3a..c7b5131 100644 --- a/src/cmd_hmac_encrypt.rs +++ b/src/cmd_hmac_encrypt.rs @@ -14,14 +14,8 @@ impl Command for CommandImpl { fn subcommand<'a>(&self) -> App<'a, 'a> { SubCommand::with_name(self.name()) .about("YubiKey HMAC encrypt") - .arg( - Arg::with_name("plaintext") - .long("plaintext") - .takes_value(true) - .required(true) - .help("Plaintext"), - ) - .arg(Arg::with_name("password").long("password").takes_value(true).help("Password")) + .arg(Arg::with_name("plaintext").long("plaintext").short("t").takes_value(true).required(true).help("Plaintext")) + .arg(Arg::with_name("password").long("password").short("P").takes_value(true).help("Password")) .arg(cmdutil::build_with_pbe_encrypt_arg()) .arg(cmdutil::build_double_pin_check_arg()) .arg(cmdutil::build_pbe_iteration_arg()) diff --git a/src/cmd_yubikey.rs b/src/cmd_yubikey.rs new file mode 100644 index 0000000..aa2eda1 --- /dev/null +++ b/src/cmd_yubikey.rs @@ -0,0 +1,44 @@ +use crate::util; +use clap::{App, ArgMatches, SubCommand}; +use rust_util::util_clap::{Command, CommandError}; +use rust_util::util_msg; +use serde_json::Value; +use std::collections::BTreeMap; +use yubikey::Context; + +pub struct CommandImpl; + +impl Command for CommandImpl { + fn name(&self) -> &str { + "yubikey" + } + + fn subcommand<'a>(&self) -> App<'a, 'a> { + SubCommand::with_name(self.name()).about("Yubikey subcommand") + } + + fn run(&self, _arg_matches: &ArgMatches, _sub_arg_matches: &ArgMatches) -> CommandError { + util_msg::set_logger_std_out(false); + + let mut list = vec![]; + let mut readers = Context::open()?; + for reader in readers.iter()? { + let yubikey = match reader.open() { + Ok(yk) => yk, + Err(e) => { + warning!("Error opening YubiKey: {}", e); + continue; + } + }; + + let mut key = BTreeMap::new(); + key.insert("serial", Value::Number(yubikey.serial().0.into())); + key.insert("version", yubikey.version().to_string().into()); + key.insert("name", yubikey.name().into()); + + list.push(key); + } + util::print_pretty_json(&list); + Ok(None) + } +} diff --git a/src/main.rs b/src/main.rs index fe65c9b..e1147bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,6 +82,7 @@ mod signfile; mod sshutil; mod util; mod yubikeyutil; +mod cmd_yubikey; pub struct DefaultCommandImpl; @@ -166,6 +167,7 @@ fn inner_main() -> CommandError { Box::new(cmd_external_public_key::CommandImpl), Box::new(cmd_external_sign::CommandImpl), Box::new(cmd_external_ecdh::CommandImpl), + Box::new(cmd_yubikey::CommandImpl), ]; #[allow(clippy::vec_init_then_push)]