Skip to content

Commit 2e4f660

Browse files
Split backend and extension
This patch splits the trussed-auth crate into two crates: trussed-auth only defines the AuthExtension and can be used by clients or other backends implementing the extension. trussed-auth-backend contains the AuthBackend that implements the extension using the filesystem.
1 parent a725ae6 commit 2e4f660

15 files changed

Lines changed: 294 additions & 236 deletions

File tree

Cargo.toml

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
11
# Copyright (C) Nitrokey GmbH
22
# SPDX-License-Identifier: CC0-1.0
33

4-
[package]
5-
name = "trussed-auth"
6-
version = "0.3.0"
4+
[workspace]
5+
members = ["backend", "extension"]
6+
resolver = "2"
7+
8+
[workspace.package]
79
authors = ["Nitrokey GmbH <info@nitrokey.com>"]
810
edition = "2021"
9-
repository = "https://github.com/trussed-dev/trussed-auth"
1011
license = "Apache-2.0 OR MIT"
11-
description = "Authentication extension and backend for Trussed"
12+
repository = "https://github.com/trussed-dev/trussed-auth"
1213

13-
[dependencies]
14-
chacha20poly1305 = { version = "0.10.1", default-features = false, features = ["reduced-round"] }
15-
hkdf = "0.12.3"
16-
hmac = "0.12.1"
17-
rand_core = "0.6.4"
14+
[workspace.dependencies]
1815
serde = { version = "1", default-features = false }
19-
serde-byte-array = "0.1.2"
20-
sha2 = { version = "0.10.6", default-features = false }
21-
subtle = { version = "2.4.1", default-features = false }
2216
trussed = { version = "0.1.0", features = ["serde-extensions"] }
23-
littlefs2 = "0.4.0"
24-
25-
[dev-dependencies]
26-
quickcheck = { version = "1.0.3", default-features = false }
27-
rand_core = { version = "0.6.4", default-features = false, features = ["getrandom"] }
28-
trussed = { version = "0.1.0", features = ["serde-extensions", "virt"] }
29-
admin-app = { version = "0.1.0", features = ["migration-tests"] }
3017

3118
[patch.crates-io]
19+
trussed-auth = { path = "extension" }
20+
3221
littlefs2 = { git = "https://github.com/sosthene-nitrokey/littlefs2.git", rev = "2b45a7559ff44260c6dd693e4cb61f54ae5efc53" }
3322
trussed = { git = "https://github.com/Nitrokey/trussed.git", rev = "be04182e2c74e73599a394e814d353bc4bf79484" }
3423
trussed-manage = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "manage-v0.1.0" }

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33

44
.PHONY: check
55
check:
6-
RUSTLFAGS='-Dwarnings' cargo check --all-features --all-targets
6+
RUSTLFAGS='-Dwarnings' cargo check --all-features --all-targets --workspace
77

88
.PHONY: lint
99
lint:
10-
cargo clippy --all-features --all-targets -- --deny warnings
11-
cargo fmt -- --check
12-
RUSTDOCFLAGS='-Dwarnings' cargo doc --no-deps
10+
cargo clippy --all-features --all-targets --workspace -- --deny warnings
11+
cargo fmt --all -- --check
12+
RUSTDOCFLAGS='-Dwarnings' cargo doc --no-deps --workspace
1313
reuse lint
1414

1515
.PHONY: test
1616
test:
17-
cargo test --all-features
17+
cargo test --all-features --workspace
1818

1919
.PHONY: ci
2020
ci: check lint test

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ SPDX-License-Identifier: CC0-1.0
55

66
# trussed-auth
77

8-
`trussed-auth` is an extension and custom backend for [Trussed][] that provides
9-
basic PIN handling.
8+
`trussed-auth` is an extension for [Trussed][] that provides basic PIN
9+
handling. `trussed-auth-backend` is a Trussed backend implementing that
10+
extension using the filesystem. Other implementations are provided by these
11+
backends:
12+
- [`trussed-se050-backend`][]
1013

1114
[Trussed]: https://github.com/trussed-dev/trussed
15+
[`trussed-se050-backend`]: https://github.com/Nitrokey/trussed-se050-backend
1216

1317
## License
1418

backend/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!--
2+
Copyright (C) Nitrokey GmbH
3+
SPDX-License-Identifier: CC0-1.0
4+
-->
5+
6+
# Changelog
7+
All notable changes to this project will be documented in this file.
8+
9+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
10+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
11+
12+
## Unreleased
13+
14+
Extracted from `trussed-auth` v0.3.0.
15+
16+
### Breaking Changes
17+
18+
- Remove the `dat` intermediary directory in file storage ([#39][])
19+
20+
[#39]: https://github.com/trussed-dev/trussed-auth/pull/39

backend/Cargo.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (C) Nitrokey GmbH
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
[package]
5+
name = "trussed-auth-backend"
6+
version = "0.1.0"
7+
description = "Authentication backend for Trussed"
8+
authors.workspace = true
9+
edition.workspace = true
10+
license.workspace = true
11+
repository.workspace = true
12+
13+
[dependencies]
14+
serde.workspace = true
15+
trussed.workspace = true
16+
17+
chacha20poly1305 = { version = "0.10.1", default-features = false, features = ["reduced-round"] }
18+
hkdf = "0.12.3"
19+
hmac = "0.12.1"
20+
rand_core = "0.6.4"
21+
serde-byte-array = "0.1.2"
22+
sha2 = { version = "0.10.6", default-features = false }
23+
subtle = { version = "2.4.1", default-features = false }
24+
trussed-auth = { version = "0.3.0" }
25+
littlefs2 = "0.4.0"
26+
27+
[dev-dependencies]
28+
quickcheck = { version = "1.0.3", default-features = false }
29+
rand_core = { version = "0.6.4", default-features = false, features = ["getrandom"] }
30+
trussed = { version = "0.1.0", features = ["serde-extensions", "virt"] }
31+
admin-app = { version = "0.1.0", features = ["migration-tests"] }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use trussed::{
1717
};
1818

1919
use super::Error;
20-
use crate::{Pin, PinId, MAX_PIN_LENGTH};
20+
use trussed_auth::{Pin, PinId, MAX_PIN_LENGTH};
2121

2222
pub(crate) const SIZE: usize = 256;
2323
pub(crate) const CHACHA_TAG_LEN: usize = 16;

src/backend.rs renamed to backend/src/lib.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
// Copyright (C) Nitrokey GmbH
22
// SPDX-License-Identifier: Apache-2.0 or MIT
33

4+
#![no_std]
5+
#![warn(
6+
missing_debug_implementations,
7+
missing_docs,
8+
non_ascii_idents,
9+
trivial_casts,
10+
unused,
11+
unused_qualifications,
12+
clippy::expect_used,
13+
clippy::unwrap_used
14+
)]
15+
#![deny(unsafe_code)]
16+
17+
//! A Trussed backend implementing the [`AuthExtension`][].
18+
//!
19+
//! [`AuthBackend`][] is an implementation of the [`AuthExtension`][] that stores PINs in the
20+
//! filesystem.
21+
422
mod data;
523

24+
pub mod migrate;
25+
626
use core::fmt;
727

828
use hkdf::Hkdf;
@@ -19,15 +39,11 @@ use trussed::{
1939
types::{CoreContext, Location, PathBuf},
2040
Bytes,
2141
};
42+
use trussed_auth::{reply, AuthExtension, AuthReply, AuthRequest};
2243

23-
use crate::{
24-
backend::data::{expand_app_key, get_app_salt},
25-
extension::{reply, AuthExtension, AuthReply, AuthRequest},
26-
BACKEND_DIR,
27-
};
28-
use data::{Key, PinData, Salt, KEY_LEN, SALT_LEN};
44+
use data::{delete_app_salt, expand_app_key, get_app_salt, Key, PinData, Salt, KEY_LEN, SALT_LEN};
2945

30-
use self::data::delete_app_salt;
46+
const BACKEND_DIR: &str = "backend-auth";
3147

3248
/// max accepted length for the hardware initial key material
3349
pub const MAX_HW_KEY_LEN: usize = 64;
@@ -115,7 +131,7 @@ impl AuthBackend {
115131
/// Creates a new `AuthBackend` with a missing hw key
116132
///
117133
/// Contrary to [`new`](Self::new) which uses a default `&[]` key, this will make operations depending on the hardware key to fail:
118-
/// - [`set_pin`](crate::AuthClient::set_pin) with `derive_key = true`
134+
/// - [`set_pin`](trussed_auth::AuthClient::set_pin) with `derive_key = true`
119135
/// - All operations on a pin that was created with `derive_key = true`
120136
pub fn with_missing_hw_key(location: Location, layout: FilesystemLayout) -> Self {
121137
Self {
@@ -388,7 +404,7 @@ impl ExtensionImpl<AuthExtension> for AuthBackend {
388404
}
389405

390406
#[derive(Clone, Copy, Debug)]
391-
pub(crate) enum Error {
407+
enum Error {
392408
NotFound,
393409
MissingHwKey,
394410
ReadFailed,

src/migrate.rs renamed to backend/src/migrate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn migrate_single(fs: &dyn DynFilesystem, path: &Path) -> Result<(), Error> {
3636
/// ```rust
3737
///# use littlefs2::{fs::Filesystem, const_ram_storage, path};
3838
///# use trussed::types::{LfsResult, LfsStorage};
39-
///# use trussed_auth::migrate::migrate_remove_dat;
39+
///# use trussed_auth_backend::migrate::migrate_remove_dat;
4040
///# const_ram_storage!(Storage, 4096);
4141
///# let mut storage = Storage::new();
4242
///# Filesystem::format(&mut storage);
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ mod dispatch {
1111
service::ServiceResources,
1212
types::{Bytes, Context, Location},
1313
};
14-
use trussed_auth::{AuthBackend, AuthContext, AuthExtension, MAX_HW_KEY_LEN};
14+
use trussed_auth::AuthExtension;
15+
use trussed_auth_backend::{AuthBackend, AuthContext, MAX_HW_KEY_LEN};
1516

1617
pub const BACKENDS: &[BackendId<Backend>] =
1718
&[BackendId::Custom(Backend::Auth), BackendId::Core];
@@ -55,7 +56,10 @@ mod dispatch {
5556
impl Dispatch {
5657
pub fn new() -> Self {
5758
Self {
58-
auth: AuthBackend::new(Location::Internal, trussed_auth::FilesystemLayout::V0),
59+
auth: AuthBackend::new(
60+
Location::Internal,
61+
trussed_auth_backend::FilesystemLayout::V0,
62+
),
5963
}
6064
}
6165

@@ -64,15 +68,15 @@ mod dispatch {
6468
auth: AuthBackend::with_hw_key(
6569
Location::Internal,
6670
hw_key,
67-
trussed_auth::FilesystemLayout::V0,
71+
trussed_auth_backend::FilesystemLayout::V0,
6872
),
6973
}
7074
}
7175
pub fn with_missing_hw_key() -> Self {
7276
Self {
7377
auth: AuthBackend::with_missing_hw_key(
7478
Location::Internal,
75-
trussed_auth::FilesystemLayout::V0,
79+
trussed_auth_backend::FilesystemLayout::V0,
7680
),
7781
}
7882
}
@@ -135,7 +139,8 @@ use trussed::{
135139
types::{Bytes, Location, Message, PathBuf},
136140
virt::{self, Ram},
137141
};
138-
use trussed_auth::{AuthClient as _, PinId, MAX_HW_KEY_LEN};
142+
use trussed_auth::{AuthClient as _, PinId};
143+
use trussed_auth_backend::MAX_HW_KEY_LEN;
139144

140145
use dispatch::{Backend, Dispatch, BACKENDS};
141146

CHANGELOG.md renamed to extension/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
[Unreleased]: https://github.com/trussed-dev/trussed-auth/compare/v0.3.0...HEAD
1515

16+
### Breaking Changes
17+
18+
- Extract `AuthBackend` into `trussed-auth-backend` crate
19+
1620
## [0.3.0][] - 2024-03-22
1721

1822
[0.3.0]: https://github.com/trussed-dev/trussed-auth/releases/tag/v0.3.0
1923

2024
### Breaking Changes
2125

22-
- Remove the `dat` intermediary directory in file storage ([#39][])
2326
- Add `delete_app_keys` and `delete_auth_keys` syscalls. ([#33][])
2427

2528
- `delete_all_pins` now doesn't affect application keys
@@ -37,7 +40,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3740
[#35]: https://github.com/trussed-dev/trussed-auth/pull/35
3841
[#36]: https://github.com/trussed-dev/trussed-auth/pull/36
3942
[#37]: https://github.com/trussed-dev/trussed-auth/pull/37
40-
[#39]: https://github.com/trussed-dev/trussed-auth/pull/39
4143

4244
## [0.2.2][] - 2023-04-26
4345

0 commit comments

Comments
 (0)