mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
feat: release GP Connect 3.3.0 with Native Shell support
This commit is contained in:
226 files changed
+7700
-5225
No files matched your search
@@ -1,7 +1,7 @@
|
||||
use std::net::ToSocketAddrs;
|
||||
|
||||
use super::{RequestParams, credential as credential_params};
|
||||
use crate::{credential::Credential, gateway::GatewayLoginContext, gp_params::GpParams};
|
||||
use crate::{credential::Credential, gateway::GatewayLoginContext, gp_params::GpParams, os_profile::ClientOs};
|
||||
|
||||
/// Inputs required to build gateway login request parameters.
|
||||
pub(crate) struct GatewayLoginInput<'a> {
|
||||
@@ -17,7 +17,7 @@ pub(crate) struct GatewayLoginInput<'a> {
|
||||
///
|
||||
/// Resolves the `server` parameter to an IPv4 address when
|
||||
/// `profile.gateway_server_uses_resolved_ipv4()` is true.
|
||||
/// Sets `gw` and `gateway-name` to the gateway FQDN.
|
||||
/// iOS uses the portal gateway name for `gw` and `gateway-name`; desktop profiles use its FQDN.
|
||||
pub(crate) fn build(input: &GatewayLoginInput) -> RequestParams {
|
||||
let profile = input.gp_params.os_profile();
|
||||
let mut body: Vec<(String, String)> = Vec::new();
|
||||
@@ -51,6 +51,10 @@ pub(crate) fn build(input: &GatewayLoginInput) -> RequestParams {
|
||||
|
||||
// Identity fields
|
||||
body.push(("host-id".into(), profile.host_id().into()));
|
||||
if profile.client_os() == ClientOs::Ios {
|
||||
body.push(("mobile-id".into(), profile.host_id().into()));
|
||||
body.push(("vpn-type".into(), "App Level VPN".into()));
|
||||
}
|
||||
body.push(("serialno".into(), profile.serialno().into()));
|
||||
body.push(("preferred-ip".into(), String::new()));
|
||||
body.push(("preferred-ipv6".into(), String::new()));
|
||||
@@ -64,8 +68,13 @@ pub(crate) fn build(input: &GatewayLoginInput) -> RequestParams {
|
||||
if let Some(context) = input.context {
|
||||
let gateway_host = context.host().to_string();
|
||||
body.push(("host".into(), gateway_host.clone()));
|
||||
body.push(("gw".into(), gateway_host.clone()));
|
||||
body.push(("gateway-name".into(), gateway_host));
|
||||
let gateway_name = if profile.client_os() == ClientOs::Ios {
|
||||
context.name().to_owned()
|
||||
} else {
|
||||
gateway_host
|
||||
};
|
||||
body.push(("gw".into(), gateway_name.clone()));
|
||||
body.push(("gateway-name".into(), gateway_name));
|
||||
body.push(("internal".into(), context.kind().as_login_param().to_string()));
|
||||
body.push((
|
||||
"selection-type".into(),
|
||||
@@ -125,7 +134,9 @@ fn resolve_server(input: &GatewayLoginInput) -> String {
|
||||
|
||||
/// Attempt DNS resolution of a hostname to its first IPv4 address.
|
||||
fn resolve_to_ipv4(host: &str) -> Option<String> {
|
||||
(host, 443)
|
||||
let server = crate::utils::normalize_server(host).ok()?;
|
||||
let server = reqwest::Url::parse(&server).ok()?;
|
||||
(server.host_str()?, server.port_or_known_default()?)
|
||||
.to_socket_addrs()
|
||||
.ok()?
|
||||
.find(|addr| addr.ip().is_ipv4())
|
||||
@@ -141,8 +152,39 @@ mod tests {
|
||||
os_profile::{ClientOs, HostIdentity, OsProfile},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn mobile_login_fields_and_gateway_names_are_ios_only() {
|
||||
for os in [ClientOs::Ios, ClientOs::Linux, ClientOs::Mac, ClientOs::Windows] {
|
||||
let params = GpParams::builder(test_profile(os)).build();
|
||||
let gateway = Gateway::new("Regional_Gateway".into(), "192.0.2.1".into());
|
||||
let context = GatewayLoginContext::new(&gateway, GatewaySelection::Manual);
|
||||
let cred = make_credential();
|
||||
let result = build(&GatewayLoginInput {
|
||||
gp_params: ¶ms,
|
||||
cred: &cred,
|
||||
gateway_host: "192.0.2.1",
|
||||
context: Some(&context),
|
||||
client_ip: Some("192.0.2.2"),
|
||||
extend_lifetime: false,
|
||||
});
|
||||
let find = |key: &str| result.body.iter().find(|(k, _)| k == key).map(|(_, v)| v.as_str());
|
||||
assert_eq!(find("host"), Some("192.0.2.1"));
|
||||
if os == ClientOs::Ios {
|
||||
assert_eq!(find("mobile-id"), Some(params.os_profile().host_id()));
|
||||
assert_eq!(find("vpn-type"), Some("App Level VPN"));
|
||||
assert_eq!(find("gw"), Some("Regional_Gateway"));
|
||||
assert_eq!(find("gateway-name"), Some("Regional_Gateway"));
|
||||
} else {
|
||||
assert_eq!(find("mobile-id"), None);
|
||||
assert_eq!(find("vpn-type"), None);
|
||||
assert_eq!(find("gw"), Some("192.0.2.1"));
|
||||
assert_eq!(find("gateway-name"), Some("192.0.2.1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_identity() -> HostIdentity {
|
||||
HostIdentity::new(
|
||||
HostIdentity::from_parts(
|
||||
"test-computer".to_string(),
|
||||
"host-id-123".to_string(),
|
||||
"serial-456".to_string(),
|
||||
@@ -151,7 +193,9 @@ mod tests {
|
||||
}
|
||||
|
||||
fn test_profile(os: ClientOs) -> OsProfile {
|
||||
OsProfile::builder(os).host_identity(test_identity()).build()
|
||||
OsProfile::builder(os)
|
||||
.host_identity(test_identity())
|
||||
.build(crate::os_profile::test_snapshot())
|
||||
}
|
||||
|
||||
fn make_gp_params() -> GpParams {
|
||||
|
||||
@@ -40,7 +40,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn linux_places_params_in_body() {
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build();
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
assert!(!result.body.is_empty());
|
||||
@@ -49,7 +49,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn mac_places_params_in_body_with_kerberos_query() {
|
||||
let profile = OsProfile::builder(ClientOs::Mac).build();
|
||||
let profile = OsProfile::builder(ClientOs::Mac).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
assert!(!result.body.is_empty());
|
||||
@@ -59,7 +59,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn windows_places_all_params_in_query() {
|
||||
let profile = OsProfile::builder(ClientOs::Windows).build();
|
||||
let profile = OsProfile::builder(ClientOs::Windows).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
assert!(result.body.is_empty());
|
||||
@@ -69,7 +69,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn uses_embedded_gateway_default_browser_value() {
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build();
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
let browser_param = result
|
||||
@@ -82,7 +82,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn uses_target_value_when_external_browser_is_requested() {
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build();
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::External);
|
||||
|
||||
let browser_param = result
|
||||
@@ -95,7 +95,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn includes_all_required_params() {
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build();
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
let keys: Vec<&str> = result.body.iter().map(|(k, _)| k.as_str()).collect();
|
||||
@@ -112,7 +112,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn data_param_is_cas_embedded_browser_base64() {
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build();
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
let data_param = result
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{credential::Credential, gp_params::GpParams, os_profile::ClientOs, p
|
||||
/// and left empty on macOS/Windows, matching official client behavior.
|
||||
pub(crate) fn build(cred: &Credential, gp_params: &GpParams, server: &str) -> RequestParams {
|
||||
let profile = gp_params.os_profile();
|
||||
let nonce = if profile.client_os() == ClientOs::Linux {
|
||||
let nonce = if matches!(profile.client_os(), ClientOs::Linux | ClientOs::Ios) {
|
||||
"0".to_string()
|
||||
} else {
|
||||
swg_nonce()
|
||||
@@ -58,17 +58,37 @@ mod tests {
|
||||
os_profile::{ClientOs, HostIdentity, OsProfile},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn ios_uses_zero_swg_nonce_without_changing_desktop_profiles() {
|
||||
for os in [ClientOs::Ios, ClientOs::Linux, ClientOs::Mac, ClientOs::Windows] {
|
||||
let params = GpParams::builder(test_profile(os)).build();
|
||||
let result = build(&password_cred(), ¶ms, "vpn.example.com");
|
||||
let nonce = result
|
||||
.body
|
||||
.iter()
|
||||
.find(|(key, _)| key == "swg-nonce")
|
||||
.unwrap()
|
||||
.1
|
||||
.as_str();
|
||||
if matches!(os, ClientOs::Ios | ClientOs::Linux) {
|
||||
assert_eq!(nonce, "0");
|
||||
} else {
|
||||
assert_ne!(nonce, "0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_profile(os: ClientOs) -> OsProfile {
|
||||
OsProfile::builder(os)
|
||||
.computer_name_override("test-computer")
|
||||
.client_version("6.3.3-100")
|
||||
.host_identity(HostIdentity::new(
|
||||
.host_identity(HostIdentity::from_parts(
|
||||
"test-computer".into(),
|
||||
"test-host-id".into(),
|
||||
"test-serial".into(),
|
||||
"aa:bb:cc:dd:ee:ff".into(),
|
||||
))
|
||||
.build()
|
||||
.build(crate::os_profile::test_snapshot())
|
||||
}
|
||||
|
||||
fn password_cred() -> Credential {
|
||||
|
||||
@@ -44,7 +44,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn linux_places_params_in_body() {
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build();
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
assert!(!result.body.is_empty());
|
||||
@@ -53,7 +53,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn mac_places_params_in_body_with_kerberos_query() {
|
||||
let profile = OsProfile::builder(ClientOs::Mac).build();
|
||||
let profile = OsProfile::builder(ClientOs::Mac).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
assert!(!result.body.is_empty());
|
||||
@@ -63,7 +63,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn windows_places_all_params_in_query() {
|
||||
let profile = OsProfile::builder(ClientOs::Windows).build();
|
||||
let profile = OsProfile::builder(ClientOs::Windows).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
assert!(result.body.is_empty());
|
||||
@@ -73,7 +73,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn uses_embedded_portal_default_browser_value() {
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build();
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
let browser_param = result
|
||||
@@ -86,7 +86,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn uses_target_value_when_external_browser_is_requested() {
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build();
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::External);
|
||||
|
||||
let browser_param = result
|
||||
@@ -99,7 +99,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn includes_all_required_params() {
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build();
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
let keys: Vec<&str> = result.body.iter().map(|(k, _)| k.as_str()).collect();
|
||||
@@ -116,7 +116,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn data_param_is_cas_embedded_browser_base64() {
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build();
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
let data_param = result
|
||||
@@ -129,7 +129,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn kerberos_not_in_query_for_linux() {
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build();
|
||||
let profile = OsProfile::builder(ClientOs::Linux).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
let has_kerberos = result.query.iter().any(|(k, _)| k == "kerberos-support");
|
||||
@@ -138,7 +138,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn kerberos_in_query_for_windows() {
|
||||
let profile = OsProfile::builder(ClientOs::Windows).build();
|
||||
let profile = OsProfile::builder(ClientOs::Windows).build(crate::os_profile::test_snapshot());
|
||||
let result = build(&profile, PreloginBrowserMode::Embedded);
|
||||
|
||||
let has_kerberos = result.query.iter().any(|(k, _)| k == "kerberos-support");
|
||||
|
||||
Reference in new issue
Block a user