Skip to content

Commit a894929

Browse files
committed
Add support for D-Bus virtual devices
1 parent 2c0cf07 commit a894929

File tree

7 files changed

+499
-0
lines changed

7 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ impl AuthenticatorService {
7171
/// Add any detected platform transports
7272
pub fn add_detected_transports(&mut self) {
7373
self.add_u2f_usb_hid_platform_transports();
74+
#[cfg(feature = "dbus")]
75+
self.add_dbus();
7476
}
7577

7678
fn add_transport(&mut self, boxed_token: Box<dyn AuthenticatorTransport + Send>) {
@@ -95,6 +97,14 @@ impl AuthenticatorService {
9597
}
9698
}
9799

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

0 commit comments

Comments
 (0)