feat: 1.10.21, add hmac-encrypt, hmac-decrypt

This commit is contained in:
2025-03-23 18:23:36 +08:00
parent 31e710d779
commit ea0b091414
8 changed files with 262 additions and 34 deletions

View File

@@ -1,10 +1,6 @@
use std::ops::Deref;
use clap::{App, Arg, ArgMatches, SubCommand};
use rust_util::util_clap::{Command, CommandError};
use rust_util::util_msg;
use yubico_manager::config::{Config, Mode, Slot};
use yubico_manager::Yubico;
use crate::hmacutil;
@@ -29,28 +25,8 @@ impl Command for CommandImpl {
if json_output { util_msg::set_logger_std_out(false); }
let challenge_bytes = hmacutil::get_challenge_bytes(sub_arg_matches)?;
let mut yubi = Yubico::new();
let device = match yubi.find_yubikey() {
Ok(device) => device,
Err(_) => {
warning!("YubiKey not found");
return Ok(Some(1));
}
};
success!("Found key, Vendor ID: {:?}, Product ID: {:?}", device.vendor_id, device.product_id);
let config = Config::default()
.set_vendor_id(device.vendor_id)
.set_product_id(device.product_id)
.set_variable_size(true)
.set_mode(Mode::Sha1)
.set_slot(Slot::Slot2);
// In HMAC Mode, the result will always be the SAME for the SAME provided challenge
let hmac_result = opt_result!(yubi.challenge_response_hmac(&challenge_bytes, config), "Challenge HMAC failed: {}");
hmacutil::output_hmac_result(sub_arg_matches, json_output, challenge_bytes, hmac_result.deref());
let hmac_result = hmacutil::compute_yubikey_hmac(&challenge_bytes)?;
hmacutil::output_hmac_result(sub_arg_matches, json_output, challenge_bytes, &hmac_result);
Ok(None)
}