diff --git a/Cargo.toml b/Cargo.toml index 693c7c7..1467369 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,10 +20,11 @@ se05x = { version = "0.0.1", optional = true } embedded-hal = { version = "0.2.7", optional = true } hex-literal = "0.4.1" rand_chacha = { version = "0.3.1", optional = true, default-features = false } +trussed-se050-backend = { version = "0.1.0", optional = true } [features] -default = ["se050"] -se050 = ["dep:se05x", "embedded-hal", "rand_chacha"] +default = [] +se050 = ["trussed-se050-backend"] log-all = [] log-none = [] @@ -35,5 +36,6 @@ log-error = [] [patch.crates-io] ctaphid-dispatch = { git = "https://github.com/trussed-dev/ctaphid-dispatch.git", rev = "57cb3317878a8593847595319aa03ef17c29ec5b" } trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "51e68500d7601d04f884f5e95567d14b9018a6cb" } +trussed-se050-backend = { git = "https://github.com/Nitrokey/trussed-se050-backend.git", rev = "3395a5b73241a0a9f14a0715952be6fe7f1e56b0" } iso7816 = { git = "https://github.com/sosthene-nitrokey/iso7816.git", rev = "160ca3bbd8e21ec4e4ee1e0748e1eaa53a45c97f"} -se05x = { git = "https://github.com/Nitrokey/se05x.git", rev = "db1ddea25cc382355b4292352652da656abc3005"} +se05x = { git = "https://github.com/Nitrokey/se05x.git", rev = "0b77eb6b152d214897696aadf87767fd84ffcb0e"} diff --git a/src/admin.rs b/src/admin.rs index 3f762c4..c9842e9 100644 --- a/src/admin.rs +++ b/src/admin.rs @@ -1,13 +1,10 @@ +use super::Client as TrussedClient; use apdu_dispatch::iso7816::Status; use apdu_dispatch::{app as apdu, command, response, Command as ApduCommand}; use core::{convert::TryInto, marker::PhantomData, time::Duration}; use ctaphid_dispatch::app::{self as hid, Command as HidCommand, Message}; use ctaphid_dispatch::command::VendorCommand; -#[cfg(feature = "se050")] -use embedded_hal::blocking::delay::DelayUs; -#[cfg(feature = "se050")] -use se05x::{se05x::Se05X, t1::I2CForT1}; -use trussed::{interrupt::InterruptFlag, syscall, types::Vec, Client as TrussedClient}; +use trussed::{interrupt::InterruptFlag, syscall, types::Vec}; pub const USER_PRESENCE_TIMEOUT_SECS: u32 = 15; @@ -30,18 +27,6 @@ const WINK: HidCommand = HidCommand::Wink; // 0x08 const RNG_DATA_LEN: usize = 57; -mod run_tests; -use run_tests::*; - -/// Trait representing the possible ownership of the SE050 by the admin app. -/// -/// Implemented by `()` and the `Se05X` struct -pub trait MaybeSe: RunTests {} - -impl MaybeSe for () {} -#[cfg(feature = "se050")] -impl> MaybeSe for Se05X {} - #[derive(PartialEq, Debug)] enum Command { Update, @@ -153,7 +138,7 @@ pub trait Reboot { fn locked() -> bool; } -pub struct App +pub struct App where T: TrussedClient, R: Reboot, @@ -165,7 +150,6 @@ where full_version: &'static str, status: S, boot_interface: PhantomData, - se050: Se05X, } impl App @@ -188,47 +172,8 @@ where full_version, status, boot_interface: PhantomData, - se050: (), } } -} - -#[cfg(feature = "se050")] -impl App> -where - T: TrussedClient, - R: Reboot, - S: AsRef<[u8]>, - Twi: I2CForT1, - D: DelayUs, -{ - pub fn with_se( - client: T, - uuid: [u8; 16], - version: u32, - full_version: &'static str, - status: S, - se050: Se05X, - ) -> Self { - Self { - trussed: client, - uuid, - version, - full_version, - status, - boot_interface: PhantomData, - se050, - } - } -} - -impl App -where - T: TrussedClient, - R: Reboot, - S: AsRef<[u8]>, - Se05X: MaybeSe, -{ fn user_present(&mut self) -> bool { let user_present = syscall!(self .trussed @@ -288,9 +233,15 @@ where response.extend_from_slice(self.status.as_ref()).ok(); } Command::TestSe05X => { - debug_now!("Running se050 tests"); - if let Err(_err) = self.se050.run_tests(response) { - debug_now!("se050 tests failed: {_err:?}"); + #[cfg(feature = "se050")] + { + let rep = syscall!(self.trussed.test_se050()); + response.extend_from_slice(&rep.reply).ok(); + return Ok(()); + } + #[cfg(not(feature = "se050"))] + { + return Err(Error::NotAvailable); } } } @@ -298,12 +249,11 @@ where } } -impl hid::App<'static> for App +impl hid::App<'static> for App where T: TrussedClient, R: Reboot, S: AsRef<[u8]>, - Se: MaybeSe, { fn commands(&self) -> &'static [HidCommand] { &[ @@ -342,12 +292,11 @@ where } } -impl iso7816::App for App +impl iso7816::App for App where T: TrussedClient, R: Reboot, S: AsRef<[u8]>, - Se: MaybeSe, { // Solo management app fn aid(&self) -> iso7816::Aid { @@ -355,12 +304,11 @@ where } } -impl apdu::App<{ command::SIZE }, { response::SIZE }> for App +impl apdu::App<{ command::SIZE }, { response::SIZE }> for App where T: TrussedClient, R: Reboot, S: AsRef<[u8]>, - Se: MaybeSe, { fn select(&mut self, _apdu: &ApduCommand, _reply: &mut response::Data) -> apdu::Result { Ok(()) diff --git a/src/lib.rs b/src/lib.rs index ec8a355..485dc7b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,3 +12,13 @@ generate_macros!(); mod admin; pub use admin::{App, Reboot}; + +#[cfg(not(feature = "se050"))] +pub trait Client: trussed::Client {} +#[cfg(not(feature = "se050"))] +impl Client for C {} + +#[cfg(feature = "se050")] +pub trait Client: trussed::Client + trussed_se050_backend::manage::ManageClient {} +#[cfg(feature = "se050")] +impl Client for C {}