-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the dat
folders to save littlefs space
#39
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
46f0fed
Move trussed-auth data to get rid of the `dat` folder
sosthene-nitrokey 2642b23
Add migration helper
sosthene-nitrokey f286fb4
Add tests for migration
sosthene-nitrokey 4d985e2
Add example for migrate
sosthene-nitrokey 93aac51
Fix clippy warning
sosthene-nitrokey 5288392
Fix reuse compliance
sosthene-nitrokey 6ed1ae7
Rename migrate to migrate_remove_dat
sosthene-nitrokey 5f5439c
Remove bundled filesystem dumps
sosthene-nitrokey 861e88f
Use migration testing from trussed-staging
sosthene-nitrokey 56e3e5d
Update changelog
sosthene-nitrokey 3908149
Add migration test with empty directories
sosthene-nitrokey f0fa52f
Update trussed
sosthene-nitrokey 6827148
Use admin-app migrations
sosthene-nitrokey f89f853
Make the use of the raw backend optional
sosthene-nitrokey b792b18
Use enum rather than bool
sosthene-nitrokey 70762fe
Use tagged admin-app
sosthene-nitrokey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
// Copyright (C) Nitrokey GmbH | ||
// SPDX-License-Identifier: Apache-2.0 or MIT | ||
|
||
//! Helper to migrate from trussed-auth's legacy data layout to the new layout | ||
//! | ||
//! See [migrate]() | ||
|
||
use core::iter::once; | ||
|
||
use littlefs2::{io::Error, object_safe::DynFilesystem, path, path::Path}; | ||
|
||
fn migrate_single(fs: &dyn DynFilesystem, path: &Path) -> Result<(), Error> { | ||
let path = path.join(path!("backend-auth")); | ||
let path_dat = path.join(path!("dat")); | ||
let dir_res = fs.read_dir_and_then(&path_dat, &mut |dir| { | ||
for f in dir.skip(2) { | ||
let f = f?; | ||
let new_path = path.join(f.file_name()); | ||
fs.rename(f.path(), &new_path)?; | ||
} | ||
Ok(()) | ||
}); | ||
match dir_res { | ||
Ok(()) => fs.remove_dir(&path_dat), | ||
Err(Error::NoSuchEntry) => Ok(()), | ||
Err(_) => dir_res, | ||
} | ||
} | ||
|
||
/// Migrate the filesystem to remove the `dat` directories | ||
/// | ||
/// `apps` must be an array of paths to the apps that make use of trussed-auth | ||
/// | ||
/// Migrate does not itself keep track of whether the migration was performed | ||
/// | ||
/// ```rust | ||
///# use littlefs2::{fs::Filesystem, const_ram_storage, path}; | ||
///# use trussed::types::{LfsResult, LfsStorage}; | ||
///# use trussed_auth::migrate::migrate_remove_dat; | ||
///# const_ram_storage!(Storage, 4096); | ||
///# let mut storage = Storage::new(); | ||
///# Filesystem::format(&mut storage); | ||
///# Filesystem::mount_and_then(&mut storage, |fs| { | ||
/// migrate_remove_dat(fs, &[path!("secrets"), path!("opcard")])?; | ||
///# Ok(()) | ||
///# }).unwrap(); | ||
/// ``` | ||
pub fn migrate_remove_dat(fs: &dyn DynFilesystem, apps: &[&Path]) -> Result<(), Error> { | ||
for p in once(&path!("/")).chain(apps) { | ||
migrate_single(fs, p)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[allow(clippy::unwrap_used)] | ||
#[cfg(test)] | ||
mod tests { | ||
use admin_app::migrations::test_utils::{test_migration_one, FsValues}; | ||
|
||
use super::*; | ||
|
||
const FIDO_DAT_DIR: FsValues = FsValues::Dir(&[ | ||
(path!("persistent-state.cbor"), FsValues::File(137)), | ||
( | ||
path!("rk"), | ||
FsValues::Dir(&[( | ||
path!("74a6ea9213c99c2f"), | ||
FsValues::Dir(&[ | ||
(path!("038dfc6165b78be9"), FsValues::File(128)), | ||
(path!("1ecbbfbed8992287"), FsValues::File(122)), | ||
(path!("7c24db95312eac56"), FsValues::File(122)), | ||
(path!("978cba44dfe39871"), FsValues::File(155)), | ||
(path!("ac889a0433749726"), FsValues::File(138)), | ||
]), | ||
)]), | ||
), | ||
]); | ||
|
||
const FIDO_SEC_DIR: FsValues = FsValues::Dir(&[ | ||
( | ||
path!("069386c3c735689061ac51b8bca9f160"), | ||
FsValues::File(48), | ||
), | ||
( | ||
path!("233d86bfc2f196ff7c108cf23a282bd5"), | ||
FsValues::File(36), | ||
), | ||
( | ||
path!("2bdef14a0e18d28191162f8c1599d598"), | ||
FsValues::File(36), | ||
), | ||
( | ||
path!("3efe6394c20aa8128e27b376e226a58b"), | ||
FsValues::File(36), | ||
), | ||
( | ||
path!("4711aa79b4834ef8e551f80e523ba8d2"), | ||
FsValues::File(36), | ||
), | ||
( | ||
path!("b43bf8b7897087b7195b8ac53dcb5f11"), | ||
FsValues::File(36), | ||
), | ||
]); | ||
|
||
#[test] | ||
fn migration_nothing() { | ||
const TEST_VALUES: FsValues = FsValues::Dir(&[ | ||
( | ||
path!("fido"), | ||
FsValues::Dir(&[(path!("dat"), FIDO_DAT_DIR), (path!("sec"), FIDO_SEC_DIR)]), | ||
), | ||
( | ||
path!("trussed"), | ||
FsValues::Dir(&[( | ||
path!("dat"), | ||
FsValues::Dir(&[(path!("rng-state.bin"), FsValues::File(32))]), | ||
)]), | ||
), | ||
]); | ||
test_migration_one(&TEST_VALUES, &TEST_VALUES, |fs| { | ||
migrate_remove_dat(fs, &[path!("secrets"), path!("opcard")]) | ||
}); | ||
} | ||
|
||
#[test] | ||
fn migration_full() { | ||
const AUTH_SECRETS_DIR: FsValues = FsValues::Dir(&[ | ||
(path!("application_salt"), FsValues::File(16)), | ||
(path!("pin.00"), FsValues::File(118)), | ||
]); | ||
|
||
const TEST_BEFORE: FsValues = FsValues::Dir(&[ | ||
( | ||
path!("backend-auth"), | ||
FsValues::Dir(&[( | ||
path!("dat"), | ||
FsValues::Dir(&[(path!("salt"), FsValues::File(16))]), | ||
)]), | ||
), | ||
( | ||
path!("fido"), | ||
FsValues::Dir(&[(path!("dat"), FIDO_DAT_DIR), (path!("sec"), FIDO_SEC_DIR)]), | ||
), | ||
( | ||
path!("secrets"), | ||
FsValues::Dir(&[( | ||
path!("backend-auth"), | ||
FsValues::Dir(&[(path!("dat"), AUTH_SECRETS_DIR)]), | ||
)]), | ||
), | ||
( | ||
path!("trussed"), | ||
FsValues::Dir(&[( | ||
path!("dat"), | ||
FsValues::Dir(&[(path!("rng-state.bin"), FsValues::File(32))]), | ||
)]), | ||
), | ||
]); | ||
|
||
const TEST_AFTER: FsValues = FsValues::Dir(&[ | ||
( | ||
path!("backend-auth"), | ||
FsValues::Dir(&[(path!("salt"), FsValues::File(16))]), | ||
), | ||
( | ||
path!("fido"), | ||
FsValues::Dir(&[(path!("dat"), FIDO_DAT_DIR), (path!("sec"), FIDO_SEC_DIR)]), | ||
), | ||
( | ||
path!("secrets"), | ||
FsValues::Dir(&[(path!("backend-auth"), AUTH_SECRETS_DIR)]), | ||
), | ||
( | ||
path!("trussed"), | ||
FsValues::Dir(&[( | ||
path!("dat"), | ||
FsValues::Dir(&[(path!("rng-state.bin"), FsValues::File(32))]), | ||
)]), | ||
), | ||
]); | ||
|
||
test_migration_one(&TEST_BEFORE, &TEST_AFTER, |fs| { | ||
migrate_remove_dat(fs, &[path!("secrets"), path!("opcard")]) | ||
}); | ||
} | ||
|
||
#[test] | ||
fn migration_empty() { | ||
const TEST_VALUES: FsValues = FsValues::Dir(&[ | ||
( | ||
path!("fido"), | ||
FsValues::Dir(&[(path!("dat"), FIDO_DAT_DIR), (path!("sec"), FIDO_SEC_DIR)]), | ||
), | ||
( | ||
path!("trussed"), | ||
FsValues::Dir(&[( | ||
path!("dat"), | ||
FsValues::Dir(&[(path!("rng-state.bin"), FsValues::File(32))]), | ||
)]), | ||
), | ||
]); | ||
test_migration_one(&TEST_VALUES, &TEST_VALUES, |fs| { | ||
migrate_remove_dat(fs, &[path!("secrets"), path!("opcard")]) | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unneeded dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right admin-app can
dev-dependency
only.