Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/ctap2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn main() {
opts.optflag("s", "hmac_secret", "With hmac-secret");
opts.optflag("h", "help", "print this help menu");
opts.optflag("f", "fallback", "Use CTAP1 fallback implementation");
opts.optflag("l", "logging", "Active request/response logging");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => panic!("{}", f.to_string()),
Expand Down Expand Up @@ -81,6 +82,7 @@ fn main() {
let mut chall_bytes = [0u8; 32];
thread_rng().fill_bytes(&mut chall_bytes);

let do_logging = matches.opt_present("logging");
let (status_tx, status_rx) = channel::<StatusUpdate>();
thread::spawn(move || loop {
match status_rx.recv() {
Expand Down Expand Up @@ -139,6 +141,13 @@ fn main() {
Ok(StatusUpdate::LargeBlobData(_, _)) => {
panic!("Unexpected large blob data request")
}
Ok(StatusUpdate::RequestLogging(dir, msg)) => {
if do_logging {
println!("{dir:?} -> ");
println!(" {msg}");
println!("--------------------------------------");
}
}
Err(RecvError) => {
println!("STATUS: end");
return;
Expand Down
23 changes: 20 additions & 3 deletions examples/ctap2_discoverable_creds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ fn register_user(
username: &str,
timeout_ms: u64,
matches: &Matches,
do_logging: bool,
) {
println!();
println!("*********************************************************************");
Expand Down Expand Up @@ -184,6 +185,13 @@ fn register_user(
panic!("Unexpected large blob data request");
}
}
Ok(StatusUpdate::RequestLogging(dir, msg)) => {
if do_logging {
println!("{dir:?} -> ");
println!(" {msg}");
println!("--------------------------------------");
}
}
Err(RecvError) => {
println!("STATUS: end");
return;
Expand Down Expand Up @@ -301,9 +309,10 @@ fn main() {
"SEC",
);
opts.optflag("s", "skip_reg", "Skip registration");
opts.optflag("b", "cred_blob", "With credBlob");
opts.optflag("l", "large_blob_key", "With largeBlobKey-extension");
opts.optflag("b", "cred_blob", "With credBlob-extension");
opts.optflag("k", "large_blob_key", "With largeBlobKey-extension");
opts.optflag("h", "help", "print this help menu");
opts.optflag("l", "logging", "Active request/response logging");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => panic!("{}", f.to_string()),
Expand All @@ -329,9 +338,10 @@ fn main() {
}
};

let do_logging = matches.opt_present("logging");
if !matches.opt_present("skip_reg") {
for username in &["A. User", "A. Nother", "Dr. Who"] {
register_user(&mut manager, username, timeout_ms, &matches)
register_user(&mut manager, username, timeout_ms, &matches, do_logging)
}
}

Expand Down Expand Up @@ -409,6 +419,13 @@ fn main() {
Ok(StatusUpdate::LargeBlobData(..)) => {
panic!("Unexpected large blob data request")
}
Ok(StatusUpdate::RequestLogging(dir, msg)) => {
if do_logging {
println!("{dir:?} -> ");
println!("{msg}");
println!("--------------------------------------");
}
}
Err(RecvError) => {
println!("STATUS: end");
return;
Expand Down
13 changes: 11 additions & 2 deletions examples/interactive_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ fn handle_bio_enrollments(
}
}

fn interactive_status_callback(status_rx: Receiver<StatusUpdate>) {
fn interactive_status_callback(status_rx: Receiver<StatusUpdate>, do_logging: bool) {
let mut tx = None;
let mut auth_info = None;
loop {
Expand Down Expand Up @@ -733,6 +733,13 @@ fn interactive_status_callback(status_rx: Receiver<StatusUpdate>) {
Ok(StatusUpdate::LargeBlobData(_, _)) => {
panic!("Unexpected large blob data request")
}
Ok(StatusUpdate::RequestLogging(dir, msg)) => {
if do_logging {
println!("{dir:?} -> ");
println!(" {msg}");
println!("--------------------------------------");
}
}
Err(RecvError) => {
println!("STATUS: end");
return;
Expand All @@ -755,6 +762,7 @@ fn main() {
"SEC",
);
opts.optflag("h", "help", "print this help menu");
opts.optflag("l", "logging", "Active request/response logging");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => panic!("{}", f.to_string()),
Expand All @@ -780,8 +788,9 @@ fn main() {
}
};

let do_logging = matches.opt_present("logging");
let (status_tx, status_rx) = channel::<StatusUpdate>();
thread::spawn(move || interactive_status_callback(status_rx));
thread::spawn(move || interactive_status_callback(status_rx, do_logging));

let (manage_tx, manage_rx) = channel();
let state_callback =
Expand Down
9 changes: 9 additions & 0 deletions examples/prf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fn main() {
"hmac-secret",
"Return hmac-secret outputs instead of prf outputs (i.e., do not prefix and hash the inputs)",
);
opts.optflag("l", "logging", "Active request/response logging");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => panic!("{}", f.to_string()),
Expand Down Expand Up @@ -93,6 +94,7 @@ fn main() {
println!("Asking a security key to register now...");
let mut chall_bytes = [0u8; 32];
thread_rng().fill_bytes(&mut chall_bytes);
let do_logging = matches.opt_present("logging");

let (status_tx, status_rx) = channel::<StatusUpdate>();
thread::spawn(move || loop {
Expand Down Expand Up @@ -152,6 +154,13 @@ fn main() {
Ok(StatusUpdate::LargeBlobData(..)) => {
panic!("Unexpected large blob data request")
}
Ok(StatusUpdate::RequestLogging(dir, msg)) => {
if do_logging {
println!("{dir:?} -> ");
println!(" {msg}");
println!("--------------------------------------");
}
}
Err(RecvError) => {
println!("STATUS: end");
return;
Expand Down
9 changes: 9 additions & 0 deletions examples/set_pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn main() {
Ok(m) => m,
Err(f) => panic!("{}", f.to_string()),
};
opts.optflag("l", "logging", "Active request/response logging");
if matches.opt_present("help") {
print_usage(&program, opts);
return;
Expand Down Expand Up @@ -62,6 +63,7 @@ fn main() {
return;
}

let do_logging = matches.opt_present("logging");
let (status_tx, status_rx) = channel::<StatusUpdate>();
thread::spawn(move || loop {
match status_rx.recv() {
Expand Down Expand Up @@ -120,6 +122,13 @@ fn main() {
Ok(StatusUpdate::LargeBlobData(_, _)) => {
panic!("Unexpected large blob data request")
}
Ok(StatusUpdate::RequestLogging(dir, msg)) => {
if do_logging {
println!("{dir:?} -> ");
println!(" {msg}");
println!("--------------------------------------");
}
}
Err(RecvError) => {
println!("STATUS: end");
return;
Expand Down
9 changes: 9 additions & 0 deletions examples/test_exclude_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn main() {
Ok(m) => m,
Err(f) => panic!("{}", f.to_string()),
};
opts.optflag("l", "logging", "Active request/response logging");
if matches.opt_present("help") {
print_usage(&program, opts);
return;
Expand Down Expand Up @@ -74,6 +75,7 @@ fn main() {
);
let chall_bytes = Sha256::digest(challenge_str.as_bytes()).into();

let do_logging = matches.opt_present("logging");
let (status_tx, status_rx) = channel::<StatusUpdate>();
thread::spawn(move || loop {
match status_rx.recv() {
Expand Down Expand Up @@ -132,6 +134,13 @@ fn main() {
Ok(StatusUpdate::LargeBlobData(_, _)) => {
panic!("Unexpected large blob data request")
}
Ok(StatusUpdate::RequestLogging(dir, msg)) => {
if do_logging {
println!("{dir:?} -> ");
println!(" {msg}");
println!("--------------------------------------");
}
}
Err(RecvError) => {
println!("STATUS: end");
return;
Expand Down
5 changes: 3 additions & 2 deletions src/authenticatorservice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use crate::ctap2::server::{
use crate::errors::*;
use crate::manager::Manager;
use crate::statecallback::StateCallback;
use serde::Serialize;
use std::sync::{mpsc::Sender, Arc, Mutex};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct RegisterArgs {
pub client_data_hash: [u8; 32],
pub relying_party: RelyingParty,
Expand All @@ -28,7 +29,7 @@ pub struct RegisterArgs {
pub use_ctap1_fallback: bool,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct SignArgs {
pub client_data_hash: [u8; 32],
pub origin: String,
Expand Down
19 changes: 15 additions & 4 deletions src/ctap2/commands/get_assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ impl RequestCtap2 for GetAssertion {
let msg = GetNextAssertion;
// We already have one, so skipping 0
for _ in 1..number_of_credentials {
let assertion = dev.send_cbor(&msg)?;
let assertion = dev.send_cbor(&msg, None)?;
let user_selected = assertion.user_selected;
let large_blob_key = assertion.large_blob_key.clone();
results.push(GetAssertionResult {
Expand Down Expand Up @@ -896,6 +896,7 @@ pub mod test {
use crate::transport::{FidoDevice, FidoDeviceIO, FidoProtocol};
use crate::u2ftypes::U2FDeviceInfo;
use rand::{thread_rng, RngCore};
use std::sync::mpsc::channel;

#[test]
fn test_get_assertion_ctap2() {
Expand Down Expand Up @@ -1056,7 +1057,7 @@ pub mod test {
large_blob_key: None,
large_blob_array: None,
}];
let response = device.send_cbor(&assertion).unwrap();
let response = device.send_cbor(&assertion, None).unwrap();
assert_eq!(response, expected);
}

Expand Down Expand Up @@ -1332,6 +1333,7 @@ pub mod test {
device.set_cid(cid);

// ctap1 request
let (tx, _rx) = channel();
fill_device_ctap1(
&mut device,
cid,
Expand All @@ -1343,6 +1345,7 @@ pub mod test {
&assertion.allow_list,
&assertion.rp,
&assertion.client_data_hash,
&tx,
)
.expect("Did not find a key_handle, even though it should have");
assertion.allow_list = vec![key_handle];
Expand All @@ -1355,7 +1358,7 @@ pub mod test {
// Pre-flighting is not done automatically
fill_device_ctap1(&mut device, cid, U2F_REQUEST_USER_PRESENCE, SW_NO_ERROR);

let response = device.send_ctap1(&assertion).unwrap();
let response = device.send_ctap1(&assertion, None).unwrap();

// Check if response is correct
let expected_auth_data = AuthenticatorData {
Expand Down Expand Up @@ -1424,12 +1427,14 @@ pub mod test {

device.set_cid(cid);

let (tx, _rx) = channel();
assert_matches!(
do_credential_list_filtering_ctap1(
&mut device,
&assertion.allow_list,
&assertion.rp,
&assertion.client_data_hash,
&tx,
),
None
);
Expand All @@ -1447,12 +1452,14 @@ pub mod test {
for allow_list in [vec![], vec![too_long_key_handle.clone(); 5]] {
assertion.allow_list = allow_list;

let (tx, _rx) = channel();
assert_matches!(
do_credential_list_filtering_ctap1(
&mut device,
&assertion.allow_list,
&assertion.rp,
&assertion.client_data_hash,
&tx,
),
None
);
Expand Down Expand Up @@ -1483,11 +1490,13 @@ pub mod test {
U2F_CHECK_IS_REGISTERED,
SW_CONDITIONS_NOT_SATISFIED,
);
let (tx, _rx) = channel();
let key_handle = do_credential_list_filtering_ctap1(
&mut device,
&assertion.allow_list,
&assertion.rp,
&assertion.client_data_hash,
&tx,
)
.expect("Did not find a key_handle, even though it should have");
assertion.allow_list = vec![key_handle];
Expand All @@ -1500,7 +1509,7 @@ pub mod test {
// Pre-flighting is not done automatically
fill_device_ctap1(&mut device, cid, U2F_REQUEST_USER_PRESENCE, SW_NO_ERROR);

let response = device.send_ctap1(&assertion).unwrap();
let response = device.send_ctap1(&assertion, None).unwrap();

// Check if response is correct
let expected_auth_data = AuthenticatorData {
Expand Down Expand Up @@ -1768,12 +1777,14 @@ pub mod test {
msg.extend(&GET_ASSERTION_SAMPLE_RESPONSE_CTAP2[293..]);
device.add_read(&msg, 0);

let (tx, _rx) = channel();
assert_matches!(
do_credential_list_filtering_ctap2(
&mut device,
&assertion.allow_list,
&assertion.rp,
None,
&tx,
),
Ok(..)
);
Expand Down
4 changes: 2 additions & 2 deletions src/ctap2/commands/large_blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ where
length: None,
pin_uv_auth_param: None,
};
let mut segment = dev.send_cbor_cancellable(&cmd, keep_alive)?;
let mut segment = dev.send_cbor_cancellable(&cmd, keep_alive, None)?;
let segment_len = segment.len();
bytes.append(&mut segment);
// Spec:
Expand Down Expand Up @@ -440,7 +440,7 @@ where
pin_uv_auth_param: None,
};
cmd.set_pin_uv_auth_param(pin_uv_auth_token.clone())?;
dev.send_cbor_cancellable(&cmd, keep_alive)?;
dev.send_cbor_cancellable(&cmd, keep_alive, None)?;
offset += chunk_len as u64;
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/ctap2/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub(crate) fn repackage_pin_errors<D: FidoDevice>(
let cmd = GetPinRetries::new();
// Treat any error as if the device returned a valid response without a pinRetries
// field.
let resp = dev.send_cbor(&cmd).unwrap_or_default();
let resp = dev.send_cbor(&cmd, None).unwrap_or_default();
AuthenticatorError::PinError(PinError::InvalidPin(resp.pin_retries))
}
HIDError::Command(CommandError::StatusCode(StatusCode::PinAuthBlocked, _)) => {
Expand All @@ -185,7 +185,7 @@ pub(crate) fn repackage_pin_errors<D: FidoDevice>(
let cmd = GetUvRetries::new();
// Treat any error as if the device returned a valid response without a uvRetries
// field.
let resp = dev.send_cbor(&cmd).unwrap_or_default();
let resp = dev.send_cbor(&cmd, None).unwrap_or_default();
AuthenticatorError::PinError(PinError::InvalidUv(resp.uv_retries))
}
HIDError::Command(CommandError::StatusCode(StatusCode::UvBlocked, _)) => {
Expand Down
Loading