feat: add pgp card admin
This commit is contained in:
@@ -12,7 +12,7 @@ impl Command for CommandImpl {
|
||||
|
||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||
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("pin").short("p").long("pin").takes_value(true).default_value("123456").help("OpenPGP card user pin"))
|
||||
.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"))
|
||||
.arg(Arg::with_name("sha512").short("5").long("sha512").takes_value(true).help("Digest SHA512 HEX"))
|
||||
@@ -24,11 +24,10 @@ impl Command for CommandImpl {
|
||||
if json_output {
|
||||
rust_util::util_msg::set_logger_std_out(false);
|
||||
}
|
||||
let pass = sub_arg_matches.value_of("pass");
|
||||
let pass = match pass {
|
||||
Some(p) => p,
|
||||
None => return simple_error!("Pass must be assigned"),
|
||||
};
|
||||
let pin_opt = sub_arg_matches.value_of("pin");
|
||||
let pin = opt_value_result!(pin_opt, "User pin must be assigned");
|
||||
if pin.len() < 6 { return simple_error!("User pin length:{}, must >= 6!", pin.len()); }
|
||||
|
||||
let sha256 = sub_arg_matches.value_of("sha256");
|
||||
let sha384 = sub_arg_matches.value_of("sha384");
|
||||
let sha512 = sub_arg_matches.value_of("sha512");
|
||||
@@ -39,7 +38,7 @@ impl Command for CommandImpl {
|
||||
|
||||
let mut json = BTreeMap::new();
|
||||
if let Some(sha256) = sha256 {
|
||||
let user = crate::pgpcardutil::get_card_user_sw1_81(pass)?;
|
||||
let user = crate::pgpcardutil::get_card_user_sw1_81(pin)?;
|
||||
let sha256_hex = opt_result!(hex::decode(sha256.trim()), "Decode sha256 failed: {}");
|
||||
let sha256_hex = copy_sha256(&sha256_hex)?;
|
||||
let sig = user.signature_for_hash(Hash::SHA256(sha256_hex))?;
|
||||
@@ -53,7 +52,7 @@ impl Command for CommandImpl {
|
||||
}
|
||||
}
|
||||
if let Some(sha384) = sha384 {
|
||||
let user = crate::pgpcardutil::get_card_user_sw1_81(pass)?;
|
||||
let user = crate::pgpcardutil::get_card_user_sw1_81(pin)?;
|
||||
let sha384_hex = opt_result!(hex::decode(sha384.trim()), "Decode sha384 failed: {}");
|
||||
let sha384_hex = copy_sha384(&sha384_hex)?;
|
||||
let sig = user.signature_for_hash(Hash::SHA384(sha384_hex))?;
|
||||
@@ -67,7 +66,7 @@ impl Command for CommandImpl {
|
||||
}
|
||||
}
|
||||
if let Some(sha512) = sha512 {
|
||||
let user = crate::pgpcardutil::get_card_user_sw1_81(pass)?;
|
||||
let user = crate::pgpcardutil::get_card_user_sw1_81(pin)?;
|
||||
let sha512_hex = opt_result!(hex::decode(sha512.trim()), "Decode sha512 failed: {}");
|
||||
let sha512_hex = copy_sha512(&sha512_hex)?;
|
||||
let sig = user.signature_for_hash(Hash::SHA512(sha512_hex))?;
|
||||
|
||||
Reference in New Issue
Block a user