From ef1f637c83a0bf36af1c0ca9da9100794a3b6b56 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 29 Dec 2024 01:53:38 +0800 Subject: [PATCH] feat: v1.10.13, ec-sign support --no-pin --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/cmd_pivecsign.rs | 14 ++++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7320365..8bf5eb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -487,7 +487,7 @@ dependencies = [ [[package]] name = "card-cli" -version = "1.10.12" +version = "1.10.13" dependencies = [ "authenticator 0.3.1", "base64 0.21.7", diff --git a/Cargo.toml b/Cargo.toml index 1711d5c..5e969f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "card-cli" -version = "1.10.12" +version = "1.10.13" authors = ["Hatter Jiang "] edition = "2018" diff --git a/src/cmd_pivecsign.rs b/src/cmd_pivecsign.rs index 96341d7..208920c 100644 --- a/src/cmd_pivecsign.rs +++ b/src/cmd_pivecsign.rs @@ -18,6 +18,7 @@ impl Command for CommandImpl { fn subcommand<'a>(&self) -> App<'a, 'a> { SubCommand::with_name(self.name()).about("PIV EC sign(with SHA256) subcommand") .arg(Arg::with_name("pin").short("p").long("pin").takes_value(true).help("PIV card user PIN")) + .arg(Arg::with_name("no-pin").long("no-pin").help("No PIN")) .arg(Arg::with_name("slot").short("s").long("slot").takes_value(true).help("PIV slot, e.g. 82, 83 ... 95, 9a, 9c, 9d, 9e")) .arg(Arg::with_name("algorithm").short("a").long("algorithm").takes_value(true).help("Algorithm, p256 or p384")) .arg(Arg::with_name("file").short("f").long("file").takes_value(true).help("Input file")) @@ -32,9 +33,14 @@ impl Command for CommandImpl { let mut json = BTreeMap::<&'_ str, String>::new(); - let pin_opt = sub_arg_matches.value_of("pin"); - let pin_opt = pinutil::get_pin(pin_opt); - let pin_opt = pin_opt.as_deref(); + let pin_opt = if sub_arg_matches.is_present("no-pin") { + None + } else { + let pin_opt = sub_arg_matches.value_of("pin"); + let pin_opt = pinutil::get_pin(pin_opt); + let pin_opt = pin_opt.as_deref(); + pin_opt.map(|p| p.to_string()) + }; let slot = opt_value_result!(sub_arg_matches.value_of("slot"), "--slot must assigned, e.g. 82, 83 ... 95, 9a, 9c, 9d, 9e"); let hash_bytes = argsutil::get_sha256_digest_or_hash(sub_arg_matches)?; @@ -47,7 +53,7 @@ impl Command for CommandImpl { let mut yk = opt_result!(YubiKey::open(), "YubiKey not found: {}"); let slot_id = pivutil::get_slot_id(slot)?; - if let Some(pin) = pin_opt { + if let Some(pin) = &pin_opt { opt_result!(yk.verify_pin(pin.as_bytes()), "YubiKey verify pin failed: {}"); }