chore: chall, chall-config

This commit is contained in:
2022-03-27 13:00:51 +08:00
parent d36aca00a0
commit c9b9607eab
2 changed files with 9 additions and 10 deletions

View File

@@ -12,7 +12,7 @@ impl Command for CommandImpl {
fn name(&self) -> &str { "chall" }
fn subcommand<'a>(&self) -> App<'a, 'a> {
SubCommand::with_name(self.name()).about("Yubikey challenge-response hmac")
SubCommand::with_name(self.name()).about("YubiKey challenge-response HMAC")
.arg(Arg::with_name("challenge").short("c").long("challenge").takes_value(true).help("Challenge"))
.arg(Arg::with_name("challenge-hex").short("x").long("challenge-hex").takes_value(true).help("Challenge HEX"))
.arg(Arg::with_name("sha256").short("2").long("sha256").help("Output SHA256"))
@@ -28,14 +28,13 @@ impl Command for CommandImpl {
let sha256_output = sub_arg_matches.is_present("sha256");
let sha384_output = sub_arg_matches.is_present("sha384");
let sha512_output = sub_arg_matches.is_present("sha512");
let challenge_bytes: Vec<u8>;
if let Some(challenge) = sub_arg_matches.value_of("challenge") {
challenge_bytes = challenge.as_bytes().to_vec();
let challenge_bytes: Vec<u8> = if let Some(challenge) = sub_arg_matches.value_of("challenge") {
challenge.as_bytes().to_vec()
} else if let Some(challenge_hex) = sub_arg_matches.value_of("challenge-hex") {
challenge_bytes = opt_result!(hex::decode(challenge_hex), "Decode challenge hex: {}, failed: {}", challenge_hex);
opt_result!(hex::decode(challenge_hex), "Decode challenge hex: {}, failed: {}", challenge_hex)
} else {
return simple_error!("Challenge must assigned");
}
};
// Challenge can not be greater than 64 bytes
if challenge_bytes.len() > 64 {
@@ -81,7 +80,7 @@ impl Command for CommandImpl {
hex_sha512.map(|hex_sha512| success!("Response SHA512 HEX: {}", hex::encode(hex_sha512)));
}
} else {
warning!("Yubikey not found");
warning!("YubiKey not found");
}
Ok(None)

View File

@@ -11,10 +11,10 @@ impl Command for CommandImpl {
fn name(&self) -> &str { "chall-config" }
fn subcommand<'a>(&self) -> App<'a, 'a> {
SubCommand::with_name(self.name()).about("Yubikey challenge-response hmac config")
SubCommand::with_name(self.name()).about("YubiKey challenge-response HMAC config")
.arg(Arg::with_name("secret").short("s").long("secret").takes_value(true).help("Secret"))
.arg(Arg::with_name("secret-hex").short("x").long("secret-hex").takes_value(true).help("Secret HEX"))
.arg(Arg::with_name("yes-config-chall").long("yes-config-chall").help("Config chall key"))
.arg(Arg::with_name("yes-config-chall").long("yes-config-chall").help("Config challenge-response key"))
}
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
@@ -55,7 +55,7 @@ impl Command for CommandImpl {
success!("Device configured");
}
} else {
warning!("Yubikey not found");
warning!("YubiKey not found");
}
Ok(None)