mirror of
https://github.com/trussed-dev/piv-authenticator.git
synced 2026-06-20 04:16:15 -07:00
Use apdu-app instead of apdu-dispatch
This commit is contained in:
committed by
sosthene-nitrokey
parent
bc2cc188c2
commit
4deca70ec2
+3
-3
@@ -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" }
|
||||
|
||||
|
||||
+7
-13
@@ -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<const C: usize>(command: &'l iso7816::Command<C>) -> Result<Self, Status> {
|
||||
pub fn try_from(command: iso7816::command::CommandView<'l>) -> Result<Self, Status> {
|
||||
command.try_into()
|
||||
}
|
||||
}
|
||||
@@ -295,7 +295,7 @@ impl<'data> TryFrom<&'data [u8]> for PutData<'data> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'l, const C: usize> TryFrom<&'l iso7816::Command<C>> for Command<'l> {
|
||||
impl<'l> TryFrom<iso7816::command::CommandView<'l>> 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<C>> 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<C>) -> Result<Self, Self::Error> {
|
||||
fn try_from(command: iso7816::command::CommandView<'l>) -> Result<Self, Self::Error> {
|
||||
let (class, instruction, p1, p2) = (
|
||||
command.class(),
|
||||
command.instruction(),
|
||||
@@ -323,13 +323,9 @@ impl<'l, const C: usize> TryFrom<&'l iso7816::Command<C>> 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<C>> 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<C>> 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)?,
|
||||
|
||||
+5
-5
@@ -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<T> App<{ command::SIZE }, { response::SIZE }> for Authenticator<T>
|
||||
impl<T, const R: usize> App<R> for Authenticator<T>
|
||||
where
|
||||
T: crate::Client,
|
||||
{
|
||||
fn select(
|
||||
&mut self,
|
||||
interface: Interface,
|
||||
_apdu: &Command,
|
||||
reply: &mut response::Data,
|
||||
_apdu: CommandView<'_>,
|
||||
reply: &mut Data<R>,
|
||||
) -> 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<R>) -> Result {
|
||||
if interface != Interface::Contact {
|
||||
return Err(Status::ConditionsOfUseNotSatisfied);
|
||||
}
|
||||
|
||||
+2
-2
@@ -153,9 +153,9 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn respond<const R: usize, const C: usize>(
|
||||
pub fn respond<const R: usize>(
|
||||
&mut self,
|
||||
command: &iso7816::Command<C>,
|
||||
command: iso7816::command::CommandView<'_>,
|
||||
reply: &mut Data<R>,
|
||||
) -> Result {
|
||||
let just_verified = self.state.volatile.app_security_status.pin_just_verified;
|
||||
|
||||
Reference in New Issue
Block a user