From f14ca92633462dbe25db5ac312f4e52d1b414cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Tue, 23 May 2023 10:21:22 +0200 Subject: [PATCH 1/6] Add support for request cancellation --- Cargo.lock | 37 +++++++++------ Cargo.toml | 22 ++++----- components/apps/Cargo.toml | 2 +- components/apps/src/lib.rs | 46 +++++++++++++++---- components/provisioner-app/src/ctaphid.rs | 2 +- runners/embedded/Cargo.toml | 1 + runners/embedded/src/lib.rs | 7 ++- .../embedded/src/soc_nrf52840/trussed_ui.rs | 2 +- runners/embedded/src/types.rs | 2 +- runners/embedded/src/types/usbnfc.rs | 4 +- 10 files changed, 85 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae9d0862..1e0f799f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,7 +5,7 @@ version = 3 [[package]] name = "admin-app" version = "0.1.0" -source = "git+https://github.com/Nitrokey/admin-app?tag=v0.1.0-nitrokey.2#398f9b258d8cfab57a9353fcb61818f162db41c8" +source = "git+https://github.com/Nitrokey/admin-app?tag=v0.1.0-nitrokey.3#15aec92ff3f30f2ad1ff157ac5077c7211a04c77" dependencies = [ "apdu-dispatch", "ctaphid-dispatch", @@ -73,7 +73,7 @@ checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" [[package]] name = "apdu-dispatch" version = "0.1.2" -source = "git+https://github.com/trussed-dev/apdu-dispatch.git?rev=b72d5eb9f4d7a3f107a78a2f0e41f3c403f4c7a4#b72d5eb9f4d7a3f107a78a2f0e41f3c403f4c7a4" +source = "git+https://github.com/trussed-dev/apdu-dispatch?rev=b72d5eb9f4d7a3f107a78a2f0e41f3c403f4c7a4#b72d5eb9f4d7a3f107a78a2f0e41f3c403f4c7a4" dependencies = [ "delog", "heapless 0.7.16", @@ -763,12 +763,14 @@ dependencies = [ [[package]] name = "ctaphid-dispatch" version = "0.1.1" -source = "git+https://github.com/trussed-dev/ctaphid-dispatch?rev=d9eb980da163b613fdf759f6092b7c3bdcc0a22c#d9eb980da163b613fdf759f6092b7c3bdcc0a22c" +source = "git+https://github.com/Nitrokey/ctaphid-dispatch?tag=v0.1.1-nitrokey.2#57cb3317878a8593847595319aa03ef17c29ec5b" dependencies = [ "delog", "heapless 0.7.16", "heapless-bytes 0.3.0", "interchange 0.3.0", + "ref-swap", + "trussed", ] [[package]] @@ -972,6 +974,7 @@ dependencies = [ "nrf52840-hal", "nrf52840-pac", "rand_core", + "ref-swap", "rtt-target", "serde", "spi-memory", @@ -1003,7 +1006,7 @@ dependencies = [ [[package]] name = "encrypted_container" version = "0.1.0" -source = "git+https://github.com/Nitrokey/trussed-secrets-app?tag=0.11.0#7d3dbe963815500e3cc3abc8f56ff92d62328da4" +source = "git+https://github.com/Nitrokey/trussed-secrets-app?rev=75626206ca3410fdcef0bb77cd7fd7962054f077#75626206ca3410fdcef0bb77cd7fd7962054f077" dependencies = [ "cbor-smol", "delog", @@ -1049,7 +1052,7 @@ dependencies = [ [[package]] name = "fido-authenticator" version = "0.1.1" -source = "git+https://github.com/Nitrokey/fido-authenticator.git?tag=v0.1.1-nitrokey.4#857899bff75331b2c9a419f95457f541440c3a0d" +source = "git+https://github.com/Nitrokey/fido-authenticator.git?tag=v0.1.1-nitrokey.5#c471c81e25506d40b03f22f1b56fbc3441220ab8" dependencies = [ "apdu-dispatch", "ctap-types", @@ -2335,6 +2338,12 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "ref-swap" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c30c54dffee5b40af088d5d50aa3455c91a0127164b51f0215efc4cb28fb3c" + [[package]] name = "regex" version = "1.7.3" @@ -2495,8 +2504,8 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "secrets-app" -version = "0.11.0" -source = "git+https://github.com/Nitrokey/trussed-secrets-app?tag=0.11.0#7d3dbe963815500e3cc3abc8f56ff92d62328da4" +version = "0.12.0" +source = "git+https://github.com/Nitrokey/trussed-secrets-app?rev=75626206ca3410fdcef0bb77cd7fd7962054f077#75626206ca3410fdcef0bb77cd7fd7962054f077" dependencies = [ "apdu-dispatch", "bitflags 2.3.1", @@ -2982,7 +2991,7 @@ dependencies = [ [[package]] name = "trussed" version = "0.1.0" -source = "git+https://github.com/Nitrokey/trussed?tag=v0.1.0-nitrokey.11#686aa7064de6a9cfb315c1903c1440f46cc8e840" +source = "git+https://github.com/Nitrokey/trussed?tag=v0.1.0-nitrokey.12#f3c95ab16fe6f9357a5d792e709e93d06c304b34" dependencies = [ "aes", "bitflags 1.3.2", @@ -3019,7 +3028,7 @@ dependencies = [ [[package]] name = "trussed-auth" version = "0.2.2" -source = "git+https://github.com/trussed-dev/trussed-auth?tag=v0.2.2#d704b046acb7b766a89adb95539805ee705b6710" +source = "git+https://github.com/Nitrokey/trussed-auth?tag=v0.2.2-nitrokey.1#203a90dd13a7378f596b3099cd986a8da6185137" dependencies = [ "chacha20poly1305", "hkdf", @@ -3049,7 +3058,7 @@ dependencies = [ [[package]] name = "trussed-staging" version = "0.1.0" -source = "git+https://github.com/Nitrokey/trussed-staging.git?tag=v0.1.0#5d7816e921d9279e4e2e3f2755039839986ea7e5" +source = "git+https://github.com/Nitrokey/trussed-staging.git?tag=v0.1.0-nitrokey.1#c6aa6bdd65f04eb746a2d65725ba2d01c27ae1f7" dependencies = [ "chacha20poly1305", "delog", @@ -3063,7 +3072,7 @@ dependencies = [ [[package]] name = "trussed-usbip" version = "0.0.1" -source = "git+https://github.com/trussed-dev/pc-usbip-runner?rev=083fca7693a9a910dd2337d8eaf9d50ccd1987d0#083fca7693a9a910dd2337d8eaf9d50ccd1987d0" +source = "git+https://github.com/trussed-dev/pc-usbip-runner?rev=e78883847fb01ac93179074ff29e13a0d470775b#e78883847fb01ac93179074ff29e13a0d470775b" dependencies = [ "apdu-dispatch", "ctaphid-dispatch", @@ -3172,7 +3181,7 @@ checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508" [[package]] name = "usbd-ccid" version = "0.2.0" -source = "git+https://github.com/trussed-dev/usbd-ccid?rev=eeea54f85cfa69a43c676b63c030608830ea35ea#eeea54f85cfa69a43c676b63c030608830ea35ea" +source = "git+https://github.com/Nitrokey/usbd-ccid?tag=v0.2.0-nitrokey.1#eeea54f85cfa69a43c676b63c030608830ea35ea" dependencies = [ "delog", "embedded-time", @@ -3185,7 +3194,7 @@ dependencies = [ [[package]] name = "usbd-ctaphid" version = "0.1.0" -source = "git+https://github.com/trussed-dev/usbd-ctaphid?rev=2f658fbe84e262037621b15cb867424c4a60b038#2f658fbe84e262037621b15cb867424c4a60b038" +source = "git+https://github.com/trussed-dev/usbd-ctaphid?rev=e9cbf904f548979685c4c06d75479b75e3695160#e9cbf904f548979685c4c06d75479b75e3695160" dependencies = [ "ctap-types", "ctaphid-dispatch", @@ -3194,7 +3203,9 @@ dependencies = [ "heapless 0.7.16", "heapless-bytes 0.3.0", "interchange 0.3.0", + "ref-swap", "serde", + "trussed", "usb-device", ] diff --git a/Cargo.toml b/Cargo.toml index 58903495..2957be3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,27 +12,27 @@ version = "1.5.0-test.20230613" [patch.crates-io] # forked -admin-app = { git = "https://github.com/Nitrokey/admin-app", tag = "v0.1.0-nitrokey.2" } +admin-app = { git = "https://github.com/Nitrokey/admin-app", tag = "v0.1.0-nitrokey.3" } ctap-types = { git = "https://github.com/Nitrokey/ctap-types", tag = "v0.1.2-nitrokey.1" } -fido-authenticator = { git = "https://github.com/Nitrokey/fido-authenticator.git", tag = "v0.1.1-nitrokey.4" } +fido-authenticator = { git = "https://github.com/Nitrokey/fido-authenticator.git", tag = "v0.1.1-nitrokey.5" } lpc55-hal = { git = "https://github.com/Nitrokey/lpc55-hal", tag = "v0.3.0-nitrokey.2" } -trussed = { git = "https://github.com/Nitrokey/trussed", tag = "v0.1.0-nitrokey.11" } +trussed = { git = "https://github.com/Nitrokey/trussed", tag = "v0.1.0-nitrokey.12" } # unreleased upstream changes -usbd-ctaphid = { git = "https://github.com/trussed-dev/usbd-ctaphid", rev = "2f658fbe84e262037621b15cb867424c4a60b038" } -usbd-ccid = { git = "https://github.com/trussed-dev/usbd-ccid", rev = "eeea54f85cfa69a43c676b63c030608830ea35ea" } -ctaphid-dispatch = { git = "https://github.com/trussed-dev/ctaphid-dispatch", rev = "d9eb980da163b613fdf759f6092b7c3bdcc0a22c" } -apdu-dispatch = { git = "https://github.com/trussed-dev/apdu-dispatch.git", rev = "b72d5eb9f4d7a3f107a78a2f0e41f3c403f4c7a4" } +usbd-ctaphid = { git = "https://github.com/trussed-dev/usbd-ctaphid", rev = "e9cbf904f548979685c4c06d75479b75e3695160" } +usbd-ccid = { git = "https://github.com/Nitrokey/usbd-ccid", tag = "v0.2.0-nitrokey.1" } +ctaphid-dispatch = { git = "https://github.com/Nitrokey/ctaphid-dispatch", tag = "v0.1.1-nitrokey.2" } +apdu-dispatch = { git = "https://github.com/trussed-dev/apdu-dispatch", rev = "b72d5eb9f4d7a3f107a78a2f0e41f3c403f4c7a4" } # unreleased crates -secrets-app = { git = "https://github.com/Nitrokey/trussed-secrets-app", tag = "0.11.0" } +secrets-app = { git = "https://github.com/Nitrokey/trussed-secrets-app", rev = "75626206ca3410fdcef0bb77cd7fd7962054f077" } opcard = { git = "https://github.com/Nitrokey/opcard-rs", tag = "v1.1.0" } piv-authenticator = { git = "https://github.com/Nitrokey/piv-authenticator", tag = "v0.3.2" } -trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth", tag = "v0.2.2" } +trussed-auth = { git = "https://github.com/Nitrokey/trussed-auth", tag = "v0.2.2-nitrokey.1" } trussed-rsa-alloc = { git = "https://github.com/Nitrokey/trussed-rsa-backend.git", tag = "v0.1.0"} -trussed-staging = { git = "https://github.com/Nitrokey/trussed-staging.git", tag = "v0.1.0"} +trussed-staging = { git = "https://github.com/Nitrokey/trussed-staging.git", tag = "v0.1.0-nitrokey.1"} iso7816 = { git = "https://github.com/Nitrokey/iso7816.git", tag = "v0.1.1-nitrokey.1" } -trussed-usbip = { git = "https://github.com/trussed-dev/pc-usbip-runner", rev = "083fca7693a9a910dd2337d8eaf9d50ccd1987d0" } +trussed-usbip = { git = "https://github.com/trussed-dev/pc-usbip-runner", rev = "e78883847fb01ac93179074ff29e13a0d470775b" } [profile.release] codegen-units = 1 diff --git a/components/apps/Cargo.toml b/components/apps/Cargo.toml index 03bbcf15..b548a7bb 100644 --- a/components/apps/Cargo.toml +++ b/components/apps/Cargo.toml @@ -20,7 +20,7 @@ trussed-staging = { version = "0.1.0", features = ["wrap-key-to-file", "chunked" admin-app = { version = "0.1.0", optional = true } fido-authenticator = { version = "0.1.1", features = ["dispatch"], optional = true } ndef-app = { path = "../ndef-app", optional = true } -secrets-app = { version = "0.11.0", features = ["apdu-dispatch", "ctaphid"], optional = true } +secrets-app = { version = "0.12.0", features = ["apdu-dispatch", "ctaphid"], optional = true } opcard = { version = "1.1.0", features = ["apdu-dispatch", "delog", "rsa2048-gen", "rsa4096"], optional = true } piv-authenticator = { version = "0.3.1", features = ["apdu-dispatch", "delog"], optional = true } provisioner-app = { path = "../provisioner-app", optional = true } diff --git a/components/apps/src/lib.rs b/components/apps/src/lib.rs index 085230ca..720e20e8 100644 --- a/components/apps/src/lib.rs +++ b/components/apps/src/lib.rs @@ -9,6 +9,7 @@ use core::marker::PhantomData; use ctaphid_dispatch::app::App as CtaphidApp; use trussed::{ backend::BackendId, client::ClientBuilder, platform::Syscall, ClientImplementation, Platform, + interrupt::InterruptFlag, Service, }; @@ -113,7 +114,7 @@ pub struct Apps { impl Apps { pub fn new( runner: &R, - mut make_client: impl FnMut(&str, &'static [BackendId]) -> Client, + mut make_client: impl FnMut(&str, &'static [BackendId], Option<&'static InterruptFlag>) -> Client, data: Data, ) -> Self { let _ = (runner, &mut make_client); @@ -153,9 +154,10 @@ impl Apps { { Self::new( runner, - |id, backends| { + |id, backends, interrupt| { ClientBuilder::new(id) .backends(backends) + .interrupt(interrupt) .prepare(trussed) .unwrap() .build(R::Syscall::default()) @@ -188,7 +190,7 @@ impl Apps { pub fn ctaphid_dispatch(&mut self, f: F) -> T where - F: FnOnce(&mut [&mut dyn CtaphidApp]) -> T, + F: FnOnce(&mut [&mut dyn CtaphidApp<'static>]) -> T, { f(&mut [ #[cfg(feature = "fido-authenticator")] @@ -204,7 +206,7 @@ impl Apps { } #[cfg(feature = "trussed-usbip")] -impl trussed_usbip::Apps, Dispatch> for Apps { +impl trussed_usbip::Apps<'static, Client, Dispatch> for Apps { type Data = (R, Data); fn new(builder: &B, (runner, data): (R, Data)) -> Self @@ -213,12 +215,12 @@ impl trussed_usbip::Apps, Dispatch> for Apps { { Self::new( &runner, - move |id, backends| builder.build(id, backends), + move |id, backends, _| builder.build(id, backends), data, ) } - fn with_ctaphid_apps(&mut self, f: impl FnOnce(&mut [&mut dyn CtaphidApp]) -> T) -> T { + fn with_ctaphid_apps(&mut self, f: impl FnOnce(&mut [&mut dyn CtaphidApp<'static>]) -> T) -> T { self.ctaphid_dispatch(f) } @@ -239,11 +241,11 @@ trait App: Sized { fn new( runner: &R, - make_client: impl FnOnce(&str, &'static [BackendId]) -> Client, + make_client: impl FnOnce(&str, &'static [BackendId], Option<&'static InterruptFlag>) -> Client, data: Self::Data, ) -> Self { let backends = Self::backends(runner); - Self::with_client(runner, make_client(Self::CLIENT_ID, backends), data) + Self::with_client(runner, make_client(Self::CLIENT_ID, backends, Self::interrupt()), data) } fn with_client(runner: &R, trussed: Client, data: Self::Data) -> Self; @@ -253,6 +255,10 @@ trait App: Sized { const BACKENDS_DEFAULT: &[BackendId] = &[]; BACKENDS_DEFAULT } + + fn interrupt() -> Option<&'static InterruptFlag> { + None + } } #[cfg(feature = "admin-app")] @@ -327,6 +333,10 @@ impl App for AdminApp { data.encode(), ) } + fn interrupt() -> Option<&'static InterruptFlag> { + static INTERRUPT: InterruptFlag = InterruptFlag::new(); + Some(&INTERRUPT) + } } #[cfg(feature = "fido-authenticator")] @@ -346,6 +356,10 @@ impl App for FidoApp { }, ) } + fn interrupt() -> Option<&'static InterruptFlag> { + static INTERRUPT: InterruptFlag = InterruptFlag::new(); + Some(&INTERRUPT) + } } #[cfg(feature = "secrets-app")] @@ -371,6 +385,10 @@ impl App for SecretsApp { let _ = runner; BACKENDS_OATH } + fn interrupt() -> Option<&'static InterruptFlag> { + static INTERRUPT: InterruptFlag = InterruptFlag::new(); + Some(&INTERRUPT) + } } #[cfg(feature = "opcard")] @@ -399,6 +417,10 @@ impl App for OpcardApp { let _ = runner; BACKENDS_OPCARD } + fn interrupt() -> Option<&'static InterruptFlag> { + static INTERRUPT: InterruptFlag = InterruptFlag::new(); + Some(&INTERRUPT) + } } #[cfg(feature = "piv-authenticator")] @@ -423,6 +445,10 @@ impl App for PivApp { let _ = runner; BACKENDS_PIV } + fn interrupt() -> Option<&'static InterruptFlag> { + static INTERRUPT: InterruptFlag = InterruptFlag::new(); + Some(&INTERRUPT) + } } #[cfg(feature = "provisioner-app")] @@ -450,4 +476,8 @@ impl App for ProvisionerApp { data.rebooter, ) } + fn interrupt() -> Option<&'static InterruptFlag> { + static INTERRUPT: InterruptFlag = InterruptFlag::new(); + Some(&INTERRUPT) + } } diff --git a/components/provisioner-app/src/ctaphid.rs b/components/provisioner-app/src/ctaphid.rs index e9b4742e..0d791283 100644 --- a/components/provisioner-app/src/ctaphid.rs +++ b/components/provisioner-app/src/ctaphid.rs @@ -9,7 +9,7 @@ use trussed::{client, store::Store, types::LfsStorage, Client}; const COMMAND_PROVISIONER: VendorCommand = VendorCommand::H71; -impl App for Provisioner +impl App<'static> for Provisioner where S: Store, FS: 'static + LfsStorage, diff --git a/runners/embedded/Cargo.toml b/runners/embedded/Cargo.toml index b1cb53ba..1c4d10d7 100644 --- a/runners/embedded/Cargo.toml +++ b/runners/embedded/Cargo.toml @@ -61,6 +61,7 @@ systick-monotonic = { version = "1.0.0", optional = true } ### Allocator alloc-cortex-m = { version = "0.4.3", optional = true } bitflags = "1.3.2" +ref-swap = "0.1.0" [build-dependencies] cargo-lock = "7" diff --git a/runners/embedded/src/lib.rs b/runners/embedded/src/lib.rs index e0645566..ae0f2cca 100644 --- a/runners/embedded/src/lib.rs +++ b/runners/embedded/src/lib.rs @@ -177,10 +177,13 @@ pub fn init_usb_nfc( let config = ::INTERFACE_CONFIG; use apdu_dispatch::interchanges::Channel as CcidChannel; + use trussed::interrupt::InterruptFlag; + use ref_swap::OptionRefSwap; use ctaphid_dispatch::types::Channel as CtapChannel; static CCID_CHANNEL: CcidChannel = Channel::new(); static NFC_CHANNEL: CcidChannel = Channel::new(); static CTAP_CHANNEL: CtapChannel = Channel::new(); + static CTAP_INTERRUPT: OptionRefSwap<'static, InterruptFlag> = OptionRefSwap::new(None); /* claim interchanges */ let (ccid_rq, ccid_rp) = CCID_CHANNEL.split().unwrap(); let (nfc_rq, nfc_rp) = NFC_CHANNEL.split().unwrap(); @@ -188,7 +191,7 @@ pub fn init_usb_nfc( /* initialize dispatchers */ let apdu_dispatch = apdu_dispatch::dispatch::ApduDispatch::new(ccid_rp, nfc_rp); - let ctaphid_dispatch = ctaphid_dispatch::dispatch::Dispatch::new(ctaphid_rp); + let ctaphid_dispatch = ctaphid_dispatch::dispatch::Dispatch::with_interrupt(ctaphid_rp, Some(&CTAP_INTERRUPT)); /* populate requesters (if bus options are provided) */ let mut usb_classes = None; @@ -198,7 +201,7 @@ pub fn init_usb_nfc( let ccid = usbd_ccid::Ccid::new(usbbus, ccid_rq, Some(config.card_issuer)); /* Class #2: CTAPHID */ - let ctaphid = usbd_ctaphid::CtapHid::new(usbbus, ctaphid_rq, 0u32) + let ctaphid = usbd_ctaphid::CtapHid::with_interrupt(usbbus, ctaphid_rq, Some(&CTAP_INTERRUPT), 0u32) .implements_ctap1() .implements_ctap2() .implements_wink(); diff --git a/runners/embedded/src/soc_nrf52840/trussed_ui.rs b/runners/embedded/src/soc_nrf52840/trussed_ui.rs index b0dd1c3c..9750ab8d 100644 --- a/runners/embedded/src/soc_nrf52840/trussed_ui.rs +++ b/runners/embedded/src/soc_nrf52840/trussed_ui.rs @@ -93,7 +93,7 @@ where let threshold: u8 = 1; let start_time = self.uptime().as_millis(); - let timeout_at = start_time + 28_000u128; + let timeout_at = start_time + 1_000u128; let mut next_check = start_time + 25u128; self.set_status(ui::Status::WaitingForUserPresence); diff --git a/runners/embedded/src/types.rs b/runners/embedded/src/types.rs index a92aa09d..f6a1301f 100644 --- a/runners/embedded/src/types.rs +++ b/runners/embedded/src/types.rs @@ -129,7 +129,7 @@ pub type Trussed = trussed::Service; pub type Iso14443 = nfc_device::Iso14443<::NfcDevice>; pub type ApduDispatch = apdu_dispatch::dispatch::ApduDispatch<'static>; -pub type CtaphidDispatch = ctaphid_dispatch::dispatch::Dispatch<'static>; +pub type CtaphidDispatch = ctaphid_dispatch::dispatch::Dispatch<'static, 'static>; pub type Apps = apps::Apps; diff --git a/runners/embedded/src/types/usbnfc.rs b/runners/embedded/src/types/usbnfc.rs index 1c00d4b7..391abf30 100644 --- a/runners/embedded/src/types/usbnfc.rs +++ b/runners/embedded/src/types/usbnfc.rs @@ -3,7 +3,7 @@ use crate::types::Soc; pub type CcidClass = usbd_ccid::Ccid<'static, 'static, ::UsbBus, { apdu_dispatch::interchanges::SIZE }>; -pub type CtapHidClass = usbd_ctaphid::CtapHid<'static, 'static, ::UsbBus>; +pub type CtapHidClass = usbd_ctaphid::CtapHid<'static, 'static,'static, ::UsbBus>; // pub type KeyboardClass = usbd_hid::hid_class::HIDClass<'static, ::UsbBus>; pub type SerialClass = usbd_serial::SerialPort<'static, ::UsbBus>; @@ -37,6 +37,6 @@ impl UsbClasses { pub struct UsbNfcInit { pub usb_classes: Option, pub apdu_dispatch: apdu_dispatch::dispatch::ApduDispatch<'static>, - pub ctaphid_dispatch: ctaphid_dispatch::dispatch::Dispatch<'static>, + pub ctaphid_dispatch: ctaphid_dispatch::dispatch::Dispatch<'static, 'static>, pub iso14443: Option, } From 74a6285be83efba736d29afc4161b152ac2f9c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Tue, 23 May 2023 10:53:04 +0200 Subject: [PATCH 2/6] Run cargo fmt --- components/apps/src/lib.rs | 28 +++++++++++++++++++++------- runners/embedded/src/lib.rs | 16 +++++++++------- runners/embedded/src/types/usbnfc.rs | 2 +- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/components/apps/src/lib.rs b/components/apps/src/lib.rs index 720e20e8..ebf02ef7 100644 --- a/components/apps/src/lib.rs +++ b/components/apps/src/lib.rs @@ -8,9 +8,8 @@ use apdu_dispatch::{ use core::marker::PhantomData; use ctaphid_dispatch::app::App as CtaphidApp; use trussed::{ - backend::BackendId, client::ClientBuilder, platform::Syscall, ClientImplementation, Platform, - interrupt::InterruptFlag, - Service, + backend::BackendId, client::ClientBuilder, interrupt::InterruptFlag, platform::Syscall, + ClientImplementation, Platform, Service, }; #[cfg(feature = "admin-app")] @@ -114,7 +113,11 @@ pub struct Apps { impl Apps { pub fn new( runner: &R, - mut make_client: impl FnMut(&str, &'static [BackendId], Option<&'static InterruptFlag>) -> Client, + mut make_client: impl FnMut( + &str, + &'static [BackendId], + Option<&'static InterruptFlag>, + ) -> Client, data: Data, ) -> Self { let _ = (runner, &mut make_client); @@ -220,7 +223,10 @@ impl trussed_usbip::Apps<'static, Client, Dispatch> for Apps { ) } - fn with_ctaphid_apps(&mut self, f: impl FnOnce(&mut [&mut dyn CtaphidApp<'static>]) -> T) -> T { + fn with_ctaphid_apps( + &mut self, + f: impl FnOnce(&mut [&mut dyn CtaphidApp<'static>]) -> T, + ) -> T { self.ctaphid_dispatch(f) } @@ -241,11 +247,19 @@ trait App: Sized { fn new( runner: &R, - make_client: impl FnOnce(&str, &'static [BackendId], Option<&'static InterruptFlag>) -> Client, + make_client: impl FnOnce( + &str, + &'static [BackendId], + Option<&'static InterruptFlag>, + ) -> Client, data: Self::Data, ) -> Self { let backends = Self::backends(runner); - Self::with_client(runner, make_client(Self::CLIENT_ID, backends, Self::interrupt()), data) + Self::with_client( + runner, + make_client(Self::CLIENT_ID, backends, Self::interrupt()), + data, + ) } fn with_client(runner: &R, trussed: Client, data: Self::Data) -> Self; diff --git a/runners/embedded/src/lib.rs b/runners/embedded/src/lib.rs index ae0f2cca..5ee188c5 100644 --- a/runners/embedded/src/lib.rs +++ b/runners/embedded/src/lib.rs @@ -177,9 +177,9 @@ pub fn init_usb_nfc( let config = ::INTERFACE_CONFIG; use apdu_dispatch::interchanges::Channel as CcidChannel; - use trussed::interrupt::InterruptFlag; - use ref_swap::OptionRefSwap; use ctaphid_dispatch::types::Channel as CtapChannel; + use ref_swap::OptionRefSwap; + use trussed::interrupt::InterruptFlag; static CCID_CHANNEL: CcidChannel = Channel::new(); static NFC_CHANNEL: CcidChannel = Channel::new(); static CTAP_CHANNEL: CtapChannel = Channel::new(); @@ -191,7 +191,8 @@ pub fn init_usb_nfc( /* initialize dispatchers */ let apdu_dispatch = apdu_dispatch::dispatch::ApduDispatch::new(ccid_rp, nfc_rp); - let ctaphid_dispatch = ctaphid_dispatch::dispatch::Dispatch::with_interrupt(ctaphid_rp, Some(&CTAP_INTERRUPT)); + let ctaphid_dispatch = + ctaphid_dispatch::dispatch::Dispatch::with_interrupt(ctaphid_rp, Some(&CTAP_INTERRUPT)); /* populate requesters (if bus options are provided) */ let mut usb_classes = None; @@ -201,10 +202,11 @@ pub fn init_usb_nfc( let ccid = usbd_ccid::Ccid::new(usbbus, ccid_rq, Some(config.card_issuer)); /* Class #2: CTAPHID */ - let ctaphid = usbd_ctaphid::CtapHid::with_interrupt(usbbus, ctaphid_rq, Some(&CTAP_INTERRUPT), 0u32) - .implements_ctap1() - .implements_ctap2() - .implements_wink(); + let ctaphid = + usbd_ctaphid::CtapHid::with_interrupt(usbbus, ctaphid_rq, Some(&CTAP_INTERRUPT), 0u32) + .implements_ctap1() + .implements_ctap2() + .implements_wink(); /* Class #3: Serial */ let serial = usbd_serial::SerialPort::new(usbbus); diff --git a/runners/embedded/src/types/usbnfc.rs b/runners/embedded/src/types/usbnfc.rs index 391abf30..10d21996 100644 --- a/runners/embedded/src/types/usbnfc.rs +++ b/runners/embedded/src/types/usbnfc.rs @@ -3,7 +3,7 @@ use crate::types::Soc; pub type CcidClass = usbd_ccid::Ccid<'static, 'static, ::UsbBus, { apdu_dispatch::interchanges::SIZE }>; -pub type CtapHidClass = usbd_ctaphid::CtapHid<'static, 'static,'static, ::UsbBus>; +pub type CtapHidClass = usbd_ctaphid::CtapHid<'static, 'static, 'static, ::UsbBus>; // pub type KeyboardClass = usbd_hid::hid_class::HIDClass<'static, ::UsbBus>; pub type SerialClass = usbd_serial::SerialPort<'static, ::UsbBus>; From cb101566550118bf7185cb99bd1faaa9264b6021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Wed, 21 Jun 2023 09:48:03 +0200 Subject: [PATCH 3/6] Use tag for pc-usbip-runner --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e0f799f..45156e47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3072,7 +3072,7 @@ dependencies = [ [[package]] name = "trussed-usbip" version = "0.0.1" -source = "git+https://github.com/trussed-dev/pc-usbip-runner?rev=e78883847fb01ac93179074ff29e13a0d470775b#e78883847fb01ac93179074ff29e13a0d470775b" +source = "git+https://github.com/Nitrokey/pc-usbip-runner?tag=v0.0.1-nitrokey.1#e78883847fb01ac93179074ff29e13a0d470775b" dependencies = [ "apdu-dispatch", "ctaphid-dispatch", diff --git a/Cargo.toml b/Cargo.toml index 2957be3e..5483f625 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ trussed-auth = { git = "https://github.com/Nitrokey/trussed-auth", tag = "v0.2.2 trussed-rsa-alloc = { git = "https://github.com/Nitrokey/trussed-rsa-backend.git", tag = "v0.1.0"} trussed-staging = { git = "https://github.com/Nitrokey/trussed-staging.git", tag = "v0.1.0-nitrokey.1"} iso7816 = { git = "https://github.com/Nitrokey/iso7816.git", tag = "v0.1.1-nitrokey.1" } -trussed-usbip = { git = "https://github.com/trussed-dev/pc-usbip-runner", rev = "e78883847fb01ac93179074ff29e13a0d470775b" } +trussed-usbip = { git = "https://github.com/Nitrokey/pc-usbip-runner", tag = "v0.0.1-nitrokey.1" } [profile.release] codegen-units = 1 From 8cd830ba4af0179b1d768ad9406034153a0b4436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Wed, 21 Jun 2023 09:49:29 +0200 Subject: [PATCH 4/6] Use tag for apdu-dispatch --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45156e47..54e520c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,7 +73,7 @@ checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" [[package]] name = "apdu-dispatch" version = "0.1.2" -source = "git+https://github.com/trussed-dev/apdu-dispatch?rev=b72d5eb9f4d7a3f107a78a2f0e41f3c403f4c7a4#b72d5eb9f4d7a3f107a78a2f0e41f3c403f4c7a4" +source = "git+https://github.com/Nitrokey/apdu-dispatch?tag=v0.1.2-nitrokey.1#b72d5eb9f4d7a3f107a78a2f0e41f3c403f4c7a4" dependencies = [ "delog", "heapless 0.7.16", diff --git a/Cargo.toml b/Cargo.toml index 5483f625..3f94ce08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ trussed = { git = "https://github.com/Nitrokey/trussed", tag = "v0.1.0-nitrokey. usbd-ctaphid = { git = "https://github.com/trussed-dev/usbd-ctaphid", rev = "e9cbf904f548979685c4c06d75479b75e3695160" } usbd-ccid = { git = "https://github.com/Nitrokey/usbd-ccid", tag = "v0.2.0-nitrokey.1" } ctaphid-dispatch = { git = "https://github.com/Nitrokey/ctaphid-dispatch", tag = "v0.1.1-nitrokey.2" } -apdu-dispatch = { git = "https://github.com/trussed-dev/apdu-dispatch", rev = "b72d5eb9f4d7a3f107a78a2f0e41f3c403f4c7a4" } +apdu-dispatch = { git = "https://github.com/Nitrokey/apdu-dispatch", tag = "v0.1.2-nitrokey.1" } # unreleased crates secrets-app = { git = "https://github.com/Nitrokey/trussed-secrets-app", rev = "75626206ca3410fdcef0bb77cd7fd7962054f077" } From 99532130abad028f8c9d2ad17243eeb6b9e4653b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Wed, 21 Jun 2023 10:40:17 +0200 Subject: [PATCH 5/6] Use usbd-ctaphid tags --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54e520c9..6337f77e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3194,7 +3194,7 @@ dependencies = [ [[package]] name = "usbd-ctaphid" version = "0.1.0" -source = "git+https://github.com/trussed-dev/usbd-ctaphid?rev=e9cbf904f548979685c4c06d75479b75e3695160#e9cbf904f548979685c4c06d75479b75e3695160" +source = "git+https://github.com/Nitrokey/usbd-ctaphid?tag=v0.1.0-nitrokey.1#e9cbf904f548979685c4c06d75479b75e3695160" dependencies = [ "ctap-types", "ctaphid-dispatch", diff --git a/Cargo.toml b/Cargo.toml index 3f94ce08..20f9a1f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ lpc55-hal = { git = "https://github.com/Nitrokey/lpc55-hal", tag = "v0.3.0-nitro trussed = { git = "https://github.com/Nitrokey/trussed", tag = "v0.1.0-nitrokey.12" } # unreleased upstream changes -usbd-ctaphid = { git = "https://github.com/trussed-dev/usbd-ctaphid", rev = "e9cbf904f548979685c4c06d75479b75e3695160" } +usbd-ctaphid = { git = "https://github.com/Nitrokey/usbd-ctaphid", tag = "v0.1.0-nitrokey.1" } usbd-ccid = { git = "https://github.com/Nitrokey/usbd-ccid", tag = "v0.2.0-nitrokey.1" } ctaphid-dispatch = { git = "https://github.com/Nitrokey/ctaphid-dispatch", tag = "v0.1.1-nitrokey.2" } apdu-dispatch = { git = "https://github.com/Nitrokey/apdu-dispatch", tag = "v0.1.2-nitrokey.1" } From ae7e172066f54c73973ccadbf5208d7326c7083b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Wed, 21 Jun 2023 11:04:54 +0200 Subject: [PATCH 6/6] Use merged and tagged secrets app --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6337f77e..fe965b20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1006,7 +1006,7 @@ dependencies = [ [[package]] name = "encrypted_container" version = "0.1.0" -source = "git+https://github.com/Nitrokey/trussed-secrets-app?rev=75626206ca3410fdcef0bb77cd7fd7962054f077#75626206ca3410fdcef0bb77cd7fd7962054f077" +source = "git+https://github.com/Nitrokey/trussed-secrets-app?tag=v0.11.0-interrupt.1#4637a4b5a425636da0283962ce1979170a9ea1fd" dependencies = [ "cbor-smol", "delog", @@ -2505,7 +2505,7 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "secrets-app" version = "0.12.0" -source = "git+https://github.com/Nitrokey/trussed-secrets-app?rev=75626206ca3410fdcef0bb77cd7fd7962054f077#75626206ca3410fdcef0bb77cd7fd7962054f077" +source = "git+https://github.com/Nitrokey/trussed-secrets-app?tag=v0.11.0-interrupt.1#4637a4b5a425636da0283962ce1979170a9ea1fd" dependencies = [ "apdu-dispatch", "bitflags 2.3.1", diff --git a/Cargo.toml b/Cargo.toml index 20f9a1f8..2202b119 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ ctaphid-dispatch = { git = "https://github.com/Nitrokey/ctaphid-dispatch", tag = apdu-dispatch = { git = "https://github.com/Nitrokey/apdu-dispatch", tag = "v0.1.2-nitrokey.1" } # unreleased crates -secrets-app = { git = "https://github.com/Nitrokey/trussed-secrets-app", rev = "75626206ca3410fdcef0bb77cd7fd7962054f077" } +secrets-app = { git = "https://github.com/Nitrokey/trussed-secrets-app", tag = "v0.11.0-interrupt.1" } opcard = { git = "https://github.com/Nitrokey/opcard-rs", tag = "v1.1.0" } piv-authenticator = { git = "https://github.com/Nitrokey/piv-authenticator", tag = "v0.3.2" } trussed-auth = { git = "https://github.com/Nitrokey/trussed-auth", tag = "v0.2.2-nitrokey.1" }