From 4deca70ec2c7a34a14d49ff9ddb5079fc40656cd Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Thu, 17 Oct 2024 23:16:51 +0200 Subject: [PATCH] Use apdu-app instead of apdu-dispatch --- Cargo.toml | 6 +++--- src/commands.rs | 20 +++++++------------- src/dispatch.rs | 10 +++++----- src/lib.rs | 4 ++-- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index da0a6dc..f40eb37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,12 +17,12 @@ name = "usbip" required-features = ["apdu-dispatch", "virt"] [dependencies] -apdu-dispatch = { version = "0.1", optional = true } +apdu-app = { version = "0.1", optional = true } delog = { version = "0.1.5", optional = true } flexiber = { version = "0.1", features = ["derive", "heapless"] } heapless = "0.7" hex-literal = "0.3" -iso7816 = "0.1.2" +iso7816 = "0.1.3" serde = { version = "1", default-features = false, features = ["derive"] } trussed = { version = "0.1", features = ["serde-extensions"] } trussed-auth = { version = "0.3" } @@ -63,6 +63,7 @@ asn1 = "0.15.2" [features] default = [] +apdu-dispatch = ["dep:apdu-app"] strict-pin = [] std = [] vpicc = ["std", "dep:vpicc", "virt"] @@ -90,7 +91,6 @@ trussed-chunked = { git = "https://github.com/trussed-dev/trussed-staging.git", trussed-staging = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "v0.3.2" } trussed-hpke = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "hpke-v0.1.0" } trussed-wrap-key-to-file = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "wrap-key-to-file-v0.1.0" } -apdu-dispatch = { git = "https://github.com/Nitrokey/apdu-dispatch", tag = "v0.1.2-nitrokey.2" } trussed-usbip = { git = "https://github.com/Nitrokey/pc-usbip-runner.git", tag = "v0.0.1-nitrokey.1" } usbd-ccid = { git = "https://github.com/Nitrokey/usbd-ccid", tag = "v0.2.0-nitrokey.1" } diff --git a/src/commands.rs b/src/commands.rs index d47012a..3f08eba 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -74,7 +74,7 @@ impl<'l> Command<'l> { /// Core method, constructs a PIV command, if the iso7816::Command is valid. /// /// Inherent method re-exposing the `TryFrom` implementation. - pub fn try_from(command: &'l iso7816::Command) -> Result { + pub fn try_from(command: iso7816::command::CommandView<'l>) -> Result { command.try_into() } } @@ -295,7 +295,7 @@ impl<'data> TryFrom<&'data [u8]> for PutData<'data> { } } -impl<'l, const C: usize> TryFrom<&'l iso7816::Command> for Command<'l> { +impl<'l> TryFrom> for Command<'l> { type Error = Status; /// The first layer of unraveling the iso7816::Command onion. /// @@ -303,7 +303,7 @@ impl<'l, const C: usize> TryFrom<&'l iso7816::Command> for Command<'l> { /// in the "Command Syntax" boxes of NIST SP 800-73-4, and return early errors. /// /// The individual piv::Command TryFroms then further interpret these validated parameters. - fn try_from(command: &'l iso7816::Command) -> Result { + fn try_from(command: iso7816::command::CommandView<'l>) -> Result { let (class, instruction, p1, p2) = ( command.class(), command.instruction(), @@ -323,13 +323,9 @@ impl<'l, const C: usize> TryFrom<&'l iso7816::Command> for Command<'l> { // TODO: should we check `command.expected() == 0`, where specified? Ok(match (class.into_inner(), instruction, p1, p2) { - (0x00, Instruction::Select, 0x04, 0x00) => { - Self::Select(Select::try_from(data.as_slice())?) - } + (0x00, Instruction::Select, 0x04, 0x00) => Self::Select(Select::try_from(data)?), - (0x00, Instruction::GetData, 0x3F, 0xFF) => { - Self::GetData(GetData::try_from(data.as_slice())?.0) - } + (0x00, Instruction::GetData, 0x3F, 0xFF) => Self::GetData(GetData::try_from(data)?.0), (0x00, Instruction::Verify, p1, p2) => { let logout = VerifyLogout::try_from(p1)?; @@ -350,7 +346,7 @@ impl<'l, const C: usize> TryFrom<&'l iso7816::Command> for Command<'l> { } (0x00, Instruction::ResetRetryCounter, 0x00, 0x80) => { - Self::ResetRetryCounter(ResetRetryCounter::try_from(data.as_slice())?) + Self::ResetRetryCounter(ResetRetryCounter::try_from(data)?) } (0x00, Instruction::GeneralAuthenticate, p1, p2) => { @@ -365,9 +361,7 @@ impl<'l, const C: usize> TryFrom<&'l iso7816::Command> for Command<'l> { }) } - (0x00, Instruction::PutData, 0x3F, 0xFF) => { - Self::PutData(PutData::try_from(data.as_slice())?) - } + (0x00, Instruction::PutData, 0x3F, 0xFF) => Self::PutData(PutData::try_from(data)?), (0x00, Instruction::GenerateAsymmetricKeyPair, 0x00, p2) => Self::GenerateAsymmetric( GenerateKeyReference::try_from(p2).map_err(|_| Status::IncorrectP1OrP2Parameter)?, diff --git a/src/dispatch.rs b/src/dispatch.rs index ade26b9..b8bd0b0 100644 --- a/src/dispatch.rs +++ b/src/dispatch.rs @@ -1,18 +1,18 @@ use crate::{reply::Reply, Authenticator, /*constants::PIV_AID,*/ Result}; -use apdu_dispatch::{app::App, command, response, Command}; +use apdu_app::{App, CommandView, Data}; use iso7816::{Interface, Status}; #[cfg(feature = "apdu-dispatch")] -impl App<{ command::SIZE }, { response::SIZE }> for Authenticator +impl App for Authenticator where T: crate::Client, { fn select( &mut self, interface: Interface, - _apdu: &Command, - reply: &mut response::Data, + _apdu: CommandView<'_>, + reply: &mut Data, ) -> Result { if interface != Interface::Contact { return Err(Status::ConditionsOfUseNotSatisfied); @@ -24,7 +24,7 @@ where self.deselect() } - fn call(&mut self, interface: Interface, apdu: &Command, reply: &mut response::Data) -> Result { + fn call(&mut self, interface: Interface, apdu: CommandView<'_>, reply: &mut Data) -> Result { if interface != Interface::Contact { return Err(Status::ConditionsOfUseNotSatisfied); } diff --git a/src/lib.rs b/src/lib.rs index aa58871..81d27be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -153,9 +153,9 @@ where Ok(()) } - pub fn respond( + pub fn respond( &mut self, - command: &iso7816::Command, + command: iso7816::command::CommandView<'_>, reply: &mut Data, ) -> Result { let just_verified = self.state.volatile.app_security_status.pin_just_verified;