Skip to content

Commit 49013dc

Browse files
committed
Add support for D-Bus virtual devices
1 parent b1c128b commit 49013dc

File tree

8 files changed

+499
-0
lines changed

8 files changed

+499
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ maintenance = { status = "actively-developed" }
1616
[features]
1717
binding-recompile = ["bindgen"]
1818
webdriver = ["base64", "bytes", "warp", "tokio", "serde", "serde_json"]
19+
dbus = ["zbus", "zvariant"]
1920

2021
[target.'cfg(target_os = "linux")'.dependencies]
2122
libudev = "^0.2"
@@ -52,6 +53,8 @@ serde = { version = "1.0", optional = true, features = ["derive"] }
5253
serde_json = { version = "1.0", optional = true }
5354
bytes = { version = "0.5", optional = true, features = ["serde"] }
5455
base64 = { version = "^0.10", optional = true }
56+
zbus = { version = "1.8", optional = true }
57+
zvariant = { version = "2.4", optional = true }
5558

5659
[dev-dependencies]
5760
base64 = "^0.10"

examples/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ fn main() {
4242
opts.optflag("x", "no-u2f-usb-hid", "do not enable u2f-usb-hid platforms");
4343
#[cfg(feature = "webdriver")]
4444
opts.optflag("w", "webdriver", "enable WebDriver virtual bus");
45+
#[cfg(feature = "dbus")]
46+
opts.optflag("d", "dbus", "enable access to remote token through D-Bus");
4547

4648
opts.optflag("h", "help", "print this help menu").optopt(
4749
"t",
@@ -74,6 +76,13 @@ fn main() {
7476
}
7577
}
7678

79+
#[cfg(feature = "dbus")]
80+
{
81+
if matches.opt_present("dbus") {
82+
manager.add_dbus();
83+
}
84+
}
85+
7786
let timeout_ms = match matches.opt_get_default::<u64>("timeout", 15) {
7887
Ok(timeout_s) => {
7988
println!("Using {}s as the timeout", &timeout_s);

src/authenticatorservice.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ impl AuthenticatorService {
9595
}
9696
}
9797

98+
#[cfg(feature = "dbus")]
99+
pub fn add_dbus(&mut self) {
100+
match crate::virtualdevices::dbus::VirtualManager::new() {
101+
Ok(token) => self.add_transport(Box::new(token)),
102+
Err(e) => error!("Could not add D-Bus transport: {}", e),
103+
}
104+
}
105+
98106
pub fn register(
99107
&mut self,
100108
flags: crate::RegisterFlags,

src/capi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ unsafe fn from_raw(ptr: *const u8, len: usize) -> Vec<u8> {
4848
pub extern "C" fn rust_u2f_mgr_new() -> *mut AuthenticatorService {
4949
if let Ok(mut mgr) = AuthenticatorService::new() {
5050
mgr.add_detected_transports();
51+
#[cfg(feature = "dbus")]
52+
mgr.add_dbus();
5153
Box::into_raw(Box::new(mgr))
5254
} else {
5355
ptr::null_mut()

0 commit comments

Comments
 (0)