diff --git a/examples/ctap2.rs b/examples/ctap2.rs index 20154e9b..6f50e4e7 100644 --- a/examples/ctap2.rs +++ b/examples/ctap2.rs @@ -87,21 +87,9 @@ fn main() { Ok(StatusUpdate::InteractiveManagement(..)) => { panic!("STATUS: This can't happen when doing non-interactive usage"); } - Ok(StatusUpdate::DeviceAvailable { dev_info }) => { - println!("STATUS: device available: {dev_info}") - } - Ok(StatusUpdate::DeviceUnavailable { dev_info }) => { - println!("STATUS: device unavailable: {dev_info}") - } - Ok(StatusUpdate::Success { dev_info }) => { - println!("STATUS: success using device: {dev_info}"); - } Ok(StatusUpdate::SelectDeviceNotice) => { println!("STATUS: Please select a device by touching one of them."); } - Ok(StatusUpdate::DeviceSelected(dev_info)) => { - println!("STATUS: Continuing with device: {dev_info}"); - } Ok(StatusUpdate::PresenceRequired) => { println!("STATUS: waiting for user presence"); } diff --git a/examples/ctap2_discoverable_creds.rs b/examples/ctap2_discoverable_creds.rs index ea5aa5bf..0ad4daa7 100644 --- a/examples/ctap2_discoverable_creds.rs +++ b/examples/ctap2_discoverable_creds.rs @@ -50,21 +50,9 @@ fn register_user(manager: &mut AuthenticatorService, username: &str, timeout_ms: Ok(StatusUpdate::InteractiveManagement(..)) => { panic!("STATUS: This can't happen when doing non-interactive usage"); } - Ok(StatusUpdate::DeviceAvailable { dev_info }) => { - println!("STATUS: device available: {dev_info}") - } - Ok(StatusUpdate::DeviceUnavailable { dev_info }) => { - println!("STATUS: device unavailable: {dev_info}") - } - Ok(StatusUpdate::Success { dev_info }) => { - println!("STATUS: success using device: {dev_info}"); - } Ok(StatusUpdate::SelectDeviceNotice) => { println!("STATUS: Please select a device by touching one of them."); } - Ok(StatusUpdate::DeviceSelected(dev_info)) => { - println!("STATUS: Continuing with device: {dev_info}"); - } Ok(StatusUpdate::PresenceRequired) => { println!("STATUS: waiting for user presence"); } @@ -246,21 +234,9 @@ fn main() { Ok(StatusUpdate::InteractiveManagement(..)) => { panic!("STATUS: This can't happen when doing non-interactive usage"); } - Ok(StatusUpdate::DeviceAvailable { dev_info }) => { - println!("STATUS: device available: {dev_info}") - } - Ok(StatusUpdate::DeviceUnavailable { dev_info }) => { - println!("STATUS: device unavailable: {dev_info}") - } - Ok(StatusUpdate::Success { dev_info }) => { - println!("STATUS: success using device: {dev_info}"); - } Ok(StatusUpdate::SelectDeviceNotice) => { println!("STATUS: Please select a device by touching one of them."); } - Ok(StatusUpdate::DeviceSelected(dev_info)) => { - println!("STATUS: Continuing with device: {dev_info}"); - } Ok(StatusUpdate::PresenceRequired) => { println!("STATUS: waiting for user presence"); } diff --git a/examples/interactive_management.rs b/examples/interactive_management.rs index 714279fb..3a061cbf 100644 --- a/examples/interactive_management.rs +++ b/examples/interactive_management.rs @@ -20,15 +20,10 @@ fn print_usage(program: &str, opts: Options) { } fn interactive_status_callback(status_rx: Receiver) { - let mut num_of_devices = 0; loop { match status_rx.recv() { - Ok(StatusUpdate::InteractiveManagement((tx, dev_info, auth_info))) => { - debug!( - "STATUS: interactive management: {:#}, {:#?}", - dev_info, auth_info - ); - println!("Device info {:#}", dev_info); + Ok(StatusUpdate::InteractiveManagement((tx, auth_info))) => { + debug!("STATUS: interactive management: {:#?}", auth_info); let mut change_pin = false; if let Some(info) = auth_info { println!("Authenticator Info {:#?}", info); @@ -98,27 +93,9 @@ fn interactive_status_callback(status_rx: Receiver) { println!("Device only supports CTAP1 and can't be managed."); } } - Ok(StatusUpdate::DeviceAvailable { dev_info }) => { - num_of_devices += 1; - debug!( - "STATUS: New device #{} available: {}", - num_of_devices, dev_info - ); - } - Ok(StatusUpdate::DeviceUnavailable { dev_info }) => { - num_of_devices -= 1; - if num_of_devices <= 0 { - println!("No more devices left. Please plug in a device!"); - } - debug!("STATUS: Device became unavailable: {}", dev_info) - } - Ok(StatusUpdate::Success { dev_info }) => { - println!("STATUS: success using device: {}", dev_info); - } Ok(StatusUpdate::SelectDeviceNotice) => { println!("STATUS: Please select a device by touching one of them."); } - Ok(StatusUpdate::DeviceSelected(_dev_info)) => {} Ok(StatusUpdate::PresenceRequired) => { println!("STATUS: waiting for user presence"); } diff --git a/examples/reset.rs b/examples/reset.rs index 1194cb2b..38ab3223 100644 --- a/examples/reset.rs +++ b/examples/reset.rs @@ -105,9 +105,6 @@ fn main() { manager.cancel().unwrap(); return; } - Ok(StatusUpdate::DeviceSelected(dev_info)) => { - println!("STATUS: Continuing with device: {dev_info}"); - } Ok(StatusUpdate::PresenceRequired) => { println!("STATUS: waiting for user presence"); break; diff --git a/examples/set_pin.rs b/examples/set_pin.rs index 18304648..6a2bb065 100644 --- a/examples/set_pin.rs +++ b/examples/set_pin.rs @@ -73,21 +73,9 @@ fn main() { Ok(StatusUpdate::InteractiveManagement(..)) => { panic!("STATUS: This can't happen when doing non-interactive usage"); } - Ok(StatusUpdate::DeviceAvailable { dev_info }) => { - println!("STATUS: device available: {dev_info}") - } - Ok(StatusUpdate::DeviceUnavailable { dev_info }) => { - println!("STATUS: device unavailable: {dev_info}") - } - Ok(StatusUpdate::Success { dev_info }) => { - println!("STATUS: success using device: {dev_info}"); - } Ok(StatusUpdate::SelectDeviceNotice) => { println!("STATUS: Please select a device by touching one of them."); } - Ok(StatusUpdate::DeviceSelected(dev_info)) => { - println!("STATUS: Continuing with device: {dev_info}"); - } Ok(StatusUpdate::PresenceRequired) => { println!("STATUS: waiting for user presence"); } diff --git a/examples/test_exclude_list.rs b/examples/test_exclude_list.rs index ad2b33fe..3c10e7fb 100644 --- a/examples/test_exclude_list.rs +++ b/examples/test_exclude_list.rs @@ -80,21 +80,9 @@ fn main() { Ok(StatusUpdate::InteractiveManagement(..)) => { panic!("STATUS: This can't happen when doing non-interactive usage"); } - Ok(StatusUpdate::DeviceAvailable { dev_info }) => { - println!("STATUS: device available: {dev_info}") - } - Ok(StatusUpdate::DeviceUnavailable { dev_info }) => { - println!("STATUS: device unavailable: {dev_info}") - } - Ok(StatusUpdate::Success { dev_info }) => { - println!("STATUS: success using device: {dev_info}"); - } Ok(StatusUpdate::SelectDeviceNotice) => { println!("STATUS: Please select a device by touching one of them."); } - Ok(StatusUpdate::DeviceSelected(dev_info)) => { - println!("STATUS: Continuing with device: {dev_info}"); - } Ok(StatusUpdate::PresenceRequired) => { println!("STATUS: waiting for user presence"); } diff --git a/src/ctap2/mod.rs b/src/ctap2/mod.rs index 0454d47b..27639c2d 100644 --- a/src/ctap2/mod.rs +++ b/src/ctap2/mod.rs @@ -424,12 +424,6 @@ pub fn register( let resp = dev.send_msg_cancellable(&makecred, alive); match resp { Ok(MakeCredentialsResult(attestation)) => { - send_status( - &status, - crate::StatusUpdate::Success { - dev_info: dev.get_device_info(), - }, - ); callback.call(Ok(RegisterResult::CTAP2(attestation))); return true; } @@ -625,12 +619,6 @@ pub fn sign( } match resp { Ok(assertions) => { - send_status( - &status, - crate::StatusUpdate::Success { - dev_info: dev.get_device_info(), - }, - ); callback.call(Ok(SignResult::CTAP2(assertions))); return true; } @@ -696,12 +684,6 @@ pub fn reset_helper( send_status(&status, crate::StatusUpdate::PresenceRequired); let resp = dev.send_cbor_cancellable(&reset, keep_alive); if resp.is_ok() { - send_status( - &status, - crate::StatusUpdate::Success { - dev_info: dev.get_device_info(), - }, - ); // The DeviceSelector could already be dead, but it might also wait // for us to respond, in order to cancel all other tokens in case // we skipped the "blinking"-action and went straight for the actual diff --git a/src/statemachine.rs b/src/statemachine.rs index 665af260..c009d2d4 100644 --- a/src/statemachine.rs +++ b/src/statemachine.rs @@ -104,12 +104,6 @@ impl StateMachine { selector .send(DeviceSelectorEvent::ImAToken((dev.id(), tx))) .ok()?; - send_status( - status, - crate::StatusUpdate::DeviceAvailable { - dev_info: dev.get_device_info(), - }, - ); // We can be cancelled from the user (through keep_alive()) or from the device selector // (through a DeviceCommand::Cancel on rx). We'll combine those signals into a single @@ -130,11 +124,6 @@ impl StateMachine { selector .send(DeviceSelectorEvent::SelectedToken(dev.id())) .ok()?; - - send_status( - status, - crate::StatusUpdate::DeviceSelected(dev.get_device_info()), - ); } BlinkResult::Cancelled => { info!("Device {:?} was not selected", dev.id()); @@ -148,20 +137,10 @@ impl StateMachine { } Ok(DeviceCommand::Removed) => { info!("Device {:?} was removed", dev.id()); - send_status( - status, - crate::StatusUpdate::DeviceUnavailable { - dev_info: dev.get_device_info(), - }, - ); return None; } Ok(DeviceCommand::Continue) => { // Just continue - send_status( - status, - crate::StatusUpdate::DeviceSelected(dev.get_device_info()), - ); } Err(_) => { warn!("Error when trying to receive messages from DeviceSelector! Exiting."); @@ -432,13 +411,6 @@ impl StateMachine { return; } - send_status( - &status, - crate::StatusUpdate::DeviceAvailable { - dev_info: dev.get_device_info(), - }, - ); - // Iterate the exclude list and see if there are any matches. // If so, we'll keep polling the device anyway to test for user // consent, to be consistent with CTAP2 device behavior. @@ -476,8 +448,6 @@ impl StateMachine { break; } }; - let dev_info = dev.get_device_info(); - send_status(&status, crate::StatusUpdate::Success { dev_info }); callback.call(Ok(RegisterResult::CTAP2(result))); break; } @@ -485,13 +455,6 @@ impl StateMachine { // Sleep a bit before trying again. thread::sleep(Duration::from_millis(100)); } - - send_status( - &status, - crate::StatusUpdate::DeviceUnavailable { - dev_info: dev.get_device_info(), - }, - ); }, ); @@ -566,13 +529,6 @@ impl StateMachine { return; } - send_status( - &status, - crate::StatusUpdate::DeviceAvailable { - dev_info: dev.get_device_info(), - }, - ); - send_status(&status, crate::StatusUpdate::PresenceRequired); 'outer: while alive() { @@ -611,8 +567,6 @@ impl StateMachine { break 'outer; } }; - let dev_info = dev.get_device_info(); - send_status(&status, crate::StatusUpdate::Success { dev_info }); callback.call(Ok(SignResult::CTAP2(result))); break 'outer; } @@ -622,13 +576,6 @@ impl StateMachine { // Sleep a bit before trying again. thread::sleep(Duration::from_millis(100)); } - - send_status( - &status, - crate::StatusUpdate::DeviceUnavailable { - dev_info: dev.get_device_info(), - }, - ); }, ); @@ -673,7 +620,6 @@ impl StateMachine { &status, crate::StatusUpdate::InteractiveManagement(( tx, - dev.get_device_info(), dev.get_authenticator_info().cloned(), )), ); diff --git a/src/status_update.rs b/src/status_update.rs index f01cbd0c..e0e1d13b 100644 --- a/src/status_update.rs +++ b/src/status_update.rs @@ -1,4 +1,4 @@ -use super::{u2ftypes, Pin}; +use super::Pin; use crate::ctap2::commands::get_info::AuthenticatorInfo; use serde::{Deserialize, Serialize as DeriveSer, Serializer}; use std::sync::mpsc::Sender; @@ -55,27 +55,17 @@ pub enum StatusPinUv { #[derive(Debug)] pub enum StatusUpdate { - /// Device found - DeviceAvailable { dev_info: u2ftypes::U2FDeviceInfo }, - /// Device got removed - DeviceUnavailable { dev_info: u2ftypes::U2FDeviceInfo }, /// We're waiting for the user to touch their token PresenceRequired, - /// We successfully finished the register or sign request - Success { dev_info: u2ftypes::U2FDeviceInfo }, /// Sent if a PIN is needed (or was wrong), or some other kind of PIN-related /// error occurred. The Sender is for sending back a PIN (if needed). PinUvError(StatusPinUv), /// Sent, if multiple devices are found and the user has to select one SelectDeviceNotice, - /// Sent, once a device was selected (either automatically or by user-interaction) - /// and the register or signing process continues with this device - DeviceSelected(u2ftypes::U2FDeviceInfo), /// Sent when a token was selected for interactive management InteractiveManagement( ( Sender, - u2ftypes::U2FDeviceInfo, Option, ), ), diff --git a/src/transport/freebsd/device.rs b/src/transport/freebsd/device.rs index 1c859b56..89301ede 100644 --- a/src/transport/freebsd/device.rs +++ b/src/transport/freebsd/device.rs @@ -4,7 +4,7 @@ extern crate libc; -use crate::consts::{CID_BROADCAST, MAX_HID_RPT_SIZE}; +use crate::consts::{Capability, CID_BROADCAST, MAX_HID_RPT_SIZE}; use crate::ctap2::commands::get_info::AuthenticatorInfo; use crate::transport::hid::HIDDevice; use crate::transport::platform::uhid; @@ -169,6 +169,16 @@ impl HIDDevice for Device { fn get_property(&self, _prop_name: &str) -> io::Result { Err(io::Error::new(io::ErrorKind::Other, "Not implemented")) } + + fn get_device_info(&self) -> U2FDeviceInfo { + // unwrap is okay, as dev_info must have already been set, else + // a programmer error + self.dev_info.clone().unwrap() + } + + fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { + self.dev_info = Some(dev_info); + } } impl FidoDevice for Device { @@ -185,14 +195,10 @@ impl FidoDevice for Device { HIDDevice::sendrecv(self, cmd, send, keep_alive) } - fn get_device_info(&self) -> U2FDeviceInfo { - // unwrap is okay, as dev_info must have already been set, else - // a programmer error - self.dev_info.clone().unwrap() - } - - fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { - self.dev_info = Some(dev_info); + fn should_try_ctap2(&self) -> bool { + HIDDevice::get_device_info(self) + .cap_flags + .contains(Capability::CBOR) } fn initialized(&self) -> bool { diff --git a/src/transport/hid.rs b/src/transport/hid.rs index eebb237a..c1ddafb0 100644 --- a/src/transport/hid.rs +++ b/src/transport/hid.rs @@ -18,6 +18,9 @@ pub trait HIDDevice: FidoDevice + Read + Write { fn new(parameters: Self::BuildParameters) -> Result; fn id(&self) -> Self::Id; + fn get_device_info(&self) -> U2FDeviceInfo; + fn set_device_info(&mut self, dev_info: U2FDeviceInfo); + // Channel ID management fn get_cid(&self) -> &[u8; 4]; fn set_cid(&mut self, cid: [u8; 4]); diff --git a/src/transport/linux/device.rs b/src/transport/linux/device.rs index 2ad23ada..e58c2911 100644 --- a/src/transport/linux/device.rs +++ b/src/transport/linux/device.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ extern crate libc; -use crate::consts::CID_BROADCAST; +use crate::consts::{Capability, CID_BROADCAST}; use crate::ctap2::commands::get_info::AuthenticatorInfo; use crate::transport::hid::HIDDevice; use crate::transport::platform::{hidraw, monitor}; @@ -121,6 +121,16 @@ impl HIDDevice for Device { fn get_property(&self, prop_name: &str) -> io::Result { monitor::get_property_linux(&self.path, prop_name) } + + fn get_device_info(&self) -> U2FDeviceInfo { + // unwrap is okay, as dev_info must have already been set, else + // a programmer error + self.dev_info.clone().unwrap() + } + + fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { + self.dev_info = Some(dev_info); + } } impl FidoDevice for Device { @@ -137,14 +147,10 @@ impl FidoDevice for Device { HIDDevice::sendrecv(self, cmd, send, keep_alive) } - fn get_device_info(&self) -> U2FDeviceInfo { - // unwrap is okay, as dev_info must have already been set, else - // a programmer error - self.dev_info.clone().unwrap() - } - - fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { - self.dev_info = Some(dev_info); + fn should_try_ctap2(&self) -> bool { + HIDDevice::get_device_info(self) + .cap_flags + .contains(Capability::CBOR) } fn initialized(&self) -> bool { diff --git a/src/transport/macos/device.rs b/src/transport/macos/device.rs index 7730b541..86ed09db 100644 --- a/src/transport/macos/device.rs +++ b/src/transport/macos/device.rs @@ -4,7 +4,7 @@ extern crate log; -use crate::consts::{CID_BROADCAST, MAX_HID_RPT_SIZE}; +use crate::consts::{Capability, CID_BROADCAST, MAX_HID_RPT_SIZE}; use crate::ctap2::commands::get_info::AuthenticatorInfo; use crate::transport::hid::HIDDevice; use crate::transport::platform::iokit::*; @@ -169,6 +169,16 @@ impl HIDDevice for Device { fn get_property(&self, prop_name: &str) -> io::Result { unsafe { self.get_property_macos(prop_name) } } + + fn get_device_info(&self) -> U2FDeviceInfo { + // unwrap is okay, as dev_info must have already been set, else + // a programmer error + self.dev_info.clone().unwrap() + } + + fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { + self.dev_info = Some(dev_info); + } } impl FidoDevice for Device { @@ -185,14 +195,10 @@ impl FidoDevice for Device { HIDDevice::sendrecv(self, cmd, send, keep_alive) } - fn get_device_info(&self) -> U2FDeviceInfo { - // unwrap is okay, as dev_info must have already been set, else - // a programmer error - self.dev_info.clone().unwrap() - } - - fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { - self.dev_info = Some(dev_info); + fn should_try_ctap2(&self) -> bool { + HIDDevice::get_device_info(self) + .cap_flags + .contains(Capability::CBOR) } fn initialized(&self) -> bool { diff --git a/src/transport/mock/device.rs b/src/transport/mock/device.rs index 561a0492..0f98d3de 100644 --- a/src/transport/mock/device.rs +++ b/src/transport/mock/device.rs @@ -1,7 +1,7 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use crate::consts::{HIDCmd, CID_BROADCAST}; +use crate::consts::{Capability, HIDCmd, CID_BROADCAST}; use crate::crypto::SharedSecret; use crate::ctap2::commands::get_info::AuthenticatorInfo; use crate::transport::device_selector::DeviceCommand; @@ -144,6 +144,14 @@ impl HIDDevice for Device { fn get_property(&self, prop_name: &str) -> io::Result { Ok(format!("{prop_name} not implemented")) } + + fn get_device_info(&self) -> U2FDeviceInfo { + self.dev_info.clone().unwrap() + } + + fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { + self.dev_info = Some(dev_info); + } } impl FidoDevice for Device { @@ -160,12 +168,10 @@ impl FidoDevice for Device { HIDDevice::sendrecv(self, cmd, send, keep_alive) } - fn get_device_info(&self) -> U2FDeviceInfo { - self.dev_info.clone().unwrap() - } - - fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { - self.dev_info = Some(dev_info); + fn should_try_ctap2(&self) -> bool { + HIDDevice::get_device_info(self) + .cap_flags + .contains(Capability::CBOR) } fn initialized(&self) -> bool { diff --git a/src/transport/mod.rs b/src/transport/mod.rs index e268c080..e7054734 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -1,4 +1,4 @@ -use crate::consts::{Capability, HIDCmd}; +use crate::consts::HIDCmd; use crate::crypto::{PinUvAuthProtocol, PinUvAuthToken, SharedSecret}; use crate::ctap2::commands::client_pin::{ GetKeyAgreement, GetPinToken, GetPinUvAuthTokenUsingPinWithPermissions, @@ -13,7 +13,6 @@ use crate::ctap2::commands::{ }; use crate::transport::device_selector::BlinkResult; use crate::transport::errors::{ApduErrorStatus, HIDError}; -use crate::u2ftypes::U2FDeviceInfo; use crate::util::io_err; use crate::Pin; use std::convert::TryFrom; @@ -96,10 +95,9 @@ where // Check if the device is actually a token fn is_u2f(&mut self) -> bool; + fn should_try_ctap2(&self) -> bool; fn get_authenticator_info(&self) -> Option<&AuthenticatorInfo>; fn set_authenticator_info(&mut self, authenticator_info: AuthenticatorInfo); - fn get_device_info(&self) -> U2FDeviceInfo; - fn set_device_info(&mut self, dev_info: U2FDeviceInfo); fn set_shared_secret(&mut self, secret: SharedSecret); fn get_shared_secret(&self) -> Option<&SharedSecret>; @@ -201,7 +199,7 @@ where // for CTAP2 support by sending an authenticatorGetInfo command. // We're not aware of any CTAP2 devices that fail to set the CBOR // capability flag, but we may need to rework this in the future. - if self.get_device_info().cap_flags.contains(Capability::CBOR) { + if self.should_try_ctap2() { let command = GetInfo::default(); if let Ok(info) = self.send_cbor(&command) { debug!("{:?}", info); diff --git a/src/transport/netbsd/device.rs b/src/transport/netbsd/device.rs index f8c70621..dbd34814 100644 --- a/src/transport/netbsd/device.rs +++ b/src/transport/netbsd/device.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ extern crate libc; -use crate::consts::{CID_BROADCAST, MAX_HID_RPT_SIZE}; +use crate::consts::{Capability, CID_BROADCAST, MAX_HID_RPT_SIZE}; use crate::ctap2::commands::get_info::AuthenticatorInfo; use crate::transport::hid::HIDDevice; use crate::transport::platform::fd::Fd; @@ -171,6 +171,16 @@ impl HIDDevice for Device { fn get_property(&self, _prop_name: &str) -> io::Result { Err(io::Error::new(io::ErrorKind::Other, "Not implemented")) } + + fn get_device_info(&self) -> U2FDeviceInfo { + // unwrap is okay, as dev_info must have already been set, else + // a programmer error + self.dev_info.clone().unwrap() + } + + fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { + self.dev_info = Some(dev_info); + } } impl FidoDevice for Device { @@ -187,14 +197,10 @@ impl FidoDevice for Device { HIDDevice::sendrecv(self, cmd, send, keep_alive) } - fn get_device_info(&self) -> U2FDeviceInfo { - // unwrap is okay, as dev_info must have already been set, else - // a programmer error - self.dev_info.clone().unwrap() - } - - fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { - self.dev_info = Some(dev_info); + fn should_try_ctap2(&self) -> bool { + HIDDevice::get_device_info(self) + .cap_flags + .contains(Capability::CBOR) } fn initialized(&self) -> bool { diff --git a/src/transport/openbsd/device.rs b/src/transport/openbsd/device.rs index 1b0f7ced..b977d961 100644 --- a/src/transport/openbsd/device.rs +++ b/src/transport/openbsd/device.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ extern crate libc; -use crate::consts::{CID_BROADCAST, MAX_HID_RPT_SIZE}; +use crate::consts::{Capability, CID_BROADCAST, MAX_HID_RPT_SIZE}; use crate::ctap2::commands::get_info::AuthenticatorInfo; use crate::transport::hid::HIDDevice; use crate::transport::platform::monitor::WrappedOpenDevice; @@ -152,6 +152,16 @@ impl HIDDevice for Device { fn get_property(&self, _prop_name: &str) -> io::Result { Err(io::Error::new(io::ErrorKind::Other, "Not implemented")) } + + fn get_device_info(&self) -> U2FDeviceInfo { + // unwrap is okay, as dev_info must have already been set, else + // a programmer error + self.dev_info.clone().unwrap() + } + + fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { + self.dev_info = Some(dev_info); + } } impl FidoDevice for Device { @@ -168,14 +178,10 @@ impl FidoDevice for Device { HIDDevice::sendrecv(self, cmd, send, keep_alive) } - fn get_device_info(&self) -> U2FDeviceInfo { - // unwrap is okay, as dev_info must have already been set, else - // a programmer error - self.dev_info.clone().unwrap() - } - - fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { - self.dev_info = Some(dev_info); + fn should_try_ctap2(&self) -> bool { + HIDDevice::get_device_info(self) + .cap_flags + .contains(Capability::CBOR) } fn initialized(&self) -> bool { diff --git a/src/transport/stub/device.rs b/src/transport/stub/device.rs index 87ad27aa..1e8b7ee7 100644 --- a/src/transport/stub/device.rs +++ b/src/transport/stub/device.rs @@ -62,6 +62,14 @@ impl HIDDevice for Device { fn get_property(&self, prop_name: &str) -> io::Result { unimplemented!(); } + + fn get_device_info(&self) -> U2FDeviceInfo { + unimplemented!(); + } + + fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { + unimplemented!(); + } } impl FidoDevice for Device { @@ -78,20 +86,16 @@ impl FidoDevice for Device { unimplemented!(); } - fn initialized(&self) -> bool { + fn should_try_ctap2(&self) -> bool { unimplemented!(); } - fn is_u2f(&mut self) -> bool { - unimplemented!() - } - - fn get_device_info(&self) -> U2FDeviceInfo { + fn initialized(&self) -> bool { unimplemented!(); } - fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { - unimplemented!(); + fn is_u2f(&mut self) -> bool { + unimplemented!() } fn get_authenticator_info(&self) -> Option<&AuthenticatorInfo> { diff --git a/src/transport/windows/device.rs b/src/transport/windows/device.rs index 054de9ca..12bb4929 100644 --- a/src/transport/windows/device.rs +++ b/src/transport/windows/device.rs @@ -3,7 +3,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use super::winapi::DeviceCapabilities; -use crate::consts::{CID_BROADCAST, FIDO_USAGE_PAGE, FIDO_USAGE_U2FHID, MAX_HID_RPT_SIZE}; +use crate::consts::{ + Capability, CID_BROADCAST, FIDO_USAGE_PAGE, FIDO_USAGE_U2FHID, MAX_HID_RPT_SIZE, +}; use crate::ctap2::commands::get_info::AuthenticatorInfo; use crate::transport::hid::HIDDevice; use crate::transport::{FidoDevice, HIDCmd, HIDError, Nonce, SharedSecret}; @@ -108,6 +110,16 @@ impl HIDDevice for Device { fn get_property(&self, _prop_name: &str) -> io::Result { Err(io::Error::new(io::ErrorKind::Other, "Not implemented")) } + + fn get_device_info(&self) -> U2FDeviceInfo { + // unwrap is okay, as dev_info must have already been set, else + // a programmer error + self.dev_info.clone().unwrap() + } + + fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { + self.dev_info = Some(dev_info); + } } impl FidoDevice for Device { @@ -124,14 +136,10 @@ impl FidoDevice for Device { HIDDevice::sendrecv(self, cmd, send, keep_alive) } - fn get_device_info(&self) -> U2FDeviceInfo { - // unwrap is okay, as dev_info must have already been set, else - // a programmer error - self.dev_info.clone().unwrap() - } - - fn set_device_info(&mut self, dev_info: U2FDeviceInfo) { - self.dev_info = Some(dev_info); + fn should_try_ctap2(&self) -> bool { + HIDDevice::get_device_info(self) + .cap_flags + .contains(Capability::CBOR) } fn initialized(&self) -> bool { diff --git a/src/u2fprotocol.rs b/src/u2fprotocol.rs index 33f401d6..d6074225 100644 --- a/src/u2fprotocol.rs +++ b/src/u2fprotocol.rs @@ -223,7 +223,6 @@ pub(crate) mod tests { use crate::consts::{Capability, HIDCmd, CID_BROADCAST, SW_NO_ERROR}; use crate::transport::device_selector::Device; use crate::transport::hid::HIDDevice; - use crate::transport::FidoDevice; use crate::u2ftypes::U2FDeviceInfo; use rand::{thread_rng, RngCore};