Move get/set_device_info to HIDDevice and remove U2FDeviceInfo status updates

This commit is contained in:
John M. Schanck
2023-06-01 14:53:25 -07:00
committed by John Schanck
parent b444f325d9
commit c19a3ea625
20 changed files with 126 additions and 246 deletions
-12
View File
@@ -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");
}
-24
View File
@@ -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");
}
+2 -25
View File
@@ -20,15 +20,10 @@ fn print_usage(program: &str, opts: Options) {
}
fn interactive_status_callback(status_rx: Receiver<StatusUpdate>) {
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<StatusUpdate>) {
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");
}
-3
View File
@@ -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;
-12
View File
@@ -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");
}
-12
View File
@@ -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");
}
-18
View File
@@ -424,12 +424,6 @@ pub fn register<Dev: FidoDevice>(
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<Dev: FidoDevice>(
}
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
-54
View File
@@ -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(),
)),
);
+1 -11
View File
@@ -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<InteractiveRequest>,
u2ftypes::U2FDeviceInfo,
Option<AuthenticatorInfo>,
),
),
+15 -9
View File
@@ -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<String> {
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 {
+3
View File
@@ -18,6 +18,9 @@ pub trait HIDDevice: FidoDevice + Read + Write {
fn new(parameters: Self::BuildParameters) -> Result<Self, (HIDError, Self::Id)>;
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]);
+15 -9
View File
@@ -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<String> {
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 {
+15 -9
View File
@@ -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<String> {
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 {
+13 -7
View File
@@ -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<String> {
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 {
+3 -5
View File
@@ -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);
+15 -9
View File
@@ -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<String> {
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 {
+15 -9
View File
@@ -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<String> {
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 {
+12 -8
View File
@@ -62,6 +62,14 @@ impl HIDDevice for Device {
fn get_property(&self, prop_name: &str) -> io::Result<String> {
unimplemented!();
}
fn get_device_info(&self) -> U2FDeviceInfo {
unimplemented!();
}
fn set_device_info(&mut self, dev_info: U2FDeviceInfo) {
unimplemented!();
}
}
impl FidoDevice for Device {
@@ -78,6 +86,10 @@ impl FidoDevice for Device {
unimplemented!();
}
fn should_try_ctap2(&self) -> bool {
unimplemented!();
}
fn initialized(&self) -> bool {
unimplemented!();
}
@@ -86,14 +98,6 @@ impl FidoDevice for Device {
unimplemented!()
}
fn get_device_info(&self) -> U2FDeviceInfo {
unimplemented!();
}
fn set_device_info(&mut self, dev_info: U2FDeviceInfo) {
unimplemented!();
}
fn get_authenticator_info(&self) -> Option<&AuthenticatorInfo> {
unimplemented!()
}
+17 -9
View File
@@ -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<String> {
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 {
-1
View File
@@ -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};