diff --git a/CHANGELOG.md b/CHANGELOG.md index b6a0a58..12910ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 1.6.1 +- Fix accept/deny prompt on Windows + ## 1.6.0 - Prompt to accept/deny a host which is not explicitly allowed diff --git a/Cargo.lock b/Cargo.lock index 7576cbf..095eee5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -134,7 +134,7 @@ checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "bitbox-bridge" -version = "1.6.0" +version = "1.6.1" dependencies = [ "clap", "env_logger", @@ -152,6 +152,7 @@ dependencies = [ "warp", "webbrowser", "windows-service", + "windows-sys 0.59.0", ] [[package]] @@ -244,7 +245,7 @@ dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -1929,7 +1930,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -1967,7 +1968,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -2002,18 +2012,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -2030,9 +2040,9 @@ checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -2048,9 +2058,9 @@ checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -2066,15 +2076,15 @@ checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -2090,9 +2100,9 @@ checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -2108,9 +2118,9 @@ checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -2126,9 +2136,9 @@ checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -2144,6 +2154,6 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/bitbox-bridge/Cargo.toml b/bitbox-bridge/Cargo.toml index c94d390..42a827c 100644 --- a/bitbox-bridge/Cargo.toml +++ b/bitbox-bridge/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bitbox-bridge" # If you bump this, also change the ProductCode in bitbox-bridge/release/windows/wix/Product.wxs. -version = "1.6.0" +version = "1.6.1" authors = ["Niklas Claesson "] edition = "2021" license = "Apache-2.0" @@ -22,6 +22,9 @@ warp = "0.3.7" tera = "1.20" uuid = { version = "1.10.0", features = ["v4"] } +[target.'cfg(windows)'.dependencies] +windows-sys = { version = "0.59.0", features = ["Win32", "Win32_System", "Win32_UI", "Win32_System_RemoteDesktop", "Win32_UI_WindowsAndMessaging"] } + [dependencies.u2fframing] version = "0.1" path = "../u2fframing" diff --git a/bitbox-bridge/release/Makefile b/bitbox-bridge/release/Makefile index 79966ad..8cddd12 100644 --- a/bitbox-bridge/release/Makefile +++ b/bitbox-bridge/release/Makefile @@ -17,7 +17,7 @@ release-linux: docker run --user ${USER} --interactive --tty -v ${MOUNT} -w /bitbox-bridge ${CONTAINER} bitbox-bridge/release/linux/release.sh release-windows: - docker run --user ${USER} --interactive --tty -v ${MOUNT} -w /bitbox-bridge ${CONTAINER} bitbox-bridge/release/windows/release.sh + docker run --interactive --tty -v ${MOUNT} -w /bitbox-bridge ${CONTAINER} bitbox-bridge/release/windows/release.sh release-darwin: docker run --user ${USER} --interactive --tty -v ${MOUNT} -w /bitbox-bridge ${CONTAINER} bitbox-bridge/release/darwin/release.sh diff --git a/bitbox-bridge/release/windows/wix/Product.wxs b/bitbox-bridge/release/windows/wix/Product.wxs index 28594c5..4420c43 100644 --- a/bitbox-bridge/release/windows/wix/Product.wxs +++ b/bitbox-bridge/release/windows/wix/Product.wxs @@ -2,7 +2,7 @@ - + diff --git a/bitbox-bridge/src/web.rs b/bitbox-bridge/src/web.rs index 930f34d..62e9f8e 100644 --- a/bitbox-bridge/src/web.rs +++ b/bitbox-bridge/src/web.rs @@ -184,6 +184,67 @@ impl AllowedHosts { } } +// On windows, we use a native system dialog to prompt the user. +// The browser based prompt does not work as we can't launch a browser from the service (not allowed). +// +// We use WTSSendMessageA as officially recommended: +// +// See https://learn.microsoft.com/en-us/windows/win32/services/interactive-services +// > You can use the following techniques to interact with the user from a service on all supported versions of Windows: +// > Display a dialog box in the user's session using the [WTSSendMessage](https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtssendmessagea) function. +#[cfg(target_os = "windows")] +async fn user_confirm( + _confirm_state: Arc, + message: String, + _base_url: &str, +) -> Result { + use windows_sys::Win32::System::RemoteDesktop::{ + WTSGetActiveConsoleSessionId, WTSSendMessageA, WTS_CURRENT_SERVER_HANDLE, + }; + + use windows_sys::Win32::UI::WindowsAndMessaging::{IDYES, MB_YESNO, MESSAGEBOX_RESULT}; + let title_c = c"BitBoxBridge"; + let message_c = std::ffi::CString::new(message.as_str()).map_err(|_| ())?; + + let mut response: MESSAGEBOX_RESULT = 0; + let timeout: u32 = 60; // 60 seconds + + unsafe { + // Need the active user session ID so the dialog is shown to the user. + let current_session = WTSGetActiveConsoleSessionId(); + if current_session == 0xFFFFFFFF { + // See https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-wtsgetactiveconsolesessionid#return-value + return Err(()); + } + let result = WTSSendMessageA( + WTS_CURRENT_SERVER_HANDLE, + current_session, + title_c.as_ptr() as *const u8, + title_c.count_bytes() as u32, + message_c.as_ptr() as *const u8, + message_c.as_c_str().count_bytes() as u32, + MB_YESNO, + timeout, + &mut response, + 1, + ); + + if result == 0 { + return Err(()); + } + } + + // Check if the user clicked 'Yes' + Ok(response == IDYES) +} + +// On Linux/maCOS, we launch a browser with a prompt. +// +// On macOS, native dialogs don't work if there is no main window (we don't have one, it's a service). +// +// On linux, native dialogs would work, but we use the browser based solution here too as native +// dialogs might not work in all distros/configs. +#[cfg(not(target_os = "windows"))] async fn user_confirm( confirm_state: Arc, message: String,