forked from trussed-dev/piv-authenticator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ac7f29
commit 8d79178
Showing
2 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (C) 2022 Nitrokey GmbH | ||
// SPDX-License-Identifier: CC0-1.0 | ||
|
||
use trussed::virt::{self, Ram, UserInterface}; | ||
use trussed::{ClientImplementation, Platform}; | ||
|
||
use piv_authenticator as piv; | ||
use trussed_usbip::Syscall; | ||
|
||
const MANUFACTURER: &str = "Nitrokey"; | ||
const PRODUCT: &str = "Nitrokey 3"; | ||
const VID: u16 = 0x20a0; | ||
const PID: u16 = 0x42b2; | ||
|
||
struct PivApp { | ||
piv: piv::Authenticator<ClientImplementation<Syscall<virt::Platform<Ram>>>>, | ||
} | ||
|
||
impl trussed_usbip::Apps<ClientImplementation<Syscall<virt::Platform<Ram>>>, ()> for PivApp { | ||
fn new( | ||
make_client: impl Fn(&str) -> ClientImplementation<Syscall<virt::Platform<Ram>>>, | ||
_data: (), | ||
) -> Self { | ||
PivApp { | ||
piv: piv::Authenticator::new(make_client("piv")), | ||
} | ||
} | ||
|
||
fn with_ccid_apps<T>( | ||
&mut self, | ||
f: impl FnOnce(&mut [&mut dyn apdu_dispatch::App<7609, 7609>]) -> T, | ||
) -> T { | ||
f(&mut [&mut self.piv]) | ||
} | ||
} | ||
|
||
fn main() { | ||
env_logger::init(); | ||
|
||
let options = trussed_usbip::Options { | ||
manufacturer: Some(MANUFACTURER.to_owned()), | ||
product: Some(PRODUCT.to_owned()), | ||
serial_number: Some("TEST".into()), | ||
vid: VID, | ||
pid: PID, | ||
}; | ||
trussed_usbip::Runner::new(virt::Ram::default(), options) | ||
.init_platform(move |platform| { | ||
let ui: Box<dyn trussed::platform::UserInterface + Send + Sync> = | ||
Box::new(UserInterface::new()); | ||
platform.user_interface().set_inner(ui); | ||
}) | ||
.exec::<PivApp, _, _>(|_platform| {}); | ||
} |