-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,326 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
[workspace] | ||
members = ["derive"] | ||
|
||
[workspace.package] | ||
authors = ["Nicolas Stalder <[email protected]>", "Nitrokey GmbH"] | ||
edition = "2021" | ||
homepage = "https://trussed.dev" | ||
license = "Apache-2.0 OR MIT" | ||
|
||
[package] | ||
name = "trussed" | ||
version = "0.1.0" | ||
authors = ["Nicolas Stalder <[email protected]>"] | ||
edition = "2021" | ||
homepage = "https://trussed.dev" | ||
repository = "https://github.com/trussed-dev/trussed" | ||
license = "Apache-2.0 OR MIT" | ||
description = "Modern Cryptographic Firmware" | ||
readme = "README.md" | ||
|
||
authors.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
# general | ||
bitflags = { version = "2.1" } | ||
|
@@ -41,7 +51,7 @@ sha2 = { version = "0.10", default-features = false } | |
cosey = "0.3" | ||
delog = "0.1.0" | ||
cbor-smol = "0.4" | ||
heapless-bytes = { version = "0.3.0", features = ["cbor"] } | ||
heapless-bytes = { version = "0.3.0" } | ||
interchange = "0.3.0" | ||
littlefs2 = "0.4.0" | ||
p256-cortex-m4 = { version = "0.1.0-alpha.6", features = ["prehash", "sec1-signatures"] } | ||
|
@@ -54,8 +64,7 @@ serial_test = { version = "2" } | |
entropy = "0.4.0" | ||
once_cell = "1.13.0" | ||
serde_test = "1" | ||
# If this is not enabled, serde_test makes serde_cbor's compilation fail | ||
serde_cbor = { version = "0.11.2", features = ["std"] } | ||
trussed-derive = { path = "derive" } | ||
# Somehow, this is causing a regression. | ||
# rand_core = { version = "0.5", features = ["getrandom"] } | ||
|
||
|
@@ -133,4 +142,4 @@ features = ["serde-extensions", "virt"] | |
rustdoc-args = ["--cfg", "docsrs"] | ||
|
||
[patch.crates-io] | ||
littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "ebd27e49ca321089d01d8c9b169c4aeb58ceeeca" } | ||
littlefs2 = { git = "https://github.com/sosthene-nitrokey/littlefs2.git", rev = "2b45a7559ff44260c6dd693e4cb61f54ae5efc53" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "trussed-derive" | ||
version = "0.1.0" | ||
|
||
authors.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license.workspace = true | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
proc-macro2 = "1.0.51" | ||
quote = "1.0.23" | ||
syn = "2.0.53" | ||
|
||
[dev-dependencies] | ||
serde = { version = "1.0", default-features = false } | ||
trussed = { path = "..", features = ["serde-extensions", "virt"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
mod backends { | ||
use trussed::backend::Backend; | ||
|
||
#[derive(Default)] | ||
pub struct ABackend; | ||
|
||
impl Backend for ABackend { | ||
type Context = (); | ||
} | ||
} | ||
|
||
enum Backend { | ||
A, | ||
} | ||
|
||
#[derive(Default, trussed_derive::Dispatch)] | ||
#[dispatch(backend_id = "Backend")] | ||
struct Dispatch { | ||
a: backends::ABackend, | ||
} | ||
|
||
fn main() { | ||
use trussed::{ | ||
backend::BackendId, | ||
client::CryptoClient, | ||
try_syscall, | ||
virt::{self, Ram}, | ||
Error, | ||
}; | ||
|
||
fn run(backends: &'static [BackendId<Backend>], expected: Option<Error>) { | ||
virt::with_platform(Ram::default(), |platform| { | ||
platform.run_client_with_backends( | ||
"test", | ||
Dispatch::default(), | ||
backends, | ||
|mut client| { | ||
assert_eq!(try_syscall!(client.random_bytes(42)).err(), expected); | ||
}, | ||
) | ||
}); | ||
} | ||
|
||
run(&[BackendId::Core], None); | ||
run( | ||
&[BackendId::Custom(Backend::A)], | ||
Some(Error::RequestNotAvailable), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
use trussed::Error; | ||
|
||
mod backends { | ||
use super::extensions::{TestExtension, TestReply, TestRequest}; | ||
use trussed::{ | ||
backend::Backend, platform::Platform, serde_extensions::ExtensionImpl, | ||
service::ServiceResources, types::CoreContext, Error, | ||
}; | ||
|
||
#[derive(Default)] | ||
pub struct ABackend; | ||
|
||
impl Backend for ABackend { | ||
type Context = (); | ||
} | ||
|
||
impl ExtensionImpl<TestExtension> for ABackend { | ||
fn extension_request<P: Platform>( | ||
&mut self, | ||
_core_ctx: &mut CoreContext, | ||
_backend_ctx: &mut Self::Context, | ||
_request: &TestRequest, | ||
_resources: &mut ServiceResources<P>, | ||
) -> Result<TestReply, Error> { | ||
Ok(TestReply) | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct BBackend; | ||
|
||
impl Backend for BBackend { | ||
type Context = (); | ||
} | ||
} | ||
|
||
mod extensions { | ||
use serde::{Deserialize, Serialize}; | ||
use trussed::{ | ||
serde_extensions::{Extension, ExtensionClient, ExtensionResult}, | ||
Error, | ||
}; | ||
|
||
pub struct TestExtension; | ||
|
||
impl Extension for TestExtension { | ||
type Request = TestRequest; | ||
type Reply = TestReply; | ||
} | ||
|
||
#[derive(Deserialize, Serialize)] | ||
pub struct TestRequest; | ||
|
||
#[derive(Deserialize, Serialize)] | ||
pub struct TestReply; | ||
|
||
impl TryFrom<TestReply> for () { | ||
type Error = Error; | ||
|
||
fn try_from(_reply: TestReply) -> Result<Self, Self::Error> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub trait TestClient { | ||
fn test(&mut self) -> ExtensionResult<'_, TestExtension, (), Self>; | ||
} | ||
|
||
impl<C: ExtensionClient<TestExtension>> TestClient for C { | ||
fn test(&mut self) -> ExtensionResult<'_, TestExtension, (), Self> { | ||
self.extension(TestRequest) | ||
} | ||
} | ||
|
||
pub struct SampleExtension; | ||
|
||
impl Extension for SampleExtension { | ||
type Request = SampleRequest; | ||
type Reply = SampleReply; | ||
} | ||
|
||
#[derive(Deserialize, Serialize)] | ||
pub struct SampleRequest; | ||
|
||
#[derive(Deserialize, Serialize)] | ||
pub struct SampleReply; | ||
} | ||
|
||
enum Backend { | ||
A, | ||
B, | ||
} | ||
|
||
#[derive(trussed_derive::ExtensionId)] | ||
enum Extension { | ||
Test = 0, | ||
Sample = 1, | ||
} | ||
|
||
#[derive(Default, trussed_derive::ExtensionDispatch)] | ||
#[dispatch(backend_id = "Backend", extension_id = "Extension")] | ||
#[extensions( | ||
Test = "extensions::TestExtension", | ||
Sample = "extensions::SampleExtension" | ||
)] | ||
struct Dispatch { | ||
#[extensions("Test")] | ||
a: backends::ABackend, | ||
b: backends::BBackend, | ||
} | ||
|
||
fn main() { | ||
use extensions::TestClient; | ||
use trussed::{ | ||
backend::BackendId, | ||
try_syscall, | ||
virt::{self, Ram}, | ||
}; | ||
|
||
fn run(backends: &'static [BackendId<Backend>], expected: Option<Error>) { | ||
virt::with_platform(Ram::default(), |platform| { | ||
platform.run_client_with_backends( | ||
"test", | ||
Dispatch::default(), | ||
backends, | ||
|mut client| { | ||
assert_eq!(try_syscall!(client.test()).err(), expected); | ||
}, | ||
) | ||
}); | ||
} | ||
|
||
run(&[BackendId::Core], Some(Error::RequestNotAvailable)); | ||
run( | ||
&[BackendId::Custom(Backend::B)], | ||
Some(Error::RequestNotAvailable), | ||
); | ||
run(&[BackendId::Custom(Backend::A)], None); | ||
} |
Oops, something went wrong.