mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 06:26:14 -05:00
fix(windows): restore browser auth focus and configure tunnel branding
This commit is contained in:
8 files changed
+72
-5
No files matched your search
@@ -102,6 +102,7 @@ tempfile.workspace = true
|
||||
uzers = { workspace = true, optional = true }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_System_Pipes", "Win32_UI_WindowsAndMessaging"] }
|
||||
# Child webviews let the Windows host own layout beside native controls.
|
||||
tauri = { workspace = true, optional = true, features = ["unstable"] }
|
||||
webview2-com = { version = "0.39", optional = true }
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
//! Per-user Windows named pipe for browser authentication callbacks.
|
||||
use anyhow::{Context, bail};
|
||||
use gpapi::{auth::SamlAuthData, error::AuthDataParseError};
|
||||
use std::{io, os::windows::io::AsRawHandle};
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
net::windows::named_pipe::{ClientOptions, NamedPipeServer},
|
||||
net::windows::named_pipe::{ClientOptions, NamedPipeClient, NamedPipeServer},
|
||||
time::timeout,
|
||||
};
|
||||
#[path = "protocol.rs"]
|
||||
mod protocol;
|
||||
pub use protocol::validate_auth_callback;
|
||||
use protocol::*;
|
||||
use windows_sys::Win32::{
|
||||
System::Pipes::GetNamedPipeServerProcessId, UI::WindowsAndMessaging::AllowSetForegroundWindow,
|
||||
};
|
||||
|
||||
pub struct AuthCallbackReceiver {
|
||||
listener: NamedPipeServer,
|
||||
@@ -52,6 +56,9 @@ impl AuthCallbackReceiver {
|
||||
let _ = timeout(IO_TIMEOUT, stream.read_u8()).await;
|
||||
self.listener.disconnect()?;
|
||||
if let Some(result) = result {
|
||||
if let Err(error) = delegate_foreground_to_parent() {
|
||||
log::debug!("Could not delegate authentication foreground permission to the parent: {error}");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -76,6 +83,12 @@ pub async fn forward_auth_callback(callback: &str) -> anyhow::Result<()> {
|
||||
stream.write_all(callback.as_bytes()).await?;
|
||||
let version = stream.read_u8().await?;
|
||||
let status = stream.read_u8().await?;
|
||||
// The receiver waits for our acknowledgement before returning to its caller.
|
||||
if version == PROTOCOL_VERSION && status == STATUS_ACCEPTED {
|
||||
if let Err(error) = delegate_foreground_to_receiver(&stream) {
|
||||
log::debug!("Could not delegate browser foreground permission to the authenticator: {error}");
|
||||
}
|
||||
}
|
||||
stream.write_u8(status).await?;
|
||||
anyhow::ensure!(
|
||||
version == PROTOCOL_VERSION,
|
||||
@@ -91,6 +104,32 @@ pub async fn forward_auth_callback(callback: &str) -> anyhow::Result<()> {
|
||||
.context("Timed out forwarding the authentication callback")?
|
||||
}
|
||||
|
||||
fn delegate_foreground_to_receiver(stream: &NamedPipeClient) -> io::Result<()> {
|
||||
let mut process_id = 0;
|
||||
unsafe {
|
||||
if GetNamedPipeServerProcessId(stream.as_raw_handle(), &mut process_id) == 0 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
}
|
||||
allow_foreground(process_id)
|
||||
}
|
||||
|
||||
fn delegate_foreground_to_parent() -> anyhow::Result<()> {
|
||||
let Some(process_id) = std::env::var_os(gpapi::process::auth_launcher::AUTH_PARENT_PROCESS_ID_ENV) else {
|
||||
return Ok(());
|
||||
};
|
||||
let process_id = process_id.to_string_lossy().parse::<u32>()?;
|
||||
allow_foreground(process_id)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn allow_foreground(process_id: u32) -> io::Result<()> {
|
||||
if unsafe { AllowSetForegroundWindow(process_id) } == 0 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn ensure_auth_callback_handler() -> anyhow::Result<()> {
|
||||
use winreg::{RegKey, enums::HKEY_CURRENT_USER};
|
||||
let executable = common::binary_paths::gpauth();
|
||||
|
||||
Reference in new issue
Block a user