forked from trussed-dev/fido-authenticator
-
Notifications
You must be signed in to change notification settings - Fork 0
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
9213a57
commit b0c72d3
Showing
2 changed files
with
77 additions
and
0 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,68 @@ | ||
// Copyright (C) 2022 Nitrokey GmbH | ||
// SPDX-License-Identifier: CC0-1.0 | ||
|
||
//! USB/IP runner for opcard. | ||
//! Run with cargo run --example usbip --features trussed/virt,dispatch | ||
|
||
use trussed::backend::{BackendId, CoreOnly}; | ||
use trussed::types::Location; | ||
use trussed::virt::{self, Client, Ram, UserInterface}; | ||
use trussed::{ClientImplementation, Platform}; | ||
use trussed_usbip::ClientBuilder; | ||
|
||
const MANUFACTURER: &str = "Nitrokey"; | ||
const PRODUCT: &str = "Nitrokey 3"; | ||
const VID: u16 = 0x20a0; | ||
const PID: u16 = 0x42b2; | ||
|
||
type VirtClient = ClientImplementation<trussed_usbip::Service<Ram, CoreOnly>, CoreOnly>; | ||
|
||
struct FidoApp { | ||
fido: fido_authenticator::Authenticator<fido_authenticator::Conforming, VirtClient>, | ||
} | ||
|
||
impl trussed_usbip::Apps<'static, VirtClient, CoreOnly> for FidoApp { | ||
type Data = (); | ||
fn new<B: ClientBuilder<VirtClient, CoreOnly>>(builder: &B, _data: ()) -> Self { | ||
let large_blogs = Some(fido_authenticator::LargeBlobsConfig { | ||
location: Location::External, | ||
#[cfg(feature = "chunked")] | ||
max_size: 4096, | ||
}); | ||
|
||
FidoApp { | ||
fido: fido_authenticator::Authenticator::new( | ||
builder.build("fido", &[BackendId::Core]), | ||
fido_authenticator::Conforming {}, | ||
fido_authenticator::Config { | ||
max_msg_size: usbd_ctaphid::constants::MESSAGE_SIZE, | ||
skip_up_timeout: None, | ||
max_resident_credential_count: Some(10), | ||
large_blobs: large_blogs, | ||
}, | ||
), | ||
} | ||
} | ||
|
||
fn with_ctaphid_apps<T>( | ||
&mut self, | ||
f: impl FnOnce(&mut [&mut dyn ctaphid_dispatch::app::App<'static>]) -> T, | ||
) -> T { | ||
f(&mut [&mut self.fido]) | ||
} | ||
} | ||
|
||
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::Builder::new(virt::Ram::default(), options) | ||
.build::<FidoApp>() | ||
.exec(|_platform| {}); | ||
} |