Use trussed's virt module

This commit is contained in:
Sosthène Guédon
2022-10-24 17:03:21 +02:00
parent 1a65eb8e11
commit 65fd2b42c8
2 changed files with 8 additions and 84 deletions
+1
View File
@@ -24,6 +24,7 @@ untrusted = "0.9"
[dev-dependencies]
littlefs2 = "0.3.2"
rand_core = { version = "0.6", features = ["getrandom"] }
trussed = { version = "0.1.0", features = ["virt"] }
[features]
default = []
+7 -84
View File
@@ -1,10 +1,3 @@
trussed::platform!(
Platform,
R: rand_core::OsRng, //chacha20::ChaCha8Rng,
S: store::Store,
UI: ui::UserInterface,
);
const COMMAND_SIZE: usize = 3072;
#[macro_export]
@@ -14,83 +7,13 @@ macro_rules! cmd {
};
}
pub type Piv<'service> = piv_authenticator::Authenticator<
trussed::ClientImplementation<&'service mut trussed::service::Service<Platform>>,
COMMAND_SIZE,
>;
use trussed::virt::{Client, Ram};
pub type Piv<'service> = piv_authenticator::Authenticator<Client<Ram>, COMMAND_SIZE>;
pub fn piv<R>(test: impl FnOnce(&mut Piv) -> R) -> R {
use trussed::Interchange as _;
unsafe {
trussed::pipe::TrussedInterchange::reset_claims();
}
let trussed_platform = init_platform();
let mut trussed_service = trussed::service::Service::new(trussed_platform);
let client_id = "test";
let trussed_client = trussed_service.try_as_new_client(client_id).unwrap();
let mut piv_app = piv_authenticator::Authenticator::new(trussed_client);
test(&mut piv_app)
}
pub fn init_platform() -> Platform {
let rng = rand_core::OsRng;
let store = store::Store::format(
store::InternalStorage::new(),
store::ExternalStorage::new(),
store::VolatileStorage::new(),
);
let ui = ui::UserInterface::new();
Platform::new(rng, store, ui)
}
pub mod ui {
use trussed::platform::{consent, reboot, ui};
pub struct UserInterface {
start_time: std::time::Instant,
}
impl UserInterface {
pub fn new() -> Self {
Self {
start_time: std::time::Instant::now(),
}
}
}
impl trussed::platform::UserInterface for UserInterface {
fn check_user_presence(&mut self) -> consent::Level {
consent::Level::Normal
}
fn set_status(&mut self, _status: ui::Status) {}
fn refresh(&mut self) {}
fn uptime(&mut self) -> core::time::Duration {
self.start_time.elapsed()
}
fn reboot(&mut self, _to: reboot::To) -> ! {
loop {
continue;
}
}
}
}
pub mod store {
use littlefs2::{
const_ram_storage,
};
use trussed::types::{LfsResult, LfsStorage};
const_ram_storage!(InternalStorage, 8192);
const_ram_storage!(ExternalStorage, 8192);
const_ram_storage!(VolatileStorage, 8192);
trussed::store!(
Store,
Internal: InternalStorage,
External: ExternalStorage,
Volatile: VolatileStorage
);
trussed::virt::with_ram_client("test", |client| {
let mut piv_app = piv_authenticator::Authenticator::new(client);
test(&mut piv_app)
})
}