feat: v1.1.16

This commit is contained in:
2022-04-12 22:45:28 +08:00
parent 2f0d4d6e8a
commit 20754c119e
5 changed files with 60 additions and 35 deletions

View File

@@ -28,6 +28,7 @@ impl Command for CommandImpl {
.arg(Arg::with_name("timeout").short("t").long("timeout").default_value("30").help("Timeout in seconds"))
.arg(Arg::with_name("public-key-hex").long("public-key-hex").takes_value(true).help("Public key hex"))
.arg(Arg::with_name("challenge").long("challenge").takes_value(true).help("Challenge HEX"))
.arg(Arg::with_name("challenge-with-timestamp-prefix").long("challenge-with-timestamp-prefix").help("Challenge with timestamp prefix"))
.arg(Arg::with_name("key-handle").short("k").long("key-handle").takes_value(true).multiple(true).help("Key handle"))
.arg(Arg::with_name("json").long("json").help("JSON output"))
}
@@ -63,8 +64,9 @@ impl Command for CommandImpl {
sign_tx.send(rv).unwrap();
}));
let u2fv2_challenge = U2fV2Challenge::new_challenge(sub_arg_matches.value_of("challenge"), app_id)?;
let challenge_hex = sub_arg_matches.value_of("challenge");
let challenge_with_timestamp_prefix = sub_arg_matches.is_present("challenge-with-timestamp-prefix");
let u2fv2_challenge = U2fV2Challenge::new_challenge(challenge_hex, app_id, challenge_with_timestamp_prefix)?;
let u2fv2_challenge_str = u2fv2_challenge.to_json();
let chall_bytes = digest::sha256(&u2fv2_challenge_str);
@@ -99,6 +101,8 @@ impl Command for CommandImpl {
let client_data = u2fv2_challenge_str.as_bytes().to_vec();
let app_id_hash = sha256(app_id.as_bytes());
let client_data_hash = sha256(&client_data[..]);
let counter_u32 = u32::from_be_bytes([counter[0], counter[1], counter[2], counter[3]]);
// application (32B) + user presence (1B) + counter (4B) + client data hash (32B)
let mut signed_message = Vec::with_capacity(128);
signed_message.extend_from_slice(&app_id_hash);
signed_message.push(*user_presence_flag);
@@ -117,15 +121,18 @@ impl Command for CommandImpl {
json.insert("signed_message", hex::encode(&signed_message));
json.insert("key_handle", hex::encode(&handle_used));
json.insert("sign_data", hex::encode(&sign_data));
json.insert("user_presence_flag", format!("{}", *user_presence_flag));
json.insert("counter", format!("{}", counter_u32));
} else {
information!("Sign challenge: {}", u2fv2_challenge_str);
information!("Sign challenge base64: {}", base64::encode(&u2fv2_challenge_str));
information!("Sign result : {}", base64::encode(&sign_data));
information!("- presence : {}", user_presence_flag);
information!("- counter : {}", u32::from_be_bytes([counter[0], counter[1], counter[2], counter[3]]));
information!("- counter : {}", counter_u32);
information!("- signature: {}", hex::encode(&signature));
// success!("Key handle used: {}", base64::encode(&handle_used));
information!("Key handle: {}", hex::encode(&handle_used));
information!("Signed message: {}", hex::encode(&signed_message));
}
if let Some(public_key_hex) = sub_arg_matches.value_of("public-key-hex") {
@@ -134,8 +141,6 @@ impl Command for CommandImpl {
json.insert("pub_key", hex::encode(&public_key));
} else {
information!("Public key: {}", hex::encode(&public_key));
information!("Signed message: {}", hex::encode(&signed_message));
let authorization_result = u2f::authorization::parse_sign_response(
app_id.to_string(),
client_data,