From 8877088c3fbf4c67f68701d0d38462f8b221038f Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 3 Jul 2024 16:03:48 +0200 Subject: [PATCH] Update littlefs2 --- Cargo.toml | 9 +++++---- src/core_api.rs | 7 +++++-- src/migrate.rs | 2 +- src/trussed_auth_impl.rs | 6 +++--- src/trussed_auth_impl/data.rs | 20 ++++++++------------ 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cef4c68..a9e5657 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,15 +55,16 @@ admin-app = { version = "0.1.0", features = ["migration-tests"] } serde_test = "1.0.176" [patch.crates-io] -littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "960e57d9fc0d209308c8e15dc26252bbe1ff6ba8" } +littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", branch = "core" } +littlefs2-core = { git = "https://github.com/trussed-dev/littlefs2.git", branch = "core" } apdu-dispatch = { git = "https://github.com/trussed-dev/apdu-dispatch.git", rev = "915fc237103fcecc29d0f0b73391f19abf6576de" } ctaphid-dispatch = { git = "https://github.com/trussed-dev/ctaphid-dispatch.git", rev = "57cb3317878a8593847595319aa03ef17c29ec5b" } -trussed = { git = "https://github.com/nitrokey/trussed.git", rev = "540ad725ef44f0d6d3d2da7dd6ec0bacffaeb5bf" } -trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth.git", tag = "v0.3.0"} +trussed = { git = "https://github.com/trussed-dev/trussed.git", branch = "littlefs2" } +trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth.git", branch = "littlefs2" } trussed-manage = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "manage-v0.1.0" } trussed-rsa-alloc = { git = "https://github.com/trussed-dev/trussed-rsa-backend.git", tag = "v0.2.1" } trussed-wrap-key-to-file = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "wrap-key-to-file-v0.1.0" } -admin-app = { git = "https://github.com/Nitrokey/admin-app.git", tag = "v0.1.0-nitrokey.12" } +admin-app = { git = "https://github.com/Nitrokey/admin-app.git", branch = "littlefs2" } trussed-se050-manage = { path = "extensions/se050-manage" } diff --git a/src/core_api.rs b/src/core_api.rs index 5504c21..03e0381 100644 --- a/src/core_api.rs +++ b/src/core_api.rs @@ -8,7 +8,10 @@ use crypto_bigint::{ }; use embedded_hal::blocking::delay::DelayUs; use hex_literal::hex; -use littlefs2::path::PathBuf; +use littlefs2::{ + path, + path::{Path, PathBuf}, +}; use rand::{CryptoRng, RngCore}; use se05x::{ se05x::{ @@ -47,7 +50,7 @@ use crate::{ mod ecdsa_der; pub(crate) const BUFFER_LEN: usize = 2048; -pub(crate) const CORE_DIR: &str = "se050-core"; +pub(crate) const CORE_DIR: &Path = path!("se050-core"); #[derive(Serialize, Deserialize, Debug, Clone)] struct VolatileKeyMaterial { diff --git a/src/migrate.rs b/src/migrate.rs index 9ed4779..f0b1db6 100644 --- a/src/migrate.rs +++ b/src/migrate.rs @@ -28,7 +28,7 @@ use crate::BACKEND_DIR; fn migrate_single(fs: &dyn DynFilesystem, path: &Path) -> Result<(), Error> { match fs.remove_dir_all(path) { - Err(Error::NoSuchEntry) => Ok(()), + Err(Error::NO_SUCH_ENTRY) => Ok(()), Err(err) => Err(err), Ok(()) => Ok(()), } diff --git a/src/trussed_auth_impl.rs b/src/trussed_auth_impl.rs index 09cf0fc..b13066b 100644 --- a/src/trussed_auth_impl.rs +++ b/src/trussed_auth_impl.rs @@ -107,11 +107,11 @@ impl> Se050Backend { global_fs: &mut impl Filestore, rng: &mut R, ) -> Result { - let path = PathBuf::from("salt"); + let path = path!("salt"); global_fs .read(&path, self.metadata_location) .or_else(|_| { - if global_fs.exists(&path, self.metadata_location) { + if global_fs.exists(path, self.metadata_location) { return Err(Error::ReadFailed); } @@ -119,7 +119,7 @@ impl> Se050Backend { salt.resize_to_capacity(); rng.fill_bytes(&mut salt); global_fs - .write(&path, self.metadata_location, &salt) + .write(path, self.metadata_location, &salt) .or(Err(Error::WriteFailed)) .and(Ok(salt)) }) diff --git a/src/trussed_auth_impl/data.rs b/src/trussed_auth_impl/data.rs index 7924d4c..f639d0c 100644 --- a/src/trussed_auth_impl/data.rs +++ b/src/trussed_auth_impl/data.rs @@ -30,10 +30,12 @@ use trussed::{ api::NotBefore, platform::CryptoRng, service::{Filestore, RngCore}, - types::{Bytes, Location, Path, PathBuf}, + types::{Bytes, Location, Path}, }; use trussed_auth::{request, PinId, MAX_PIN_LENGTH}; +const APP_SALT_PATH: &Path = path!("application_salt"); + #[derive(Serialize, Deserialize, Debug, Clone)] enum PinSeId { Raw(PinObjectId), @@ -49,18 +51,12 @@ impl PinSeId { } } -fn app_salt_path() -> PathBuf { - const SALT_PATH: &str = "application_salt"; - - PathBuf::from(SALT_PATH) -} - pub(crate) fn get_app_salt( fs: &mut S, rng: &mut R, location: Location, ) -> Result { - if !fs.exists(&app_salt_path(), location) { + if !fs.exists(APP_SALT_PATH, location) { create_app_salt(fs, rng, location) } else { load_app_salt(fs, location) @@ -71,8 +67,8 @@ pub(crate) fn delete_app_salt( fs: &mut S, location: Location, ) -> Result<(), trussed::Error> { - if fs.exists(&app_salt_path(), location) { - fs.remove_file(&app_salt_path(), location) + if fs.exists(APP_SALT_PATH, location) { + fs.remove_file(APP_SALT_PATH, location) } else { Ok(()) } @@ -85,13 +81,13 @@ fn create_app_salt( ) -> Result { let mut salt = Salt::default(); rng.fill_bytes(&mut *salt); - fs.write(&app_salt_path(), location, &*salt) + fs.write(APP_SALT_PATH, location, &*salt) .map_err(|_| Error::WriteFailed)?; Ok(salt) } fn load_app_salt(fs: &mut S, location: Location) -> Result { - fs.read(&app_salt_path(), location) + fs.read(APP_SALT_PATH, location) .map_err(|_| Error::ReadFailed) .and_then(|b: Bytes| (**b).try_into().map_err(|_| Error::ReadFailed)) }