Skip to content

Commit

Permalink
Add usbip example runner
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Jan 6, 2023
1 parent 4ac7f29 commit 8d79178
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ aes = "0.8.2"
stoppable_thread = "0.2.1"
expectrl = "0.6.0"

# Examples
trussed-usbip = { git = "https://github.com/trussed-dev/pc-usbip-runner", default-features = false, features = ["ccid"]}
apdu-dispatch = "0.1"
usbd-ccid = { git = "https://github.com/Nitrokey/nitrokey-3-firmware", features = ["highspeed-usb"]}
rand = "0.8.5"

[features]
default = []
strict-pin = []
std = []
virtual = ["std", "vpicc","trussed/virt"]
virtual = ["std", "vpicc", "trussed/virt"]
pivy-tests = []
opensc-tests = []

Expand All @@ -62,7 +67,8 @@ log-warn = []
log-error = []

[patch.crates-io]
trussed = { git = "https://github.com/Nitrokey/trussed", tag = "v0.1.0-nitrokey-3"}
trussed = { git = "https://github.com/Nitrokey/trussed", tag = "v0.1.0-nitrokey-4"}
littlefs2 = { git = "https://github.com/Nitrokey/littlefs2", tag = "v0.3.2-nitrokey-1" }

[profile.dev.package.rsa]
opt-level = 2
Expand Down
54 changes: 54 additions & 0 deletions examples/usbip.rs
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| {});
}

0 comments on commit 8d79178

Please sign in to comment.