feat: v1.1.2 make clippy happy
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -336,7 +336,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "card-cli"
|
name = "card-cli"
|
||||||
version = "1.1.1"
|
version = "1.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"authenticator",
|
"authenticator",
|
||||||
"base64 0.13.0",
|
"base64 0.13.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "card-cli"
|
name = "card-cli"
|
||||||
version = "1.1.1"
|
version = "1.1.2"
|
||||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|||||||
@@ -79,9 +79,9 @@ impl Command for CommandImpl {
|
|||||||
} else {
|
} else {
|
||||||
success!("Challenge HEX: {}", hex::encode(challenge_bytes));
|
success!("Challenge HEX: {}", hex::encode(challenge_bytes));
|
||||||
success!("Response HEX: {}", hex_string);
|
success!("Response HEX: {}", hex_string);
|
||||||
hex_sha256.map(|hex_sha256| success!("Response SHA256 HEX: {}", hex::encode(hex_sha256)));
|
if let Some(hex_sha256) = hex_sha256 { success!("Response SHA256 HEX: {}", hex::encode(hex_sha256)); }
|
||||||
hex_sha384.map(|hex_sha384| success!("Response SHA384 HEX: {}", hex::encode(hex_sha384)));
|
if let Some(hex_sha384) = hex_sha384 { success!("Response SHA384 HEX: {}", hex::encode(hex_sha384)); }
|
||||||
hex_sha512.map(|hex_sha512| success!("Response SHA512 HEX: {}", hex::encode(hex_sha512)));
|
if let Some(hex_sha512) = hex_sha512 { success!("Response SHA512 HEX: {}", hex::encode(hex_sha512)); }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warning!("YubiKey not found");
|
warning!("YubiKey not found");
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ impl Command for CommandImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
|
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
|
||||||
let pin_opt = sub_arg_matches.value_of("pass").or(sub_arg_matches.value_of("pin"));
|
let pin_opt = sub_arg_matches.value_of("pass").or_else(|| sub_arg_matches.value_of("pin"));
|
||||||
let pin = opt_value_result!(pin_opt, "Pass must be assigned");
|
let pin = opt_value_result!(pin_opt, "Pass must be assigned");
|
||||||
if pin.len() < 8 { return simple_error!("Admin pin length:{}, must >= 8!", pin.len()); }
|
if pin.len() < 8 { return simple_error!("Admin pin length:{}, must >= 8!", pin.len()); }
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ impl Command for CommandImpl {
|
|||||||
if let Some(lang) = sub_arg_matches.value_of("lang") {
|
if let Some(lang) = sub_arg_matches.value_of("lang") {
|
||||||
information!("Set lang to: {}", lang);
|
information!("Set lang to: {}", lang);
|
||||||
let lang_bytes = lang.as_bytes();
|
let lang_bytes = lang.as_bytes();
|
||||||
opt_result!(trans.set_lang(&vec![Lang::Value([lang_bytes[0], lang_bytes[1]])]), "Set lang failed: {}");
|
opt_result!(trans.set_lang(&[Lang::Value([lang_bytes[0], lang_bytes[1]])]), "Set lang failed: {}");
|
||||||
success!("Set lang success");
|
success!("Set lang success");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ impl Command for CommandImpl {
|
|||||||
let json_output = sub_arg_matches.is_present("json");
|
let json_output = sub_arg_matches.is_present("json");
|
||||||
if json_output { rust_util::util_msg::set_logger_std_out(false); }
|
if json_output { rust_util::util_msg::set_logger_std_out(false); }
|
||||||
|
|
||||||
let pin_opt = sub_arg_matches.value_of("pass").or(sub_arg_matches.value_of("pin"));
|
let pin_opt = sub_arg_matches.value_of("pass").or_else(|| sub_arg_matches.value_of("pin"));
|
||||||
let pin = opt_value_result!(pin_opt, "User pin must be assigned");
|
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()); }
|
if pin.len() < 6 { return simple_error!("User pin length:{}, must >= 6!", pin.len()); }
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ use std::collections::BTreeMap;
|
|||||||
|
|
||||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||||
use openpgp_card::{KeyType, OpenPgp};
|
use openpgp_card::{KeyType, OpenPgp};
|
||||||
|
use openpgp_card::crypto_data::PublicKeyMaterial;
|
||||||
use openpgp_card_pcsc::PcscBackend;
|
use openpgp_card_pcsc::PcscBackend;
|
||||||
|
use openssl::bn::BigNum;
|
||||||
|
use openssl::rsa::Rsa;
|
||||||
|
use pem::Pem;
|
||||||
use rust_util::util_clap::{Command, CommandError};
|
use rust_util::util_clap::{Command, CommandError};
|
||||||
|
|
||||||
pub struct CommandImpl;
|
pub struct CommandImpl;
|
||||||
@@ -12,10 +16,12 @@ impl Command for CommandImpl {
|
|||||||
|
|
||||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
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 List subcommand")
|
||||||
|
.arg(Arg::with_name("detail").long("detail").help("Detail output"))
|
||||||
.arg(Arg::with_name("json").long("json").help("JSON output"))
|
.arg(Arg::with_name("json").long("json").help("JSON output"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
|
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
|
||||||
|
let detail_output = sub_arg_matches.is_present("detail");
|
||||||
let json_output = sub_arg_matches.is_present("json");
|
let json_output = sub_arg_matches.is_present("json");
|
||||||
if json_output { rust_util::util_msg::set_logger_std_out(false); }
|
if json_output { rust_util::util_msg::set_logger_std_out(false); }
|
||||||
|
|
||||||
@@ -99,6 +105,16 @@ impl Command for CommandImpl {
|
|||||||
if json_output {
|
if json_output {
|
||||||
json.insert("authentication_fingerprint", a.to_string());
|
json.insert("authentication_fingerprint", a.to_string());
|
||||||
}
|
}
|
||||||
|
if detail_output {
|
||||||
|
if let Ok(public_key) = trans.public_key(KeyType::Authentication) {
|
||||||
|
if let Some(public_key_pem) = public_key_pem(&public_key) {
|
||||||
|
information!("Authentication public key: {}", public_key_pem.trim());
|
||||||
|
if json_output {
|
||||||
|
json.insert("authentication_public_key_pem", public_key_pem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(d) = fingerprints.decryption() {
|
if let Some(d) = fingerprints.decryption() {
|
||||||
if let Ok(algo) = application_related_data.algorithm_attributes(KeyType::Decryption) {
|
if let Ok(algo) = application_related_data.algorithm_attributes(KeyType::Decryption) {
|
||||||
@@ -108,6 +124,16 @@ impl Command for CommandImpl {
|
|||||||
if json_output {
|
if json_output {
|
||||||
json.insert("encryption_fingerprint", d.to_string());
|
json.insert("encryption_fingerprint", d.to_string());
|
||||||
}
|
}
|
||||||
|
if detail_output {
|
||||||
|
if let Ok(public_key) = trans.public_key(KeyType::Decryption) {
|
||||||
|
if let Some(public_key_pem) = public_key_pem(&public_key) {
|
||||||
|
information!("Encryption public key: {}", public_key_pem.trim());
|
||||||
|
if json_output {
|
||||||
|
json.insert("encryption_public_key_pem", public_key_pem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(s) = fingerprints.signature() {
|
if let Some(s) = fingerprints.signature() {
|
||||||
if let Ok(algo) = application_related_data.algorithm_attributes(KeyType::Signing) {
|
if let Ok(algo) = application_related_data.algorithm_attributes(KeyType::Signing) {
|
||||||
@@ -117,6 +143,16 @@ impl Command for CommandImpl {
|
|||||||
if json_output {
|
if json_output {
|
||||||
json.insert("signature_fingerprint", s.to_string());
|
json.insert("signature_fingerprint", s.to_string());
|
||||||
}
|
}
|
||||||
|
if detail_output {
|
||||||
|
if let Ok(public_key) = trans.public_key(KeyType::Signing) {
|
||||||
|
if let Some(public_key_pem) = public_key_pem(&public_key) {
|
||||||
|
information!("Signature public key: {}", public_key_pem.trim());
|
||||||
|
if json_output {
|
||||||
|
json.insert("signature_public_key_pem", public_key_pem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,3 +165,23 @@ impl Command for CommandImpl {
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn public_key_pem(public_key: &PublicKeyMaterial) -> Option<String> {
|
||||||
|
match public_key {
|
||||||
|
PublicKeyMaterial::R(rsa_pub) => {
|
||||||
|
let rsa_pub_key = Rsa::from_public_components(
|
||||||
|
BigNum::from_slice(rsa_pub.n()).unwrap(),
|
||||||
|
BigNum::from_slice(rsa_pub.v()).unwrap(),
|
||||||
|
);
|
||||||
|
let pub_key_pem_obj = Pem {
|
||||||
|
tag: String::from("PUBLIC KEY"),
|
||||||
|
contents: rsa_pub_key.unwrap().public_key_to_der().unwrap(),
|
||||||
|
};
|
||||||
|
Some(pem::encode(&pub_key_pem_obj))
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
warning!("Not RSA public key: {:?}", public_key);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,7 +35,7 @@ impl Command for CommandImpl {
|
|||||||
let json_output = sub_arg_matches.is_present("json");
|
let json_output = sub_arg_matches.is_present("json");
|
||||||
if json_output { rust_util::util_msg::set_logger_std_out(false); }
|
if json_output { rust_util::util_msg::set_logger_std_out(false); }
|
||||||
|
|
||||||
let pin_opt = sub_arg_matches.value_of("pass").or(sub_arg_matches.value_of("pin"));
|
let pin_opt = sub_arg_matches.value_of("pass").or_else(|| sub_arg_matches.value_of("pin"));
|
||||||
let pin = opt_value_result!(pin_opt, "User pin must be assigned");
|
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()); }
|
if pin.len() < 6 { return simple_error!("User pin length:{}, must >= 6!", pin.len()); }
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ impl Command for CommandImpl {
|
|||||||
rust_util::util_msg::set_logger_std_out(false);
|
rust_util::util_msg::set_logger_std_out(false);
|
||||||
}
|
}
|
||||||
warning!("This feature is not complete");
|
warning!("This feature is not complete");
|
||||||
let pin_opt = sub_arg_matches.value_of("pass").or(sub_arg_matches.value_of("pin"));
|
let pin_opt = sub_arg_matches.value_of("pass").or_else(|| sub_arg_matches.value_of("pin"));
|
||||||
let pin = opt_value_result!(pin_opt, "User pin must be assigned");
|
let pin = opt_value_result!(pin_opt, "User pin must be assigned");
|
||||||
|
|
||||||
let mut yk = opt_result!(YubiKey::open(), "YubiKey not found: {}");
|
let mut yk = opt_result!(YubiKey::open(), "YubiKey not found: {}");
|
||||||
|
|||||||
Reference in New Issue
Block a user