Move protocol-specific user presence checking code from Env to CTAP library (#501)
* Common duration type for ctap library independent of TockOS * Implement Env-specific ctap-hid channels for I/O Common I/O Status, Error and Result types * Move common user presence checking code to ctap library * Move CtapHidChannel and UserPresence traits, with their accompanying types to separate API mods. Remove Default implementations of methods in these traits, to keep all implementation details inside of concrete Env types. Rename methods in UserPresence trait, for better readability. Remove duplicate code for finding appropriate HID channel for given transport. Rework check_user_presence() function so that there's no more need for quick_check() method in UserPresence trait. To short-circuit user presence check, Env implementation may use wait_with_timeout() method. * Fix button press wait with zero timeout for TockEnv * Fix formatting * Remove type for duration, use embedded_time::duration::Milliseconds directly, for better readability. Treat any unconfirmed result of user presence check as an error, which maps more naturally to CTAP spec status codes. Remove unneeded underscores in trait definition. Store usb endpoint directly, in TockEnv channels, to avoid unneeded conversions. * No need for separate error type for send_keepalive_up_needed() * Document UserPresence trait and types. Remove unused parameters in UserPresence trait's methods. Add conversion function from UserPresence errors to Ctap2 status codes. Do not check button status when tock user presence wait is called with zero timeout. * Make test environment always report success sending data * Rename CtapHidChannel to HidConnection, rename *_hid_channel -> *_hid_connection, for clarity. Use "Channel" to refer to the logical connection from authenticator to one client, and use "Connection" to refer to physical connection of authenticator to platform, on which clients run. Remove channel parameter from user presence API, it's not needed. * Remove duplicate comments. Co-authored-by: kaczmarczyck <43844792+kaczmarczyck@users.noreply.github.com>
This commit is contained in:
19
src/env/mod.rs
vendored
19
src/env/mod.rs
vendored
@@ -1,8 +1,8 @@
|
||||
use crate::api::connection::HidConnection;
|
||||
use crate::api::customization::Customization;
|
||||
use crate::api::firmware_protection::FirmwareProtection;
|
||||
use crate::api::upgrade_storage::UpgradeStorage;
|
||||
use crate::ctap::status_code::Ctap2StatusCode;
|
||||
use crate::ctap::Channel;
|
||||
use crate::api::user_presence::UserPresence;
|
||||
use persistent_store::{Storage, Store};
|
||||
use rng256::Rng256;
|
||||
|
||||
@@ -10,13 +10,6 @@ use rng256::Rng256;
|
||||
pub mod test;
|
||||
pub mod tock;
|
||||
|
||||
pub trait UserPresence {
|
||||
/// Blocks for user presence.
|
||||
///
|
||||
/// Returns an error in case of timeout or keepalive error.
|
||||
fn check(&mut self, channel: Channel) -> Result<(), Ctap2StatusCode>;
|
||||
}
|
||||
|
||||
/// Describes what CTAP needs to function.
|
||||
pub trait Env {
|
||||
type Rng: Rng256;
|
||||
@@ -26,6 +19,7 @@ pub trait Env {
|
||||
type FirmwareProtection: FirmwareProtection;
|
||||
type Write: core::fmt::Write;
|
||||
type Customization: Customization;
|
||||
type HidConnection: HidConnection;
|
||||
|
||||
fn rng(&mut self) -> &mut Self::Rng;
|
||||
fn user_presence(&mut self) -> &mut Self::UserPresence;
|
||||
@@ -48,4 +42,11 @@ pub trait Env {
|
||||
fn write(&mut self) -> Self::Write;
|
||||
|
||||
fn customization(&self) -> &Self::Customization;
|
||||
|
||||
/// I/O connection for sending packets implementing CTAP HID protocol.
|
||||
fn main_hid_connection(&mut self) -> &mut Self::HidConnection;
|
||||
|
||||
/// I/O connection for sending packets implementing vendor extensions to CTAP HID protocol.
|
||||
#[cfg(feature = "vendor_hid")]
|
||||
fn vendor_hid_connection(&mut self) -> &mut Self::HidConnection;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user