diff --git a/src/api.rs b/src/api.rs index d8cf0b5d856..893f31ed777 100644 --- a/src/api.rs +++ b/src/api.rs @@ -227,7 +227,6 @@ pub mod request { ReadDirFilesFirst: - location: Location - dir: PathBuf - - user_attribute: Option ReadDirFilesNext: @@ -279,8 +278,7 @@ pub mod request { WriteFile: - location: Location - path: PathBuf - - data: Message - - user_attribute: Option + - data: LargeMessage UnsafeInjectKey: - mechanism: Mechanism // -> implies key type @@ -339,7 +337,7 @@ pub mod request { WriteCertificate: - location: Location - - der: Message + - der: LargeMessage SerdeExtension: - id: u8 @@ -429,7 +427,7 @@ pub mod reply { - entry: Option ReadFile: - - data: Message + - data: LargeMessage Metadata: - metadata: Option @@ -490,7 +488,7 @@ pub mod reply { DeleteCertificate: ReadCertificate: - - der: Message + - der: LargeMessage WriteCertificate: - id: CertId diff --git a/src/client.rs b/src/client.rs index c2f5d58b728..a3da2a3ec67 100644 --- a/src/client.rs +++ b/src/client.rs @@ -258,7 +258,7 @@ pub trait CertificateClient: PollClient { location: Location, der: &[u8], ) -> ClientResult<'_, reply::WriteCertificate, Self> { - let der = Message::from_slice(der).map_err(|_| ClientError::DataTooLarge)?; + let der = LargeMessage::from_slice(der).map_err(|_| ClientError::DataTooLarge)?; self.request(request::WriteCertificate { location, der }) } } @@ -577,13 +577,8 @@ pub trait FilesystemClient: PollClient { &mut self, location: Location, dir: PathBuf, - user_attribute: Option, ) -> ClientResult<'_, reply::ReadDirFilesFirst, Self> { - self.request(request::ReadDirFilesFirst { - dir, - location, - user_attribute, - }) + self.request(request::ReadDirFilesFirst { dir, location }) } fn read_dir_files_next(&mut self) -> ClientResult<'_, reply::ReadDirFilesNext, Self> { @@ -650,14 +645,12 @@ pub trait FilesystemClient: PollClient { &mut self, location: Location, path: PathBuf, - data: Message, - user_attribute: Option, + data: LargeMessage, ) -> ClientResult<'_, reply::WriteFile, Self> { self.request(request::WriteFile { location, path, data, - user_attribute, }) } } diff --git a/src/config.rs b/src/config.rs index 174293c2183..85c6fbbe940 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,6 +9,7 @@ use littlefs2::consts; pub type MAX_APPLICATION_NAME_LENGTH = consts::U256; pub const MAX_LONG_DATA_LENGTH: usize = 1024; pub const MAX_MESSAGE_LENGTH: usize = 1024; +pub const MAX_LARGE_MESSAGE_LENGTH: usize = 2048; pub type MAX_OBJECT_HANDLES = consts::U16; pub type MAX_LABEL_LENGTH = consts::U256; pub const MAX_MEDIUM_DATA_LENGTH: usize = 256; diff --git a/src/service.rs b/src/service.rs index 6da1cd908d2..7623d17fc7d 100644 --- a/src/service.rs +++ b/src/service.rs @@ -378,7 +378,7 @@ impl ServiceResources

{ } Request::ReadDirFilesFirst(request) => { - let maybe_data = match filestore.read_dir_files_first(&request.dir, request.location, request.user_attribute.clone())? { + let maybe_data = match filestore.read_dir_files_first(&request.dir, request.location)? { Some((data, state)) => { ctx.read_dir_files_state = Some(state); data diff --git a/src/store/certstore.rs b/src/store/certstore.rs index d5d181335b8..659d6a0a921 100644 --- a/src/store/certstore.rs +++ b/src/store/certstore.rs @@ -4,7 +4,7 @@ use littlefs2::path::PathBuf; use crate::{ error::{Error, Result}, store::{self, Store}, - types::{CertId, Location, Message}, + types::{CertId, LargeMessage, Location}, }; pub struct ClientCertstore @@ -18,11 +18,11 @@ where pub trait Certstore { fn delete_certificate(&mut self, id: CertId) -> Result<()>; - fn read_certificate(&mut self, id: CertId) -> Result; + fn read_certificate(&mut self, id: CertId) -> Result; /// TODO: feels a bit heavy-weight to pass in the ClientCounterstore here /// just to ensure the next global counter ("counter zero") is used, and /// not something random. - fn write_certificate(&mut self, location: Location, der: &Message) -> Result; + fn write_certificate(&mut self, location: Location, der: &[u8]) -> Result; } impl Certstore for ClientCertstore { @@ -36,7 +36,7 @@ impl Certstore for ClientCertstore { .ok_or(Error::NoSuchKey) } - fn read_certificate(&mut self, id: CertId) -> Result { + fn read_certificate(&mut self, id: CertId) -> Result { let path = self.cert_path(id); let locations = [Location::Internal, Location::External, Location::Volatile]; locations @@ -45,10 +45,10 @@ impl Certstore for ClientCertstore { .ok_or(Error::NoSuchCertificate) } - fn write_certificate(&mut self, location: Location, der: &Message) -> Result { + fn write_certificate(&mut self, location: Location, der: &[u8]) -> Result { let id = CertId::new(&mut self.rng); let path = self.cert_path(id); - store::store(self.store, location, &path, der.as_slice())?; + store::store(self.store, location, &path, der)?; Ok(id) } } diff --git a/src/store/filestore.rs b/src/store/filestore.rs index 95d7daa8950..9df4d37c55d 100644 --- a/src/store/filestore.rs +++ b/src/store/filestore.rs @@ -2,7 +2,7 @@ use crate::{ error::{Error, Result}, // service::ReadDirState, store::{self, Store}, - types::{Location, Message, UserAttribute}, + types::{Location, Message}, Bytes, }; @@ -17,7 +17,6 @@ pub struct ReadDirFilesState { real_dir: PathBuf, last: usize, location: Location, - user_attribute: Option, } use littlefs2::{ @@ -119,7 +118,6 @@ pub trait Filestore { &mut self, clients_dir: &PathBuf, location: Location, - user_attribute: Option, ) -> Result, ReadDirFilesState)>>; /// Continuation of `read_dir_files_first`. @@ -271,7 +269,6 @@ impl Filestore for ClientFilestore { &mut self, clients_dir: &PathBuf, location: Location, - user_attribute: Option, ) -> Result, ReadDirFilesState)>> { if location != Location::Internal { return Err(Error::RequestNotAvailable); @@ -289,35 +286,13 @@ impl Filestore for ClientFilestore { // // Option> -> ?? .map(|(i, entry)| (i, entry.unwrap())) - // skip over directories (including `.` and `..`) - .filter(|(_, entry)| entry.file_type().is_file()) - // take first entry that meets requirements - .find(|(_, entry)| { - if let Some(user_attribute) = user_attribute.as_ref() { - let mut path = dir.clone(); - path.push(entry.file_name()); - let attribute = fs - .attribute(&path, crate::config::USER_ATTRIBUTE_NUMBER) - .unwrap(); - - if let Some(attribute) = attribute { - user_attribute == attribute.data() - } else { - false - } - } else { - true - } - }) - // if there is an entry, construct the state that needs storing out of it, - // and return the file's contents. - // the client, and return both the entry and the state + // skip over directories (including `.` and `..`) and take first file + .find(|(_, entry)| entry.file_type().is_file()) .map(|(i, entry)| { let read_dir_files_state = ReadDirFilesState { real_dir: dir.clone(), last: i, location, - user_attribute, }; // The semantics is that for a non-existent file, we return None (not an error) let data = store::read(self.store, location, entry.path()).ok(); @@ -340,7 +315,6 @@ impl Filestore for ClientFilestore { real_dir, last, location, - user_attribute, } = state; let fs = self.store.ifs(); @@ -353,31 +327,13 @@ impl Filestore for ClientFilestore { .skip(last + 1) // entry is still a Result :/ (see question in `read_dir_first`) .map(|(i, entry)| (i, entry.unwrap())) - // skip over directories (including `.` and `..`) - .filter(|(_, entry)| entry.file_type().is_file()) - // take first entry that meets requirements - .find(|(_, entry)| { - if let Some(user_attribute) = user_attribute.as_ref() { - let mut path = real_dir.clone(); - path.push(entry.file_name()); - let attribute = fs - .attribute(&path, crate::config::USER_ATTRIBUTE_NUMBER) - .unwrap(); - if let Some(attribute) = attribute { - user_attribute == attribute.data() - } else { - false - } - } else { - true - } - }) + // skip over directories (including `.` and `..`) and take first file + .find(|(_, entry)| entry.file_type().is_file()) .map(|(i, entry)| { let read_dir_files_state = ReadDirFilesState { real_dir: real_dir.clone(), last: i, location, - user_attribute, }; // The semantics is that for a non-existent file, we return None (not an error) let data = store::read(self.store, location, entry.path()).ok(); diff --git a/src/tests.rs b/src/tests.rs index 55be5e7abb4..e230301bf86 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -528,12 +528,7 @@ fn filesystem() { let data = Bytes::from_slice(&[0; 20]).unwrap(); block!(client - .write_file( - Location::Internal, - PathBuf::from("test_file"), - data.clone(), - None, - ) + .write_file(Location::Internal, PathBuf::from("test_file"), data.clone()) .expect("no client error")) .expect("no errors"); diff --git a/src/types.rs b/src/types.rs index 8a9e5e89f68..a5499e75fe6 100644 --- a/src/types.rs +++ b/src/types.rs @@ -589,6 +589,7 @@ pub type ShortData = Bytes; pub type Message = Bytes; pub type SerializedKey = Bytes; +pub type LargeMessage = Bytes; #[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] pub enum KeySerialization { @@ -615,5 +616,3 @@ pub enum SignatureSerialization { Raw, // Sec1, } - -pub type UserAttribute = Bytes; diff --git a/tests/backends.rs b/tests/backends.rs index 1b7c423a9cc..67d5404d2a6 100644 --- a/tests/backends.rs +++ b/tests/backends.rs @@ -7,7 +7,7 @@ use trussed::{ error::Error, platform, service::{Service, ServiceResources}, - types::{Context, CoreContext, Location, Message, PathBuf}, + types::{Context, CoreContext, LargeMessage, Location, PathBuf}, virt::{self, Ram}, ClientImplementation, }; @@ -61,7 +61,7 @@ impl backend::Backend for TestBackend { ) -> Result { match request { Request::ReadFile(_) => { - let mut data = Message::new(); + let mut data = LargeMessage::new(); data.push(0xff).unwrap(); Ok(Reply::ReadFile(ReadFile { data })) } diff --git a/tests/virt.rs b/tests/virt.rs index 93f2dbb8217..4da5c441e23 100644 --- a/tests/virt.rs +++ b/tests/virt.rs @@ -24,7 +24,7 @@ fn run_test(data: u8) { // ensure that no other client is messing with our filesystem while syscall!(client.uptime()).uptime < Duration::from_secs(1) { - syscall!(client.write_file(location, path.clone(), write_data.clone(), None)); + syscall!(client.write_file(location, path.clone(), write_data.clone())); let read_data = syscall!(client.read_file(location, path.clone())).data; assert_eq!(write_data, read_data); }