From 3961e5228700a97c5cfe8acbd83c23801b789efe Mon Sep 17 00:00:00 2001 From: ADEM MUHAMMED ERDAM Date: Thu, 3 Dec 2026 18:40:18 +0300 Subject: [PATCH] topbar: use passPhrase keyType in Wi-Fi profile XML (#318) The Windows WLAN_profile v1 schema requires case-sensitive `passPhrase` for `` (matching `plugins/rust-settings/src/wifi.rs`). Using lowercase `passphrase` caused WlanSetProfile to reject password-protected Wi-Fi profiles created from the topbar flyout. Fixes #318 --- plugins/topbar/src/fly.rs | 42 +++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/plugins/topbar/src/fly.rs b/plugins/topbar/src/fly.rs index 1bdba3ec..88fbe9b8 100644 --- a/plugins/topbar/src/fly.rs +++ b/plugins/topbar/src/fly.rs @@ -609,21 +609,26 @@ fn esc(s: &str) -> String { s.replace('&', "&").replace('<', "<").replace('>', ">").replace('"', """) } -/// Saves a profile for a new network and connects. shortcut: only open and WPA/WPA2/WPA3 personal (password) networks; enterprise ones go to Windows settings. -unsafe fn wifi_join(n: &Net, pass: &str) { - let (auth, key) = match n.auth { - 1 => ("open", String::new()), - 4 => ("WPAPSK", pass.into()), - 7 => ("WPA2PSK", pass.into()), - _ => ("WPA3SAE", pass.into()), +/// Builds the WLAN profile XML for `wifi_join`. The Windows WLAN schema requires `passPhrase` (case-sensitive). +fn wifi_profile_xml(ssid: &str, auth: i32, pass: &str) -> String { + let auth = match auth { + 1 => "open", + 4 => "WPAPSK", + 7 => "WPA2PSK", + _ => "WPA3SAE", }; let sec = if auth == "open" { "opennonefalse".to_string() } else { - format!("{auth}AESfalsepassphrasefalse{}", esc(&key)) + format!("{auth}AESfalsepassPhrasefalse{}", esc(pass)) }; - let name = esc(&n.ssid); - let xml = format!("{name}{name}ESSauto{sec}"); + let name = esc(ssid); + format!("{name}{name}ESSauto{sec}") +} + +/// Saves a profile for a new network and connects. shortcut: only open and WPA/WPA2/WPA3 personal (password) networks; enterprise ones go to Windows settings. +unsafe fn wifi_join(n: &Net, pass: &str) { + let xml = wifi_profile_xml(&n.ssid, n.auth, pass); let x = wide(&xml); let mut reason = 0u32; let ok = with_iface(&n.g, |h, g| WlanSetProfile(h, g, 0, x.as_ptr(), null(), 1, null_mut(), &mut reason) == 0).unwrap_or(false); @@ -2263,7 +2268,7 @@ mod tile_glide_tests { #[cfg(test)] mod tests { - use super::{flip_layout, score, init, is_open, toggle, close_now, Kind, FLY, FH, GetModuleHandleW, SetProcessDPIAware, null, null_mut, DestroyWindow, IsWindow}; + use super::{flip_layout, score, wifi_profile_xml, init, is_open, toggle, close_now, Kind, FLY, FH, GetModuleHandleW, SetProcessDPIAware, null, null_mut, DestroyWindow, IsWindow}; #[test] fn layout_flip_both_ways() { @@ -2308,6 +2313,21 @@ mod tests { assert_eq!(score("calculator", ""), None); assert_eq!(score("v", "v"), Some(0)); // one-letter initials do not count, the prefix does } + + #[test] + fn wifi_profile_uses_passphrase_key_type() { + for (auth, expected) in [(4, "WPAPSK"), (7, "WPA2PSK"), (9, "WPA3SAE")] { + let xml = wifi_profile_xml("a{expected}"))); + assert!(xml.contains("passPhrase")); + assert!(!xml.contains("passphrase")); + assert!(xml.contains("a<b")); + assert!(xml.contains("p&ss"1234")); + } + let open = wifi_profile_xml("Cafe", 1, ""); + assert!(open.contains("opennone")); + assert!(!open.contains("sharedKey")); + } } #[cfg(test)]