Merge pull request #8 from Nitrokey/tests-backend

Move tests to a custom backend
This commit is contained in:
sosthene-nitrokey
2023-09-19 14:01:08 +02:00
committed by GitHub
3 changed files with 30 additions and 70 deletions
+5 -3
View File
@@ -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"}
+15 -67
View File
@@ -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<Twi: I2CForT1, D: DelayUs<u32>> MaybeSe for Se05X<Twi, D> {}
#[derive(PartialEq, Debug)]
enum Command {
Update,
@@ -153,7 +138,7 @@ pub trait Reboot {
fn locked() -> bool;
}
pub struct App<T, R, S, Se05X = ()>
pub struct App<T, R, S>
where
T: TrussedClient,
R: Reboot,
@@ -165,7 +150,6 @@ where
full_version: &'static str,
status: S,
boot_interface: PhantomData<R>,
se050: Se05X,
}
impl<T, R, S> App<T, R, S>
@@ -188,47 +172,8 @@ where
full_version,
status,
boot_interface: PhantomData,
se050: (),
}
}
}
#[cfg(feature = "se050")]
impl<T, R, S, Twi, D> App<T, R, S, Se05X<Twi, D>>
where
T: TrussedClient,
R: Reboot,
S: AsRef<[u8]>,
Twi: I2CForT1,
D: DelayUs<u32>,
{
pub fn with_se(
client: T,
uuid: [u8; 16],
version: u32,
full_version: &'static str,
status: S,
se050: Se05X<Twi, D>,
) -> Self {
Self {
trussed: client,
uuid,
version,
full_version,
status,
boot_interface: PhantomData,
se050,
}
}
}
impl<T, R, S, Se05X> App<T, R, S, Se05X>
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<T, R, S, Se> hid::App<'static> for App<T, R, S, Se>
impl<T, R, S> hid::App<'static> for App<T, R, S>
where
T: TrussedClient,
R: Reboot,
S: AsRef<[u8]>,
Se: MaybeSe,
{
fn commands(&self) -> &'static [HidCommand] {
&[
@@ -342,12 +292,11 @@ where
}
}
impl<T, R, S, Se> iso7816::App for App<T, R, S, Se>
impl<T, R, S> iso7816::App for App<T, R, S>
where
T: TrussedClient,
R: Reboot,
S: AsRef<[u8]>,
Se: MaybeSe,
{
// Solo management app
fn aid(&self) -> iso7816::Aid {
@@ -355,12 +304,11 @@ where
}
}
impl<T, R, S, Se> apdu::App<{ command::SIZE }, { response::SIZE }> for App<T, R, S, Se>
impl<T, R, S> apdu::App<{ command::SIZE }, { response::SIZE }> for App<T, R, S>
where
T: TrussedClient,
R: Reboot,
S: AsRef<[u8]>,
Se: MaybeSe,
{
fn select(&mut self, _apdu: &ApduCommand, _reply: &mut response::Data) -> apdu::Result {
Ok(())
+10
View File
@@ -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<C: trussed::Client> Client for C {}
#[cfg(feature = "se050")]
pub trait Client: trussed::Client + trussed_se050_backend::manage::ManageClient {}
#[cfg(feature = "se050")]
impl<C: trussed::Client + trussed_se050_backend::manage::ManageClient> Client for C {}