feat: v1.1.16
This commit is contained in:
14
src/fido.rs
14
src/fido.rs
@@ -1,6 +1,7 @@
|
||||
use std::fmt;
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::thread;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use authenticator::{RegisterResult, StatusUpdate};
|
||||
use base64::URL_SAFE_NO_PAD;
|
||||
@@ -95,9 +96,9 @@ pub struct U2fV2Challenge {
|
||||
}
|
||||
|
||||
impl U2fV2Challenge {
|
||||
pub fn new_challenge(challenge_hex: Option<&str>, app_id: &str) -> XResult<U2fV2Challenge> {
|
||||
pub fn new_challenge(challenge_hex: Option<&str>, app_id: &str, with_time_stamp_prefix: bool) -> XResult<U2fV2Challenge> {
|
||||
Ok(match challenge_hex {
|
||||
None => U2fV2Challenge::new_random(app_id),
|
||||
None => U2fV2Challenge::new_random(app_id, with_time_stamp_prefix),
|
||||
Some(challenge_hex) => {
|
||||
let challenge_bytes = opt_result!(hex::decode(challenge_hex), "Decode challenge hex failed: {}");
|
||||
let challenge = base64::encode_config(&challenge_bytes, base64::URL_SAFE_NO_PAD);
|
||||
@@ -106,13 +107,20 @@ impl U2fV2Challenge {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_random<S>(app_id: S) -> Self where S: Into<String> {
|
||||
pub fn new_random<S>(app_id: S, with_time_stamp_prefix: bool) -> Self where S: Into<String> {
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut rand_bytes = [0_u8; 32];
|
||||
for c in &mut rand_bytes {
|
||||
let b: u8 = rng.gen();
|
||||
*c = b;
|
||||
}
|
||||
if with_time_stamp_prefix {
|
||||
let timestamp = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis() as u64;
|
||||
let timestamp_be_bytes = timestamp.to_be_bytes();
|
||||
for i in 0..8 {
|
||||
rand_bytes[i] = timestamp_be_bytes[i];
|
||||
}
|
||||
}
|
||||
|
||||
let challenge = base64::encode_config(&rand_bytes, URL_SAFE_NO_PAD);
|
||||
Self::new(challenge, app_id)
|
||||
|
||||
Reference in New Issue
Block a user