diff --git a/Cargo.lock b/Cargo.lock index 300bd452..67ce77ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -319,9 +319,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.11.0" +version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" [[package]] name = "block-buffer" @@ -1042,15 +1042,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.32" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" [[package]] name = "futures-io" -version = "0.3.32" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" [[package]] name = "futures-lite" @@ -1645,7 +1645,7 @@ dependencies = [ "mac-notification-sys", "serde", "tauri-winrt-notification", - "zbus", + "zbus 5.19.0", ] [[package]] @@ -1854,6 +1854,7 @@ dependencies = [ "ctrlc", "dirs 7.0.0", "env_logger", + "futures-lite", "git2 0.21.0", "hex", "hkdf", @@ -1885,7 +1886,7 @@ dependencies = [ "tokio", "toml", "tss-esapi", - "zbus", + "zbus 6.0.0", "zeroize", ] @@ -2357,9 +2358,9 @@ dependencies = [ [[package]] name = "rustix" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d" dependencies = [ "bitflags", "errno", @@ -2612,9 +2613,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52d1cfed4120b4d927bf7c0f86d2087a4a7d6027c906d9f9d525a80573b9be51" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" dependencies = [ "libc", "windows-sys 0.61.2", @@ -2828,7 +2829,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.3.4", + "getrandom 0.4.2", "once_cell", "rustix", "windows-sys 0.61.2", @@ -3644,17 +3645,45 @@ dependencies = [ "rustix", "serde", "serde_repr", - "tokio", "tracing", "uds_windows", "uuid", "windows-sys 0.61.2", "winnow 1.0.0", - "zbus_macros", + "zbus_macros 5.19.0", "zbus_names", "zvariant", ] +[[package]] +name = "zbus" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266223222c9d81e5966455a9da0783e35d56a7ccab79a03c2366b2d98f8fc8a9" +dependencies = [ + "async-trait", + "bitflags", + "endi", + "futures-core", + "hex", + "libc", + "ordered-stream", + "rustix", + "serde", + "serde_repr", + "socket2", + "tokio", + "tracing", + "uds_windows", + "uuid", + "windows-sys 0.61.2", + "winnow 1.0.0", + "zbus_macros 6.0.0", + "zbus_utils", + "zcheapstr", + "zruntime", +] + [[package]] name = "zbus_macros" version = "5.19.0" @@ -3670,6 +3699,18 @@ dependencies = [ "zvariant_utils", ] +[[package]] +name = "zbus_macros" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69191782481ef4e0ac88ca487347c52e08bb85cceb2a163b79f7281fe5be0a3c" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", + "zbus_utils", +] + [[package]] name = "zbus_names" version = "4.3.4" @@ -3681,6 +3722,19 @@ dependencies = [ "zvariant", ] +[[package]] +name = "zbus_utils" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c27a055b114bd9fc3686e90f62bd1fe612d523fc5f620bac3b1d2f42d3f6cab8" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "syn 3.0.9", + "winnow 1.0.0", +] + [[package]] name = "zcheapstr" version = "1.0.0" @@ -3790,6 +3844,20 @@ version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" +[[package]] +name = "zruntime" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "467fd80a2014d186319f14b81aef027aa466712f355c90158a0e6b39de60726d" +dependencies = [ + "futures-core", + "futures-io", + "rustix", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + [[package]] name = "zvariant" version = "5.14.0" diff --git a/Cargo.toml b/Cargo.toml index df5dfb7a..bb0d1ed0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,8 @@ zeroize = { version = "1.8", features = ["zeroize_derive"] } hex = "0.4" shadow-rs = "2.0" psl = "2" -zbus = "5.14" +zbus = "6.0" +futures-lite = "2" # Proc macro dependencies syn = { version = "3.0", features = ["full", "extra-traits"] } diff --git a/cmd/passless/Cargo.toml b/cmd/passless/Cargo.toml index 33ba7ec6..62443419 100644 --- a/cmd/passless/Cargo.toml +++ b/cmd/passless/Cargo.toml @@ -53,6 +53,7 @@ libc.workspace = true nix.workspace = true notify-rust.workspace = true zbus.workspace = true +futures-lite.workspace = true aes-gcm.workspace = true rand.workspace = true ctrlc.workspace = true @@ -88,7 +89,7 @@ serde.workspace = true serde_json.workspace = true passless-config-doc.workspace = true zbus = { workspace = true, features = ["tokio"] } -tokio = { version = "1.0", features = ["rt", "macros", "time", "sync"] } +tokio = { version = "1.0", features = ["rt", "rt-multi-thread", "macros", "time", "sync"] } [build-dependencies] passless-core.workspace = true diff --git a/cmd/passless/src/agent/prompt.rs b/cmd/passless/src/agent/prompt.rs index 2d09e085..020a4d88 100644 --- a/cmd/passless/src/agent/prompt.rs +++ b/cmd/passless/src/agent/prompt.rs @@ -504,7 +504,7 @@ pub fn query_server_capabilities() -> ServerCapability { } fn resolve_notification_server_unique_name() -> Result { - let conn = zbus::blocking::Connection::session().map_err(|e| { + let conn = zbus::block_on(zbus::Connection::session()).map_err(|e| { warn!( "Prompt: failed to connect to session bus for sender validation: {}", e @@ -514,23 +514,22 @@ fn resolve_notification_server_unique_name() -> Result { } })?; - let reply = conn - .call_method( - Some("org.freedesktop.DBus"), - "/org/freedesktop/DBus", - Some("org.freedesktop.DBus"), - "GetNameOwner", - &NOTIFICATIONS_WELL_KNOWN_NAME, - ) - .map_err(|e| { - warn!( - "Prompt: failed to resolve notification server unique name: {}", - e - ); - PromptError { - kind: PromptErrorKind::NotificationUnsupported, - } - })?; + let reply = zbus::block_on(conn.call_method( + Some("org.freedesktop.DBus"), + "/org/freedesktop/DBus", + Some("org.freedesktop.DBus"), + "GetNameOwner", + &NOTIFICATIONS_WELL_KNOWN_NAME, + )) + .map_err(|e| { + warn!( + "Prompt: failed to resolve notification server unique name: {}", + e + ); + PromptError { + kind: PromptErrorKind::NotificationUnsupported, + } + })?; let unique_name: String = reply.body().deserialize().map_err(|e| { warn!("Prompt: failed to deserialize GetNameOwner reply: {}", e); @@ -553,7 +552,7 @@ fn wait_for_validated_action( notification_id: u32, timeout: Duration, ) -> ValidatedAction { - let conn = match zbus::blocking::Connection::session() { + let conn = match zbus::block_on(zbus::Connection::session()) { Ok(c) => c, Err(e) => { warn!( @@ -567,17 +566,23 @@ fn wait_for_validated_action( let rule = match zbus::MatchRule::builder() .msg_type(zbus::message::Type::Signal) .sender(server_unique_name) - .and_then(|b| b.interface(NOTIFICATIONS_IFACE)) + .interface(NOTIFICATIONS_IFACE) + .build() { - Ok(builder) => builder.build(), + Ok(rule) => rule, Err(e) => { warn!("Prompt: failed to build match rule: {}", e); return ValidatedAction::Closed; } }; - let mut iter = match zbus::blocking::MessageIterator::for_match_rule(rule, &conn, Some(16)) { - Ok(iter) => iter, + let max_queued = std::num::NonZeroUsize::new(16).unwrap(); + let stream = match zbus::block_on(zbus::MessageStream::for_match_rule( + rule, + &conn, + Some(max_queued), + )) { + Ok(s) => s, Err(e) => { warn!("Prompt: failed to subscribe to signals: {}", e); return ValidatedAction::Closed; @@ -589,49 +594,53 @@ fn wait_for_validated_action( let server_unique_name_owned = server_unique_name.to_string(); let thread = std::thread::spawn(move || { - for msg in &mut iter { - let msg = match msg { - Ok(m) => m, - Err(_) => continue, - }; - let header = msg.header(); - let sender = match header.sender() { - Some(s) => s.to_string(), - None => continue, - }; - if sender != server_unique_name_owned { - debug!( - "Prompt: rejecting signal from unexpected sender: {}", - sender - ); - continue; - } - let member = match header.member() { - Some(m) => m.to_string(), - None => continue, - }; - match member.as_str() { - "ActionInvoked" => { - let body: Result<(u32, String), _> = msg.body().deserialize(); - if let Ok((id, action_key)) = body - && id == notification_id - { - let _ = tx.send(ValidatedAction::Action(action_key)); - return; - } + zbus::block_on(async { + use futures_lite::StreamExt; + let mut stream = std::pin::pin!(stream); + while let Some(msg_result) = stream.next().await { + let msg = match msg_result { + Ok(m) => m, + Err(_) => continue, + }; + let header = msg.header(); + let sender = match header.sender() { + Some(s) => s.to_string(), + None => continue, + }; + if sender != server_unique_name_owned { + debug!( + "Prompt: rejecting signal from unexpected sender: {}", + sender + ); + continue; } - "NotificationClosed" => { - let body: Result<(u32, u32), _> = msg.body().deserialize(); - if let Ok((id, _reason)) = body - && id == notification_id - { - let _ = tx.send(ValidatedAction::Closed); - return; + let member = match header.member() { + Some(m) => m.to_string(), + None => continue, + }; + match member.as_str() { + "ActionInvoked" => { + let body: Result<(u32, String), _> = msg.body().deserialize(); + if let Ok((id, action_key)) = body + && id == notification_id + { + let _ = tx.send(ValidatedAction::Action(action_key)); + return; + } + } + "NotificationClosed" => { + let body: Result<(u32, u32), _> = msg.body().deserialize(); + if let Ok((id, _reason)) = body + && id == notification_id + { + let _ = tx.send(ValidatedAction::Closed); + return; + } } + _ => {} } - _ => {} } - } + }); }); let now = Instant::now(); @@ -1637,7 +1646,7 @@ mod dbus_tests { summary: &str, body: &str, actions: Vec, - _hints: HashMap>, + _hints: HashMap>, expire_timeout: i32, ) -> zbus::fdo::Result { let mut state = self.state.lock().unwrap(); @@ -1817,11 +1826,8 @@ mod dbus_tests { let timeout_result = tokio::time::timeout(Duration::from_secs(TEST_TIMEOUT_SECS), async { let (service, state, notify_ready) = TestNotificationService::new(server_kind); let conn = Builder::session() - .unwrap() .name("org.freedesktop.Notifications") - .unwrap() .serve_at("/org/freedesktop/Notifications", service) - .unwrap() .build() .await .unwrap();