Skip to content
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

Update dependencies for trussed-core and ctaphid-app #34

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ description = "Administrative Trussed app for SoloKeys Solo 2 security keys"
[dependencies]
apdu-app = "0.1"
cbor-smol = { version = "0.5.0", features = ["heapless-v0-7", "heapless-bytes-v0-3"] }
ctaphid-dispatch = "0.1"
ctaphid-app = "0.1.0-rc.1"
delog = "0.1"
heapless = "0.7"
heapless-bytes = "0.3"
iso7816 = "0.1"
littlefs2 = { version = "0.5", optional = true }
littlefs2-core = { version = "0.1", features = ["heapless-bytes03"] }
serde = { version = "1.0.180", default-features = false }
strum_macros = "0.25.2"
trussed = "0.1"
trussed = { version = "0.1", default-features = false }
trussed-core = { version = "0.1.0-rc.1", features = ["crypto-client", "filesystem-client", "management-client", "ui-client"] }

embedded-hal = { version = "0.2.7", optional = true }
hex-literal = "0.4.1"
Expand All @@ -43,7 +46,6 @@ log-error = []
migration-tests = ["dep:littlefs2"]

[patch.crates-io]
ctaphid-dispatch = { git = "https://github.com/trussed-dev/ctaphid-dispatch.git", rev = "57cb3317878a8593847595319aa03ef17c29ec5b" }
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "046478b7a4f6e2315acf9112d98308379c2e3eee" }
trussed-manage = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "manage-v0.1.0" }
trussed-se050-manage = { git = "https://github.com/Nitrokey/trussed-se050-backend.git", tag = "se050-manage-v0.1.0" }
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "6bba8fde36d05c0227769eb63345744e87d84b2b" }
trussed-manage = { git = "https://github.com/trussed-dev/trussed-staging.git", rev = "9355f700831c1a278c334f76382fbf98d82aedcd" }
trussed-se050-manage = { git = "https://github.com/Nitrokey/trussed-se050-backend.git", rev = "a0bb4b92bffb2dc119fcc0cc47259ea7ed59d8a4" }
20 changes: 10 additions & 10 deletions src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use super::Client as TrussedClient;
use apdu_app::{CommandView, Interface, Status};
use cbor_smol::{cbor_deserialize, cbor_serialize_to};
use core::{convert::TryInto, marker::PhantomData, time::Duration};
use ctaphid_dispatch::app::{self as hid, Command as HidCommand, Message};
use ctaphid_dispatch::command::VendorCommand;
use ctaphid_app::{self as hid, Command as HidCommand, VendorCommand};
use heapless::Vec;
use heapless_bytes::Bytes;
#[cfg(feature = "factory-reset")]
use littlefs2_core::PathBuf;
use serde::Deserialize;
use trussed::store::Store;
use trussed::try_syscall;
use trussed::{interrupt::InterruptFlag, store::filestore::Filestore, syscall, types::Vec};
use trussed::store::{filestore::Filestore, Store};
use trussed_core::{syscall, try_syscall, InterruptFlag};

use crate::config::{self, Config, ConfigError};
use crate::migrations::Migrator;
Expand Down Expand Up @@ -531,7 +531,7 @@ where
}
}

impl<T, R, S, C> hid::App<'static> for App<T, R, S, C>
impl<T, R, S, C, const N: usize> hid::App<'static, N> for App<T, R, S, C>
where
T: TrussedClient,
R: Reboot,
Expand All @@ -554,17 +554,17 @@ where
fn call(
&mut self,
command: HidCommand,
input_data: &Message,
response: &mut Message,
) -> hid::AppResult {
input_data: &[u8],
response: &mut Bytes<N>,
) -> Result<(), hid::Error> {
let (command, input) = if command == HidCommand::Vendor(ADMIN) {
// new mode: first input byte specifies the actual command
let (command, input) = input_data.split_first().ok_or(Error::InvalidLength)?;
let command = Command::try_from(*command)?;
(command, input)
} else {
// old mode: directly use vendor commands + wink
(Command::try_from(command)?, input_data.as_slice())
(Command::try_from(command)?, input_data)
};
self.exec(command, input, response).map_err(From::from)
}
Expand Down
17 changes: 11 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use core::{
};

use cbor_smol::{cbor_deserialize, cbor_serialize_to};
use heapless::Vec;
use littlefs2_core::{path, Path};
use serde::{de::DeserializeOwned, Serialize};
use strum_macros::FromRepr;
use trussed::{
store::filestore::Filestore,
use trussed::store::filestore::Filestore;
use trussed_core::{
try_syscall,
types::{Location, Message, Vec},
Client,
types::{Location, Message},
FilesystemClient,
};

#[derive(Debug)]
Expand Down Expand Up @@ -312,7 +313,7 @@ pub fn save_filestore<F: Filestore, C: Config>(
Ok(())
}

pub fn save<T: Client, C: Config>(client: &mut T, config: &C) -> Result<(), ConfigError> {
pub fn save<T: FilesystemClient, C: Config>(client: &mut T, config: &C) -> Result<(), ConfigError> {
if config == &Default::default() {
if exists(client, LOCATION, FILENAME)? {
try_syscall!(client.remove_file(LOCATION, FILENAME.into()))
Expand All @@ -327,7 +328,11 @@ pub fn save<T: Client, C: Config>(client: &mut T, config: &C) -> Result<(), Conf
Ok(())
}

fn exists<T: Client>(client: &mut T, location: Location, path: &Path) -> Result<bool, ConfigError> {
fn exists<T: FilesystemClient>(
client: &mut T,
location: Location,
path: &Path,
) -> Result<bool, ConfigError> {
try_syscall!(client.entry_metadata(location, path.into()))
.map(|r| r.metadata.is_some())
.map_err(|_| ConfigError::ReadFailed)
Expand Down
25 changes: 21 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//! It directly implements the APDU and CTAPHID dispatch App interfaces.
#![no_std]

use trussed_core::{CryptoClient, FilesystemClient, ManagementClient, UiClient};

#[macro_use]
extern crate delog;
generate_macros!();
Expand All @@ -24,11 +26,26 @@ use trussed_manage::ManageClient;
use trussed_se050_manage::Se050ManageClient;

#[cfg(not(feature = "se050"))]
pub trait Client: trussed::Client + ManageClient {}
pub trait Client:
CryptoClient + FilesystemClient + ManagementClient + UiClient + ManageClient
{
}
#[cfg(not(feature = "se050"))]
impl<C: trussed::Client + ManageClient> Client for C {}
impl<C: CryptoClient + FilesystemClient + ManagementClient + UiClient + ManageClient> Client for C {}

#[cfg(feature = "se050")]
pub trait Client: trussed::Client + Se050ManageClient + ManageClient {}
pub trait Client:
CryptoClient + FilesystemClient + ManagementClient + UiClient + Se050ManageClient + ManageClient
{
}
#[cfg(feature = "se050")]
impl<C: trussed::Client + Se050ManageClient + ManageClient> Client for C {}
impl<
C: CryptoClient
+ FilesystemClient
+ ManagementClient
+ UiClient
+ Se050ManageClient
+ ManageClient,
> Client for C
{
}