From 83e33925f1edcc1f20ae9cc4a44fffe487c9fa69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Mon, 28 Aug 2023 17:32:38 +0200 Subject: [PATCH 1/4] Adapt to updated trussed --- Cargo.toml | 2 +- src/streaming/mod.rs | 9 ++++++--- src/wrap_key_to_file/mod.rs | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9dc6a04..463b14d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,4 +41,4 @@ log-warn = [] log-error = [] [patch.crates-io] -trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "51e68500d7601d04f884f5e95567d14b9018a6cb" } +trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "df720980888e3e0d5487250bd14a28db02a5f13b" } diff --git a/src/streaming/mod.rs b/src/streaming/mod.rs index d31d2aa..dd4ba1d 100644 --- a/src/streaming/mod.rs +++ b/src/streaming/mod.rs @@ -430,7 +430,7 @@ impl ExtensionImpl for super::StagingBackend { resources: &mut ServiceResources

, ) -> Result { let rng = &mut resources.rng()?; - let keystore = &mut resources.keystore(core_ctx)?; + let keystore = &mut resources.keystore(core_ctx.path.clone())?; let filestore = &mut resources.filestore(core_ctx.path.clone()); let client_id = &core_ctx.path; let store = resources.platform_mut().store(); @@ -482,7 +482,8 @@ impl ExtensionImpl for super::StagingBackend { Ok(reply::WriteChunk {}.into()) } ChunkedRequest::AbortChunkedWrite(_request) => { - let Some(ChunkedIoState::Write(ref write_state)) = backend_ctx.chunked_io_state else { + let Some(ChunkedIoState::Write(ref write_state)) = backend_ctx.chunked_io_state + else { return Ok(reply::AbortChunkedWrite { aborted: false }.into()); }; let aborted = store::abort_chunked_write( @@ -673,7 +674,9 @@ fn read_encrypted_chunk( ctx: &mut StagingContext, ) -> Result { let Some(ChunkedIoState::EncryptedRead(ref mut read_state)) = ctx.chunked_io_state else { - unreachable!("Read encrypted chunk can only be called in the context encrypted chunk reads"); + unreachable!( + "Read encrypted chunk can only be called in the context encrypted chunk reads" + ); }; let (mut data, len): (Bytes<{ MAX_MESSAGE_LENGTH + POLY1305_TAG_LEN }>, usize) = store::filestore_read_chunk( diff --git a/src/wrap_key_to_file/mod.rs b/src/wrap_key_to_file/mod.rs index 7958337..49ee1ec 100644 --- a/src/wrap_key_to_file/mod.rs +++ b/src/wrap_key_to_file/mod.rs @@ -248,7 +248,7 @@ impl ExtensionImpl for super::StagingBackend { request: &WrapKeyToFileRequest, resources: &mut ServiceResources

, ) -> Result { - let keystore = &mut resources.keystore(core_ctx)?; + let keystore = &mut resources.keystore(core_ctx.path.clone())?; let filestore = &mut resources.filestore(core_ctx.path.clone()); match request { WrapKeyToFileRequest::WrapKeyToFile(request) => { From c3822d658eff71b98610d2dcb340a048f72d4802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Tue, 24 Oct 2023 10:47:29 +0200 Subject: [PATCH 2/4] Fix visiblity to allow out-of-crate implementations This is required by the SE050 backend --- src/wrap_key_to_file/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wrap_key_to_file/mod.rs b/src/wrap_key_to_file/mod.rs index 49ee1ec..74acc77 100644 --- a/src/wrap_key_to_file/mod.rs +++ b/src/wrap_key_to_file/mod.rs @@ -28,7 +28,7 @@ pub enum WrapKeyToFileRequest { UnwrapKeyFromFile(request::UnwrapKeyFromFile), } -mod request { +pub mod request { use super::*; use serde::{Deserialize, Serialize}; use trussed::types::{KeyId, Location, Mechanism, Message, PathBuf}; @@ -94,13 +94,13 @@ pub enum WrapKeyToFileReply { UnwrapKeyFromFile(reply::UnwrapKeyFromFile), } -mod reply { +pub mod reply { use serde::{Deserialize, Serialize}; use trussed::{types::KeyId, Error}; use super::*; - #[derive(Debug, Deserialize, Serialize)] + #[derive(Debug, Deserialize, Serialize, Default)] #[non_exhaustive] pub struct WrapKeyToFile {} From bf51805abf96ac9af491a52a077635cedf392a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Tue, 24 Oct 2023 10:50:45 +0200 Subject: [PATCH 3/4] Run cargo fmt --- src/streaming/store.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/streaming/store.rs b/src/streaming/store.rs index 43d99a5..38d101b 100644 --- a/src/streaming/store.rs +++ b/src/streaming/store.rs @@ -268,9 +268,9 @@ pub fn abort_chunked_write( path: &PathBuf, location: Location, ) -> bool { - let Ok(path) = chunks_path(client_id,path, location) else { - return false; - }; + let Ok(path) = chunks_path(client_id, path, location) else { + return false; + }; trussed::store::delete(store, Location::Volatile, &path) } From 5bf1fb2852fb3687adc0b7251077e0d97c950337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Tue, 24 Oct 2023 10:59:48 +0200 Subject: [PATCH 4/4] Fix rustdoc warnings --- src/streaming/mod.rs | 6 +++--- src/virt.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/streaming/mod.rs b/src/streaming/mod.rs index dd4ba1d..d368b7d 100644 --- a/src/streaming/mod.rs +++ b/src/streaming/mod.rs @@ -768,7 +768,7 @@ pub trait ChunkedClient: ExtensionClient + FilesystemClient { /// Begin writing an encrypted file that can be larger than 1KiB /// /// More chunks can be written with [`write_file_chunk`](ChunkedClient::write_file_chunk). - /// The data is flushed and becomes readable when a chunk smaller than the maximum capacity of a [`Message`](trussed::types::Message) is transfered. + /// The data is flushed and becomes readable when a chunk smaller than the maximum capacity of a [`Message`] is transfered. #[cfg(feature = "encrypted-chunked")] fn start_encrypted_chunked_write( &mut self, @@ -790,7 +790,7 @@ pub trait ChunkedClient: ExtensionClient + FilesystemClient { /// Begin reading a file that can be larger than 1KiB /// /// More chunks can be read with [`read_file_chunk`](ChunkedClient::read_file_chunk). - /// The read is over once a chunk of size smaller than the maximum capacity of a [`Message`](trussed::types::Message) is transfered. + /// The read is over once a chunk of size smaller than the maximum capacity of a [`Message`] is transfered. fn start_chunked_read( &mut self, location: Location, @@ -802,7 +802,7 @@ pub trait ChunkedClient: ExtensionClient + FilesystemClient { /// Begin reading an encrypted file that can be larger than 1KiB /// /// More chunks can be read with [`read_file_chunk`](ChunkedClient::read_file_chunk). - /// The read is over once a chunk of size smaller than the maximum capacity of a [`Message`](trussed::types::Message) is transfered. + /// The read is over once a chunk of size smaller than the maximum capacity of a [`Message`] is transfered. /// Only once the entire file has been read does the data have been properly authenticated. #[cfg(feature = "encrypted-chunked")] fn start_encrypted_chunked_read( diff --git a/src/virt.rs b/src/virt.rs index f22cf47..74011a8 100644 --- a/src/virt.rs +++ b/src/virt.rs @@ -1,7 +1,7 @@ // Copyright (C) Nitrokey GmbH // SPDX-License-Identifier: Apache-2.0 or MIT -//! Wrapper around [`trussed::virt`][] that provides clients with both the core backend and the [`StagingBackend`](crate::StagingBackend) backend. +//! Wrapper around [`trussed::virt`][] that provides clients with both the core backend and the [`StagingBackend`] backend. #[cfg(feature = "wrap-key-to-file")] use crate::wrap_key_to_file::WrapKeyToFileExtension;