mirror of
https://github.com/trussed-dev/piv-authenticator.git
synced 2026-06-20 04:16:15 -07:00
Add options to the authenticator
This commit is contained in:
+1
-1
@@ -22,7 +22,7 @@ impl trussed_usbip::Apps<ClientImplementation<Syscall<virt::Platform<Ram>>>, ()>
|
||||
_data: (),
|
||||
) -> Self {
|
||||
PivApp {
|
||||
piv: piv::Authenticator::new(make_client("piv")),
|
||||
piv: piv::Authenticator::new(make_client("piv"), piv::Options::default()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -11,11 +11,13 @@
|
||||
|
||||
// TODO: add CLI
|
||||
|
||||
use piv_authenticator::{Authenticator, Options};
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
trussed_rsa_alloc::virt::with_ram_client("piv-authenticator", |client| {
|
||||
let card = piv_authenticator::Authenticator::new(client);
|
||||
let card = Authenticator::new(client, Options::default());
|
||||
let mut virtual_card = piv_authenticator::vpicc::VirtualCard::new(card);
|
||||
let vpicc = vpicc::connect().expect("failed to connect to vpicc");
|
||||
vpicc
|
||||
|
||||
+24
-1
@@ -45,17 +45,38 @@ pub type Result<O = ()> = iso7816::Result<O>;
|
||||
use reply::Reply;
|
||||
use state::{AdministrationAlgorithm, CommandCache, KeyWithAlg, LoadedState, State, TouchPolicy};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Options {
|
||||
storage: Location,
|
||||
}
|
||||
|
||||
impl Default for Options {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
storage: Location::External,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Options {
|
||||
pub fn storage(self, storage: Location) -> Self {
|
||||
Self { storage, ..self }
|
||||
}
|
||||
}
|
||||
|
||||
/// PIV authenticator Trussed app.
|
||||
///
|
||||
/// The `C` parameter is necessary, as PIV includes command sequences,
|
||||
/// where we need to store the previous command, so we need to know how
|
||||
/// much space to allocate.
|
||||
pub struct Authenticator<T> {
|
||||
options: Options,
|
||||
state: State,
|
||||
trussed: T,
|
||||
}
|
||||
|
||||
struct LoadedAuthenticator<'a, T> {
|
||||
options: &'a mut Options,
|
||||
state: LoadedState<'a>,
|
||||
trussed: &'a mut T,
|
||||
}
|
||||
@@ -70,13 +91,14 @@ impl<T> Authenticator<T>
|
||||
where
|
||||
T: client::Client + client::Ed255 + client::Tdes,
|
||||
{
|
||||
pub fn new(trussed: T) -> Self {
|
||||
pub fn new(trussed: T, options: Options) -> Self {
|
||||
// seems like RefCell is not the right thing, we want something like `Rc` instead,
|
||||
// which can be cloned and injected into other parts of the App that use Trussed.
|
||||
// let trussed = RefCell::new(trussed);
|
||||
Self {
|
||||
// state: state::State::new(trussed.clone()),
|
||||
state: Default::default(),
|
||||
options,
|
||||
trussed,
|
||||
}
|
||||
}
|
||||
@@ -85,6 +107,7 @@ where
|
||||
Ok(LoadedAuthenticator {
|
||||
state: self.state.load(&mut self.trussed)?,
|
||||
trussed: &mut self.trussed,
|
||||
options: &mut self.options,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2022 Nitrokey GmbH
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
use piv_authenticator::{vpicc::VirtualCard, Authenticator};
|
||||
use piv_authenticator::{vpicc::VirtualCard, Authenticator, Options};
|
||||
|
||||
use std::{sync::mpsc, thread::sleep, time::Duration};
|
||||
use stoppable_thread::spawn;
|
||||
@@ -18,7 +18,7 @@ pub fn with_vsc<F: FnOnce() -> R, R>(f: F) -> R {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let handle = spawn(move |stopped| {
|
||||
trussed_rsa_alloc::virt::with_ram_client("opcard", |client| {
|
||||
let card = Authenticator::new(client);
|
||||
let card = Authenticator::new(client, Options::default());
|
||||
let mut virtual_card = VirtualCard::new(card);
|
||||
let mut result = Ok(());
|
||||
while !stopped.get() && result.is_ok() {
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@ macro_rules! cmd {
|
||||
};
|
||||
}
|
||||
|
||||
use piv_authenticator::{Authenticator, Options};
|
||||
use trussed::virt::Ram;
|
||||
use trussed_rsa_alloc::virt::Client;
|
||||
|
||||
@@ -18,7 +19,7 @@ pub type Piv = piv_authenticator::Authenticator<Client<Ram>>;
|
||||
|
||||
pub fn piv<R>(test: impl FnOnce(&mut Piv) -> R) -> R {
|
||||
trussed_rsa_alloc::virt::with_ram_client("test", |client| {
|
||||
let mut piv_app = piv_authenticator::Authenticator::new(client);
|
||||
let mut piv_app = Authenticator::new(client, Options::default());
|
||||
test(&mut piv_app)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user