From d5c14935e4655ca7e45775da34d1dddadbaa2aba Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Thu, 31 Jul 2025 16:49:49 +0200 Subject: [PATCH] Update to heapless-bytes v0.5 and trussed-core v0.2 --- CHANGELOG.md | 3 +++ Cargo.toml | 9 ++++----- src/crypto_traits.rs | 2 +- src/lib.rs | 4 ++-- src/virt.rs | 22 ++++++---------------- tests/rsa2048.rs | 2 +- tests/rsa3072.rs | 2 +- tests/rsa4096.rs | 2 +- types/CHANGELOG.md | 4 +++- types/src/lib.rs | 22 ++++++++++++++++------ 10 files changed, 38 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d497928..919878f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ SPDX-License-Identifier: CC0-1.0 [Unreleased]: https://github.com/trussed-dev/trussed-rsa-backend/compare/v0.3.0...HEAD - Move `RsaImportFormat` and `RsaPublicParts` to the `trussed-rsa-types` crate. +- Update dependencies: + - `heapless-bytes` v0.5 + - `trussed-core` v0.2 ## [v0.3.0][] (2025-07-31) diff --git a/Cargo.toml b/Cargo.toml index 1b3d967..f2bee77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,8 @@ license = "Apache-2.0 OR MIT" repository = "https://github.com/trussed-dev/trussed-rsa-backend" [workspace.dependencies] -heapless-bytes = "0.3" -trussed-core = "0.1" +heapless-bytes = "0.5" +trussed-core = "0.2" [package] name = "trussed-rsa-alloc" @@ -42,10 +42,9 @@ delog = { version = "0.1.6", features = ["std-log"] } test-log = "0.2.11" env_logger = "0.10.0" rand = "0.8.5" -trussed = { version = "0.1", default-features = false, features = ["certificate-client", "clients-1", "crypto-client"] } +trussed = { version = "0.1", default-features = false, features = ["certificate-client", "crypto-client"] } [features] - virt = ["std", "trussed/virt"] std = [] @@ -61,7 +60,7 @@ log-warn = [] log-error = [] [patch.crates-io] -trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "6bba8fde36d05c0227769eb63345744e87d84b2b" } +trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "0b65280d69be541b8771f7756139826332c7d674" } trussed-rsa-types.path = "types" [profile.dev.package.rsa] diff --git a/src/crypto_traits.rs b/src/crypto_traits.rs index 90fb462..791e37a 100644 --- a/src/crypto_traits.rs +++ b/src/crypto_traits.rs @@ -9,7 +9,7 @@ use trussed_core::{ types::{ KeyId, KeySerialization, Location, Mechanism, SignatureSerialization, StorageAttributes, }, - ClientError, ClientResult, CryptoClient, + {ClientError, ClientResult, CryptoClient}, }; use trussed_rsa_types::{RsaImportFormat, RsaPublicParts}; diff --git a/src/lib.rs b/src/lib.rs index 0a39a45..18d21c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -270,7 +270,7 @@ fn sign( Error::InternalError })?; let our_signature = - Signature::from_slice(&native_signature.to_bytes()).unwrap_or_else(|_| panic!()); + Signature::try_from(&*native_signature.to_bytes()).unwrap_or_else(|_| panic!()); Ok(reply::Sign { signature: our_signature, @@ -337,7 +337,7 @@ fn decrypt( })?; Ok(reply::Decrypt { - plaintext: Some(Bytes::from_slice(&res).map_err(|_| { + plaintext: Some(Bytes::try_from(&*res).map_err(|_| { error!("Failed type conversion"); Error::InternalError })?), diff --git a/src/virt.rs b/src/virt.rs index 8452034..d5e3cce 100644 --- a/src/virt.rs +++ b/src/virt.rs @@ -23,19 +23,17 @@ impl Dispatch for Dispatcher { } } -use std::path::PathBuf; use trussed::{ backend::{Backend, BackendId, Dispatch}, - virt::{self, Filesystem, Ram, StoreProvider}, + virt::{self, StoreConfig}, Platform, }; -pub type Client = virt::Client; +pub type Client<'a, D = Dispatcher> = virt::Client<'a, D>; -pub fn with_client(store: S, client_id: &str, f: F) -> R +pub fn with_client(store: StoreConfig, client_id: &str, f: F) -> R where - F: FnOnce(Client) -> R, - S: StoreProvider, + F: FnOnce(Client) -> R, { virt::with_platform(store, |platform| { platform.run_client_with_backends( @@ -47,17 +45,9 @@ where }) } -pub fn with_fs_client(internal: P, client_id: &str, f: F) -> R -where - F: FnOnce(Client) -> R, - P: Into, -{ - with_client(Filesystem::new(internal), client_id, f) -} - pub fn with_ram_client(client_id: &str, f: F) -> R where - F: FnOnce(Client) -> R, + F: FnOnce(Client) -> R, { - with_client(Ram::default(), client_id, f) + with_client(StoreConfig::ram(), client_id, f) } diff --git a/tests/rsa2048.rs b/tests/rsa2048.rs index 4cbe3b1..295db90 100644 --- a/tests/rsa2048.rs +++ b/tests/rsa2048.rs @@ -5,13 +5,13 @@ use rsa::sha2::Sha256; use rsa::{traits::PublicKeyParts, Pkcs1v15Encrypt, Pkcs1v15Sign}; -use trussed::client::CryptoClient; use trussed::syscall; use trussed::types::KeyId; use trussed::types::KeySerialization; use trussed::types::Location::*; use trussed::types::Mechanism; use trussed::types::StorageAttributes; +use trussed_core::CryptoClient; use trussed_rsa_alloc::*; use trussed_rsa_types::*; diff --git a/tests/rsa3072.rs b/tests/rsa3072.rs index 1e5f3a6..aced102 100644 --- a/tests/rsa3072.rs +++ b/tests/rsa3072.rs @@ -5,13 +5,13 @@ use rsa::sha2::Sha384; use rsa::{traits::PublicKeyParts, Pkcs1v15Encrypt, Pkcs1v15Sign}; -use trussed::client::CryptoClient; use trussed::syscall; use trussed::types::KeyId; use trussed::types::KeySerialization; use trussed::types::Location::*; use trussed::types::Mechanism; use trussed::types::StorageAttributes; +use trussed_core::CryptoClient; use trussed_rsa_alloc::*; use trussed_rsa_types::*; diff --git a/tests/rsa4096.rs b/tests/rsa4096.rs index ff0c5c6..3ab00a0 100644 --- a/tests/rsa4096.rs +++ b/tests/rsa4096.rs @@ -5,13 +5,13 @@ use rsa::sha2::Sha512; use rsa::{traits::PublicKeyParts, Pkcs1v15Encrypt, Pkcs1v15Sign}; -use trussed::client::CryptoClient; use trussed::syscall; use trussed::types::KeyId; use trussed::types::KeySerialization; use trussed::types::Location::*; use trussed::types::Mechanism; use trussed::types::StorageAttributes; +use trussed_core::CryptoClient; use trussed_rsa_alloc::*; use trussed_rsa_types::*; diff --git a/types/CHANGELOG.md b/types/CHANGELOG.md index a94b6d2..8f6ff9a 100644 --- a/types/CHANGELOG.md +++ b/types/CHANGELOG.md @@ -7,7 +7,9 @@ SPDX-License-Identifier: CC0-1.0 ## [Unreleased](https://github.com/trussed-dev/trussed-rsa-backend/compare/types-v0.1.0...HEAD) -- +- Update dependencies: + - `heapless-bytes` v0.5 + - `trussed-core` v0.2 ## [v0.1.0](https://github.com/trussed-dev/trussed-rsa-backend/releases/tag/types-v0.1.0) diff --git a/types/src/lib.rs b/types/src/lib.rs index e02c929..eb5f88e 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -1,6 +1,8 @@ // Copyright (C) Nitrokey GmbH // SPDX-License-Identifier: Apache-2.0 or MIT +#![no_std] + use heapless_bytes::Bytes; use serde::{Deserialize, Serialize}; use trussed_core::types::SerializedKey; @@ -25,6 +27,16 @@ pub struct Error { kind: ErrorKind, } +pub(crate) fn postcard_serialize_bytes( + object: &T, +) -> postcard::Result> { + let mut vec = Bytes::new(); + vec.resize_to_capacity(); + let serialized = postcard::to_slice(object, &mut vec)?.len(); + vec.resize(serialized, 0).unwrap(); + Ok(vec) +} + /// Structure containing the public part of an RSA key /// /// Given how Trussed extensions are implemented, this structure cannot be sent as-is to the backend, @@ -42,15 +54,14 @@ pub struct RsaPublicParts<'d> { impl<'d> RsaPublicParts<'d> { pub fn serialize(&self) -> Result { use postcard::Error as PError; - let vec = postcard::to_vec(self).map_err(|err| match err { + postcard_serialize_bytes(self).map_err(|err| match err { PError::SerializeBufferFull => Error { kind: ErrorKind::SerializeBufferFull, }, _ => Error { kind: ErrorKind::SerializeCustom, }, - })?; - Ok(Bytes::from(vec)) + }) } pub fn deserialize(data: &'d [u8]) -> Result { @@ -79,15 +90,14 @@ pub struct RsaImportFormat<'d> { impl<'d> RsaImportFormat<'d> { pub fn serialize(&self) -> Result { use postcard::Error as PError; - let vec = postcard::to_vec(self).map_err(|err| match err { + postcard_serialize_bytes(self).map_err(|err| match err { PError::SerializeBufferFull => Error { kind: ErrorKind::SerializeBufferFull, }, _ => Error { kind: ErrorKind::SerializeCustom, }, - })?; - Ok(Bytes::from(vec)) + }) } pub fn deserialize(data: &'d [u8]) -> Result {