Skip to content

Commit

Permalink
Add support for D-Bus virtual devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ueno committed Jan 12, 2021
1 parent b1c128b commit 49013dc
Show file tree
Hide file tree
Showing 8 changed files with 499 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ maintenance = { status = "actively-developed" }
[features]
binding-recompile = ["bindgen"]
webdriver = ["base64", "bytes", "warp", "tokio", "serde", "serde_json"]
dbus = ["zbus", "zvariant"]

[target.'cfg(target_os = "linux")'.dependencies]
libudev = "^0.2"
Expand Down Expand Up @@ -52,6 +53,8 @@ serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0", optional = true }
bytes = { version = "0.5", optional = true, features = ["serde"] }
base64 = { version = "^0.10", optional = true }
zbus = { version = "1.8", optional = true }
zvariant = { version = "2.4", optional = true }

[dev-dependencies]
base64 = "^0.10"
Expand Down
9 changes: 9 additions & 0 deletions examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ fn main() {
opts.optflag("x", "no-u2f-usb-hid", "do not enable u2f-usb-hid platforms");
#[cfg(feature = "webdriver")]
opts.optflag("w", "webdriver", "enable WebDriver virtual bus");
#[cfg(feature = "dbus")]
opts.optflag("d", "dbus", "enable access to remote token through D-Bus");

opts.optflag("h", "help", "print this help menu").optopt(
"t",
Expand Down Expand Up @@ -74,6 +76,13 @@ fn main() {
}
}

#[cfg(feature = "dbus")]
{
if matches.opt_present("dbus") {
manager.add_dbus();
}
}

let timeout_ms = match matches.opt_get_default::<u64>("timeout", 15) {
Ok(timeout_s) => {
println!("Using {}s as the timeout", &timeout_s);
Expand Down
8 changes: 8 additions & 0 deletions src/authenticatorservice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ impl AuthenticatorService {
}
}

#[cfg(feature = "dbus")]
pub fn add_dbus(&mut self) {
match crate::virtualdevices::dbus::VirtualManager::new() {
Ok(token) => self.add_transport(Box::new(token)),
Err(e) => error!("Could not add D-Bus transport: {}", e),
}
}

pub fn register(
&mut self,
flags: crate::RegisterFlags,
Expand Down
2 changes: 2 additions & 0 deletions src/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ unsafe fn from_raw(ptr: *const u8, len: usize) -> Vec<u8> {
pub extern "C" fn rust_u2f_mgr_new() -> *mut AuthenticatorService {
if let Ok(mut mgr) = AuthenticatorService::new() {
mgr.add_detected_transports();
#[cfg(feature = "dbus")]
mgr.add_dbus();
Box::into_raw(Box::new(mgr))
} else {
ptr::null_mut()
Expand Down
Loading

0 comments on commit 49013dc

Please sign in to comment.