mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
Main changes: - Refactor connect/auth flows around a single OS profile and host identity model, including gateway fallback and cookie-on-stdin handling. - Align request parameters, HIP host-id propagation, SAML webview user-agent behavior, and portal default-browser handling with observed official client behavior. - Add opt-in cookie cache support and Microsoft Defender HIP reporting while keeping host-id validation explicit. - Add BSD build, packaging, release artifact, and provenance support with FreeBSD/OpenBSD path and dependency cleanup. - Update NixOS install documentation and dependency compatibility fixes.
83 lines
2.3 KiB
Rust
83 lines
2.3 KiB
Rust
use anyhow::bail;
|
|
use block2::RcBlock;
|
|
use log::warn;
|
|
use objc2::runtime::AnyObject;
|
|
use objc2_foundation::{NSError, NSObject, NSObjectNSKeyValueCoding, NSString, NSURL, NSURLRequest};
|
|
use objc2_web_kit::WKWebView;
|
|
use tauri::webview::PlatformWebview;
|
|
|
|
use super::webview_auth::PlatformWebviewExt;
|
|
|
|
impl PlatformWebviewExt for PlatformWebview {
|
|
fn ignore_tls_errors(&self) -> anyhow::Result<()> {
|
|
warn!("Ignoring TLS errors is not supported on macOS");
|
|
Ok(())
|
|
}
|
|
|
|
fn user_agent(&self) -> anyhow::Result<String> {
|
|
unsafe {
|
|
let wv: &NSObject = &*self.inner().cast();
|
|
let Some(value) = wv.valueForKey(&NSString::from_str("userAgent")) else {
|
|
bail!("Failed to get webview user agent");
|
|
};
|
|
let Some(user_agent) = value.downcast_ref::<NSString>() else {
|
|
bail!("Webview user agent is not a string");
|
|
};
|
|
|
|
Ok(user_agent.to_string())
|
|
}
|
|
}
|
|
|
|
fn set_user_agent(&self, user_agent: &str) -> anyhow::Result<()> {
|
|
unsafe {
|
|
let wv: &WKWebView = &*self.inner().cast();
|
|
wv.setCustomUserAgent(Some(&NSString::from_str(user_agent)));
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn load_url(&self, url: &str) -> anyhow::Result<()> {
|
|
unsafe {
|
|
let wv: &WKWebView = &*self.inner().cast();
|
|
let url = NSURL::URLWithString(&NSString::from_str(url)).ok_or_else(|| anyhow::anyhow!("Invalid URL"))?;
|
|
let request = NSURLRequest::requestWithURL(&url);
|
|
|
|
wv.loadRequest(&request);
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn load_html(&self, html: &str) -> anyhow::Result<()> {
|
|
unsafe {
|
|
let wv: &WKWebView = &*self.inner().cast();
|
|
wv.loadHTMLString_baseURL(&NSString::from_str(html), None);
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn get_html(&self, callback: Box<dyn Fn(anyhow::Result<String>) + 'static>) {
|
|
unsafe {
|
|
let wv: &WKWebView = &*self.inner().cast();
|
|
|
|
let js_callback = RcBlock::new(move |body: *mut AnyObject, err: *mut NSError| {
|
|
if let Some(err) = err.as_ref() {
|
|
let code = err.code();
|
|
let message = err.localizedDescription();
|
|
callback(Err(anyhow::anyhow!("Error {}: {}", code, message)));
|
|
} else {
|
|
let body: &NSString = &*body.cast();
|
|
callback(Ok(body.to_string()));
|
|
}
|
|
});
|
|
|
|
wv.evaluateJavaScript_completionHandler(
|
|
&NSString::from_str("document.documentElement.outerHTML"),
|
|
Some(&js_callback),
|
|
);
|
|
}
|
|
}
|
|
}
|