From 1414a89a6030e90dc58b09d6e39a84d6b33f5a7d Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 13 Mar 2024 18:54:25 +0100 Subject: [PATCH] Move manage::ManageExtension into trussed-se050-manage crate Similar to the changes in trussed-staging#19 [0], this patch moves the extension that was previously defined in the backend crate into a separate extension crate. [0] https://github.com/trussed-dev/trussed-staging/pull/19 --- CHANGELOG.md | 1 + Cargo.toml | 26 +++++- extensions/se050-manage/Cargo.toml | 11 +++ extensions/se050-manage/src/lib.rs | 137 +++++++++++++++++++++++++++++ src/lib.rs | 2 +- src/manage.rs | 137 +---------------------------- 6 files changed, 176 insertions(+), 138 deletions(-) create mode 100644 extensions/se050-manage/Cargo.toml create mode 100644 extensions/se050-manage/src/lib.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index b21cb27..32312d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Use extension crates `trussed-manage` and `trussed-wrap-key-to-file` instead of backend crate `trussed-staging`, see [trussed-staging#19][]. +- Move `manage::ManageExtension` into `trussed-se050-manage` crate. [trussed-staging#19]: https://github.com/trussed-dev/trussed-staging/pull/19 diff --git a/Cargo.toml b/Cargo.toml index d6ada77..a4a192f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,32 @@ +[workspace] +members = ["extensions/se050-manage"] + +[workspace.package] +authors = ["Nitrokey GmbH "] +edition = "2021" +repository = "https://github.com/trussed-dev/trussed-staging" +license = "Apache-2.0 OR MIT" + [package] name = "trussed-se050-backend" version = "0.2.0" -edition = "2021" +authors.workspace = true +edition.workspace = true +repository.workspace = true +license.workspace = true -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[workspace.dependencies] +serde = { version = "1.0.185", default-features = false, features = ["derive"] } +trussed = { version = "0.1.0", features = ["serde-extensions"] } [dependencies] +serde.workspace = true +trussed.workspace = true + se05x = { version = "0.1.1", features = ["serde", "builder"] } -trussed = { version = "0.1.0", features = ["serde-extensions"] } trussed-auth = "0.2.2" trussed-manage = "0.1.0" +trussed-se050-manage = "0.1.0" trussed-wrap-key-to-file = "0.1.0" delog = "0.1.6" embedded-hal = "0.2.7" @@ -19,7 +36,6 @@ hex-literal = "0.4.1" serde-byte-array = "0.1.2" iso7816 = "0.1.1" hmac = "0.12.1" -serde = { version = "1.0.185", default-features = false, features = ["derive"] } rand = { version = "0.8.5", default-features = false } littlefs2 = "0.4.0" cbor-smol = "0.4.0" @@ -39,6 +55,8 @@ trussed-manage = { git = "https://github.com/trussed-dev/trussed-staging.git", t trussed-rsa-alloc = { git = "https://github.com/Nitrokey/trussed-rsa-backend.git", rev = "2088e2f8a8d706276c1559717b4c6b6d4f270253" } trussed-wrap-key-to-file = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "wrap-key-to-file-v0.1.0" } +trussed-se050-manage = { path = "extensions/se050-manage" } + [features] default = ["log-all"] diff --git a/extensions/se050-manage/Cargo.toml b/extensions/se050-manage/Cargo.toml new file mode 100644 index 0000000..5f06eba --- /dev/null +++ b/extensions/se050-manage/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "trussed-se050-manage" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +serde.workspace = true +trussed.workspace = true diff --git a/extensions/se050-manage/src/lib.rs b/extensions/se050-manage/src/lib.rs new file mode 100644 index 0000000..19fc7cd --- /dev/null +++ b/extensions/se050-manage/src/lib.rs @@ -0,0 +1,137 @@ +use serde::{Deserialize, Serialize}; +use trussed::{ + serde_extensions::{Extension, ExtensionClient, ExtensionResult}, + types::Bytes, + Error, +}; + +#[derive(Debug, Default)] +pub struct ManageExtension; + +/// Request information regarding the SE050 +#[derive(Debug, Deserialize, Serialize, Copy, Clone)] +pub struct InfoRequest; + +/// Test SE050 functionality +/// +/// This is now a placeholder for the previous test. It is kept to return available space on the SE050 +#[derive(Debug, Deserialize, Serialize, Copy, Clone)] +pub struct TestSe050Request; + +#[allow(clippy::large_enum_variant)] +#[derive(Debug, Deserialize, Serialize)] +pub enum ManageRequest { + Info(InfoRequest), + TestSe050(TestSe050Request), +} + +impl TryFrom for InfoRequest { + type Error = Error; + fn try_from(request: ManageRequest) -> Result { + match request { + ManageRequest::Info(request) => Ok(request), + _ => Err(Error::InternalError), + } + } +} + +impl From for ManageRequest { + fn from(request: InfoRequest) -> Self { + Self::Info(request) + } +} + +impl TryFrom for TestSe050Request { + type Error = Error; + fn try_from(request: ManageRequest) -> Result { + match request { + ManageRequest::TestSe050(request) => Ok(request), + _ => Err(Error::InternalError), + } + } +} + +impl From for ManageRequest { + fn from(request: TestSe050Request) -> Self { + Self::TestSe050(request) + } +} + +#[derive(Debug, Deserialize, Serialize, Copy, Clone)] +pub struct InfoReply { + pub major: u8, + pub minor: u8, + pub patch: u8, + pub sb_major: u8, + pub sb_minor: u8, + pub persistent: u16, + pub transient_deselect: u16, + pub transient_reset: u16, +} + +#[derive(Debug, Deserialize, Serialize)] +pub enum ManageReply { + Info(InfoReply), + TestSe050(TestSe050Reply), +} + +impl TryFrom for InfoReply { + type Error = Error; + fn try_from(request: ManageReply) -> Result { + match request { + ManageReply::Info(request) => Ok(request), + _ => Err(Error::InternalError), + } + } +} + +impl From for ManageReply { + fn from(request: InfoReply) -> Self { + Self::Info(request) + } +} + +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct TestSe050Reply { + pub reply: Bytes<1024>, +} + +impl TryFrom for TestSe050Reply { + type Error = Error; + fn try_from(request: ManageReply) -> Result { + match request { + ManageReply::TestSe050(request) => Ok(request), + _ => Err(Error::InternalError), + } + } +} + +impl From for ManageReply { + fn from(request: TestSe050Reply) -> Self { + Self::TestSe050(request) + } +} + +impl Extension for ManageExtension { + type Request = ManageRequest; + type Reply = ManageReply; +} + +pub type ManageResult<'a, R, C> = ExtensionResult<'a, ManageExtension, R, C>; + +pub trait ManageClient: ExtensionClient { + /// Get info on the SE050 + fn get_info(&mut self) -> ManageResult<'_, InfoReply, Self> { + self.extension(InfoRequest) + } + + /// Test the se050 device and driver + /// + /// This will fake the results of the tests from v0.1.0-test-driver for compatibility but + /// return correct metadata header to be shown in the test result + fn test_se050(&mut self) -> ManageResult<'_, TestSe050Reply, Self> { + self.extension(TestSe050Request) + } +} + +impl> ManageClient for C {} diff --git a/src/lib.rs b/src/lib.rs index 8352511..8bcb41f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,7 @@ use trussed_auth_impl::{AuthContext, HardwareKey}; mod staging; mod core_api; -pub mod manage; +mod manage; pub mod namespacing; /// Need overhead for TLV + SW bytes diff --git a/src/manage.rs b/src/manage.rs index 7861e33..bc844e9 100644 --- a/src/manage.rs +++ b/src/manage.rs @@ -7,129 +7,19 @@ use se05x::{ }, t1::I2CForT1, }; -use serde::{Deserialize, Serialize}; use trussed::{ - serde_extensions::{Extension, ExtensionClient, ExtensionImpl, ExtensionResult}, + serde_extensions::{Extension, ExtensionImpl}, service::ServiceResources, types::Bytes, types::CoreContext, Error, }; +use trussed_se050_manage::{ + InfoReply, InfoRequest, ManageExtension, ManageRequest, TestSe050Reply, +}; use crate::Se050Backend; -#[derive(Debug, Default)] -pub struct ManageExtension; - -/// Request information regarding the SE050 -#[derive(Debug, Deserialize, Serialize, Copy, Clone)] -pub struct InfoRequest; - -/// Test SE050 functionality -/// -/// This is now a placeholder for the previous test. It is kept to return available space on the SE050 -#[derive(Debug, Deserialize, Serialize, Copy, Clone)] -pub struct TestSe050Request; - -#[allow(clippy::large_enum_variant)] -#[derive(Debug, Deserialize, Serialize)] -pub enum ManageRequest { - Info(InfoRequest), - TestSe050(TestSe050Request), -} - -impl TryFrom for InfoRequest { - type Error = Error; - fn try_from(request: ManageRequest) -> Result { - match request { - ManageRequest::Info(request) => Ok(request), - _ => Err(Error::InternalError), - } - } -} - -impl From for ManageRequest { - fn from(request: InfoRequest) -> Self { - Self::Info(request) - } -} - -impl TryFrom for TestSe050Request { - type Error = Error; - fn try_from(request: ManageRequest) -> Result { - match request { - ManageRequest::TestSe050(request) => Ok(request), - _ => Err(Error::InternalError), - } - } -} - -impl From for ManageRequest { - fn from(request: TestSe050Request) -> Self { - Self::TestSe050(request) - } -} - -#[derive(Debug, Deserialize, Serialize, Copy, Clone)] -pub struct InfoReply { - pub major: u8, - pub minor: u8, - pub patch: u8, - pub sb_major: u8, - pub sb_minor: u8, - pub persistent: u16, - pub transient_deselect: u16, - pub transient_reset: u16, -} - -#[derive(Debug, Deserialize, Serialize)] -pub enum ManageReply { - Info(InfoReply), - TestSe050(TestSe050Reply), -} - -impl TryFrom for InfoReply { - type Error = Error; - fn try_from(request: ManageReply) -> Result { - match request { - ManageReply::Info(request) => Ok(request), - _ => Err(Error::InternalError), - } - } -} - -impl From for ManageReply { - fn from(request: InfoReply) -> Self { - Self::Info(request) - } -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct TestSe050Reply { - pub reply: Bytes<1024>, -} - -impl TryFrom for TestSe050Reply { - type Error = Error; - fn try_from(request: ManageReply) -> Result { - match request { - ManageReply::TestSe050(request) => Ok(request), - _ => Err(Error::InternalError), - } - } -} - -impl From for ManageReply { - fn from(request: TestSe050Reply) -> Self { - Self::TestSe050(request) - } -} - -impl Extension for ManageExtension { - type Request = ManageRequest; - type Reply = ManageReply; -} - impl> ExtensionImpl for Se050Backend { fn extension_request( &mut self, @@ -264,22 +154,3 @@ impl> ExtensionImpl for Se050Bac } } } - -type ManageResult<'a, R, C> = ExtensionResult<'a, ManageExtension, R, C>; - -pub trait ManageClient: ExtensionClient { - /// Get info on the SE050 - fn get_info(&mut self) -> ManageResult<'_, InfoReply, Self> { - self.extension(InfoRequest) - } - - /// Test the se050 device and driver - /// - /// This will fake the results of the tests from v0.1.0-test-driver for compatibility but - /// return correct metadata header to be shown in the test result - fn test_se050(&mut self) -> ManageResult<'_, TestSe050Reply, Self> { - self.extension(TestSe050Request) - } -} - -impl> ManageClient for C {}