feat: v1.13.7, add subcommand yubikey
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -508,7 +508,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "card-cli"
|
name = "card-cli"
|
||||||
version = "1.13.6"
|
version = "1.13.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes-gcm-stream",
|
"aes-gcm-stream",
|
||||||
"authenticator 0.3.1",
|
"authenticator 0.3.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "card-cli"
|
name = "card-cli"
|
||||||
version = "1.13.6"
|
version = "1.13.7"
|
||||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ impl Command for CommandImpl {
|
|||||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||||
SubCommand::with_name(self.name())
|
SubCommand::with_name(self.name())
|
||||||
.about("YubiKey HMAC decrypt")
|
.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("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(Arg::with_name("outputs-password").long("outputs-password").help("Outputs password"))
|
||||||
.arg(cmdutil::build_json_arg())
|
.arg(cmdutil::build_json_arg())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,14 +14,8 @@ impl Command for CommandImpl {
|
|||||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||||
SubCommand::with_name(self.name())
|
SubCommand::with_name(self.name())
|
||||||
.about("YubiKey HMAC encrypt")
|
.about("YubiKey HMAC encrypt")
|
||||||
.arg(
|
.arg(Arg::with_name("plaintext").long("plaintext").short("t").takes_value(true).required(true).help("Plaintext"))
|
||||||
Arg::with_name("plaintext")
|
.arg(Arg::with_name("password").long("password").short("P").takes_value(true).help("Password"))
|
||||||
.long("plaintext")
|
|
||||||
.takes_value(true)
|
|
||||||
.required(true)
|
|
||||||
.help("Plaintext"),
|
|
||||||
)
|
|
||||||
.arg(Arg::with_name("password").long("password").takes_value(true).help("Password"))
|
|
||||||
.arg(cmdutil::build_with_pbe_encrypt_arg())
|
.arg(cmdutil::build_with_pbe_encrypt_arg())
|
||||||
.arg(cmdutil::build_double_pin_check_arg())
|
.arg(cmdutil::build_double_pin_check_arg())
|
||||||
.arg(cmdutil::build_pbe_iteration_arg())
|
.arg(cmdutil::build_pbe_iteration_arg())
|
||||||
|
|||||||
44
src/cmd_yubikey.rs
Normal file
44
src/cmd_yubikey.rs
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,6 +82,7 @@ mod signfile;
|
|||||||
mod sshutil;
|
mod sshutil;
|
||||||
mod util;
|
mod util;
|
||||||
mod yubikeyutil;
|
mod yubikeyutil;
|
||||||
|
mod cmd_yubikey;
|
||||||
|
|
||||||
pub struct DefaultCommandImpl;
|
pub struct DefaultCommandImpl;
|
||||||
|
|
||||||
@@ -166,6 +167,7 @@ fn inner_main() -> CommandError {
|
|||||||
Box::new(cmd_external_public_key::CommandImpl),
|
Box::new(cmd_external_public_key::CommandImpl),
|
||||||
Box::new(cmd_external_sign::CommandImpl),
|
Box::new(cmd_external_sign::CommandImpl),
|
||||||
Box::new(cmd_external_ecdh::CommandImpl),
|
Box::new(cmd_external_ecdh::CommandImpl),
|
||||||
|
Box::new(cmd_yubikey::CommandImpl),
|
||||||
];
|
];
|
||||||
|
|
||||||
#[allow(clippy::vec_init_then_push)]
|
#[allow(clippy::vec_init_then_push)]
|
||||||
|
|||||||
Reference in New Issue
Block a user