mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
feat: add portable GlobalProtect APIs and iOS tunnel support
This commit is contained in:
112 files changed
+3864
-3011
No files matched your search
@@ -307,6 +307,7 @@ fn pbes2_legacy_ciphers_remain_supported() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "desktop")]
|
||||
fn legacy_pkcs8_conversion_preserves_the_key_and_password_errors() {
|
||||
let identity = load("rsa-cert.pem", "rsa-pbes1-3des.pem", Some(PASSWORD)).unwrap();
|
||||
assert_eq!(
|
||||
@@ -326,6 +327,7 @@ fn legacy_pkcs8_conversion_preserves_the_key_and_password_errors() {
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
#[cfg(feature = "desktop")]
|
||||
fn legacy_pkcs8_matches_previous_linux_openssl_processing() {
|
||||
let encrypted = fs::read(fixture("rsa-pbes1-3des.pem")).unwrap();
|
||||
let previous = openssl::pkey::PKey::private_key_from_pem_passphrase(&encrypted, PASSWORD.as_bytes())
|
||||
@@ -338,6 +340,7 @@ fn legacy_pkcs8_matches_previous_linux_openssl_processing() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "desktop")]
|
||||
fn legacy_pkcs8_converter_failures_are_terminal_and_modern_keys_need_no_executable() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
@@ -407,6 +410,7 @@ fn legacy_pkcs8_converter_failures_are_terminal_and_modern_keys_need_no_executab
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "desktop")]
|
||||
fn legacy_converter_reports_its_password_length_limit_without_requesting_a_retry() {
|
||||
let password = "x".repeat(1024);
|
||||
let encrypted = fs::read(fixture("rsa-pbes1-3des-password-1024.pem")).unwrap();
|
||||
@@ -435,6 +439,7 @@ fn legacy_converter_reports_its_password_length_limit_without_requesting_a_retry
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "desktop")]
|
||||
fn legacy_conversion_keeps_original_files_and_rejects_line_breaks_in_passwords() {
|
||||
let original = fs::read(fixture("rsa-pbes1-3des.pem")).unwrap();
|
||||
for password in [
|
||||
@@ -706,3 +711,15 @@ fn mismatched_certificate_key_is_rejected_before_request_client_creation() {
|
||||
.contains("Check that the private key matches the certificate")
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "desktop"))]
|
||||
#[test]
|
||||
fn portable_legacy_pkcs8_is_explicitly_unsupported() {
|
||||
for password in [None, Some(PASSWORD)] {
|
||||
let error = load("rsa-cert.pem", "rsa-pbes1-3des.pem", password).unwrap_err();
|
||||
assert!(matches!(
|
||||
error.downcast_ref::<RequestIdentityError>(),
|
||||
Some(RequestIdentityError::UnsupportedEncryption)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
use gpapi::{
|
||||
credential::{Credential, PasswordCredential},
|
||||
error::AuthenticationRejected,
|
||||
gateway::GatewayLoginClient,
|
||||
gp_params::GpParams,
|
||||
os_profile::{ClientOs, HostIdentity, HostSnapshot, OsProfile},
|
||||
portal,
|
||||
};
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
net::TcpListener,
|
||||
};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
#[tokio::test]
|
||||
async fn explicit_rejection_is_typed_for_ios_without_changing_desktop_errors() {
|
||||
for os in [ClientOs::Ios, ClientOs::Linux, ClientOs::Mac, ClientOs::Windows] {
|
||||
for status in [401, 403, 503] {
|
||||
for gateway in [false, true] {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let origin = format!("http://{}", listener.local_addr().unwrap());
|
||||
let server = tokio::spawn(async move {
|
||||
let (mut socket, _) = listener.accept().await.unwrap();
|
||||
let mut request = Vec::new();
|
||||
loop {
|
||||
let mut chunk = [0; 4096];
|
||||
let count = socket.read(&mut chunk).await.unwrap();
|
||||
if count == 0 {
|
||||
break;
|
||||
}
|
||||
request.extend_from_slice(&chunk[..count]);
|
||||
if let Some(end) = request.windows(4).position(|v| v == b"\r\n\r\n") {
|
||||
let headers = String::from_utf8_lossy(&request[..end]).to_lowercase();
|
||||
let length: usize = headers
|
||||
.lines()
|
||||
.find_map(|line| line.strip_prefix("content-length:").and_then(|s| s.trim().parse().ok()))
|
||||
.unwrap_or(0);
|
||||
if request.len() >= end + 4 + length {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
socket
|
||||
.write_all(format!("HTTP/1.1 {status} Test\r\nContent-Length: 0\r\nConnection: close\r\n\r\n").as_bytes())
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
let profile = OsProfile::builder(os).build(HostSnapshot {
|
||||
runtime_os: os,
|
||||
identity: HostIdentity::application("fixture".into(), "fixture-id".into()),
|
||||
os_version: "fixture".into(),
|
||||
software_version: String::new(),
|
||||
});
|
||||
let params = GpParams::builder(profile).build();
|
||||
let credential = Credential::Password(PasswordCredential::new("fixture", "fixture-password"));
|
||||
let token = CancellationToken::new();
|
||||
let error = if gateway {
|
||||
GatewayLoginClient::new(&origin, params)
|
||||
.unwrap()
|
||||
.login(&credential, None, &token)
|
||||
.await
|
||||
.err()
|
||||
.unwrap()
|
||||
} else {
|
||||
portal::retrieve_config(&origin, &credential, ¶ms, &token)
|
||||
.await
|
||||
.err()
|
||||
.unwrap()
|
||||
};
|
||||
server.await.unwrap();
|
||||
assert_eq!(
|
||||
error.is::<AuthenticationRejected>(),
|
||||
os == ClientOs::Ios && status != 503,
|
||||
"os={os:?}, status={status}, gateway={gateway}"
|
||||
);
|
||||
if os != ClientOs::Ios {
|
||||
let prefix = if gateway {
|
||||
"Gateway login error:"
|
||||
} else {
|
||||
"Portal config error:"
|
||||
};
|
||||
assert!(error.to_string().starts_with(prefix));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
use gpapi::{
|
||||
gp_params::GpParams,
|
||||
os_profile::{ClientOs, HostIdentity, OsProfile},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn mobile_profile_preserves_supplied_identity_without_hardware_claims() {
|
||||
let profile = OsProfile::builder(ClientOs::Ios).build(gpapi::os_profile::HostSnapshot {
|
||||
runtime_os: ClientOs::Ios,
|
||||
identity: HostIdentity::application("Phone".into(), "installation-id".into()),
|
||||
os_version: "Apple iOS 27.0.1".into(),
|
||||
software_version: String::new(),
|
||||
});
|
||||
assert_eq!(profile.client_os().as_str(), "iOS");
|
||||
assert_eq!(profile.client_os().to_openconnect_os(), "apple-ios");
|
||||
assert_eq!(profile.host_id(), "installation-id");
|
||||
assert_eq!(profile.computer(), "Phone");
|
||||
assert_eq!(profile.os_version(), "Apple iOS 27.0.1");
|
||||
assert!(profile.serialno().is_empty());
|
||||
assert!(profile.mac_addr().is_empty());
|
||||
assert!(!GpParams::builder(profile).build().ignore_tls_errors());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reported_profile_does_not_change_runtime_platform() {
|
||||
let profile = OsProfile::builder(ClientOs::Mac).build(gpapi::os_profile::HostSnapshot {
|
||||
runtime_os: ClientOs::Ios,
|
||||
identity: HostIdentity::application("Phone".into(), "installation-id".into()),
|
||||
os_version: "Apple iOS 27.0.1".into(),
|
||||
software_version: String::new(),
|
||||
});
|
||||
assert!(!profile.is_native());
|
||||
assert!(profile.os_version().starts_with("Apple Mac OS X "));
|
||||
assert_eq!(profile.host_identity().host_id(), "installation-id");
|
||||
}
|
||||
Reference in new issue
Block a user