mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-20 06:56:17 -05:00
feat: add support for client version emulation and integrate OpenConnect submodule
This commit is contained in:
21 files changed
+273
-29
No files matched your search
@@ -54,6 +54,7 @@ jobs:
|
|||||||
repository: yuezk/GlobalProtect-openconnect
|
repository: yuezk/GlobalProtect-openconnect
|
||||||
ref: ${{ github.ref }}
|
ref: ${{ github.ref }}
|
||||||
path: source/gp
|
path: source/gp
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
- name: Create tarball
|
- name: Create tarball
|
||||||
run: |
|
run: |
|
||||||
@@ -194,6 +195,7 @@ jobs:
|
|||||||
repository: yuezk/GlobalProtect-openconnect
|
repository: yuezk/GlobalProtect-openconnect
|
||||||
ref: ${{ github.ref }}
|
ref: ${{ github.ref }}
|
||||||
path: gpgui-source/gp
|
path: gpgui-source/gp
|
||||||
|
submodules: recursive
|
||||||
- name: Checkout gpgui@${{ github.ref_name }}
|
- name: Checkout gpgui@${{ github.ref_name }}
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
@@ -249,6 +251,7 @@ jobs:
|
|||||||
repository: yuezk/GlobalProtect-openconnect
|
repository: yuezk/GlobalProtect-openconnect
|
||||||
ref: ${{ github.ref }}
|
ref: ${{ github.ref }}
|
||||||
path: gh-release/gp
|
path: gh-release/gp
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
- name: Download all artifacts
|
- name: Download all artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "deps/openconnect"]
|
||||||
|
path = deps/openconnect
|
||||||
|
url = https://gitlab.com/openconnect/openconnect.git
|
||||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Mac",
|
"name": "Mac",
|
||||||
"includePath": ["/opt/homebrew/include"],
|
"includePath": ["deps/openconnect"],
|
||||||
"macFrameworkPath": ["/System/Library/Frameworks", "/Library/Frameworks"],
|
"macFrameworkPath": ["/System/Library/Frameworks", "/Library/Frameworks"],
|
||||||
"intelliSenseMode": "macos-clang-x64",
|
"intelliSenseMode": "macos-clang-x64",
|
||||||
"compilerPath": "/usr/bin/clang",
|
"compilerPath": "/usr/bin/clang",
|
||||||
|
|||||||
Generated
+18
@@ -190,6 +190,15 @@ version = "1.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autotools"
|
||||||
|
version = "0.2.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ef941527c41b0fc0dd48511a8154cd5fc7e29200a0ff8b7203c5d777dbc795cf"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "axum"
|
name = "axum"
|
||||||
version = "0.8.6"
|
version = "0.8.6"
|
||||||
@@ -1235,6 +1244,12 @@ dependencies = [
|
|||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fs_extra"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futf"
|
name = "futf"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
@@ -2981,9 +2996,12 @@ dependencies = [
|
|||||||
name = "openconnect"
|
name = "openconnect"
|
||||||
version = "2.4.7"
|
version = "2.4.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"autotools",
|
||||||
"cc",
|
"cc",
|
||||||
|
"fs_extra",
|
||||||
"is_executable",
|
"is_executable",
|
||||||
"log",
|
"log",
|
||||||
|
"pkg-config",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ INCLUDE_GUI ?= 0
|
|||||||
CARGO ?= cargo
|
CARGO ?= cargo
|
||||||
DISABLE_RUST_TOOLCHAIN ?= 0
|
DISABLE_RUST_TOOLCHAIN ?= 0
|
||||||
|
|
||||||
VERSION = $(shell $(CARGO) metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
|
VERSION = $(shell grep '^version' Cargo.toml | head -1 | sed 's/version *= *"\(.*\)"/\1/')
|
||||||
REVISION ?= 1
|
REVISION ?= 1
|
||||||
RPM_SOURCE ?= %{name}.tar.gz
|
RPM_SOURCE ?= %{name}.tar.gz
|
||||||
|
|
||||||
|
|||||||
@@ -205,10 +205,11 @@ This project includes a devcontainer configuration that provides a consistent bu
|
|||||||
|
|
||||||
#### Build Steps
|
#### Build Steps
|
||||||
|
|
||||||
1. Clone the repository:
|
1. Clone the repository and submodules:
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/yuezk/GlobalProtect-openconnect.git
|
git clone https://github.com/yuezk/GlobalProtect-openconnect.git
|
||||||
cd GlobalProtect-openconnect
|
cd GlobalProtect-openconnect
|
||||||
|
git submodule update --init --recursive
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Build the devcontainer image:
|
2. Build the devcontainer image:
|
||||||
@@ -216,12 +217,8 @@ This project includes a devcontainer configuration that provides a consistent bu
|
|||||||
docker build -t gpoc-devcontainer .devcontainer/
|
docker build -t gpoc-devcontainer .devcontainer/
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Install `jq` in the container and build the project:
|
3. Build the project:
|
||||||
```bash
|
```bash
|
||||||
docker run --privileged --cap-add=NET_ADMIN --device=/dev/net/tun \
|
|
||||||
-v "$(pwd)":/workspace -w /workspace --user root gpoc-devcontainer \
|
|
||||||
bash -c "apt-get update && apt-get install -y jq"
|
|
||||||
|
|
||||||
docker run --privileged --cap-add=NET_ADMIN --device=/dev/net/tun \
|
docker run --privileged --cap-add=NET_ADMIN --device=/dev/net/tun \
|
||||||
-v "$(pwd)":/workspace -w /workspace gpoc-devcontainer \
|
-v "$(pwd)":/workspace -w /workspace gpoc-devcontainer \
|
||||||
bash -c "export PATH=/usr/local/cargo/bin:\$PATH && make build"
|
bash -c "export PATH=/usr/local/cargo/bin:\$PATH && make build"
|
||||||
@@ -248,7 +245,7 @@ This project includes a devcontainer configuration that provides a consistent bu
|
|||||||
|
|
||||||
- [Install Rust 1.85 or later](https://www.rust-lang.org/tools/install)
|
- [Install Rust 1.85 or later](https://www.rust-lang.org/tools/install)
|
||||||
- Install Tauri dependencies: https://tauri.app/start/prerequisites/
|
- Install Tauri dependencies: https://tauri.app/start/prerequisites/
|
||||||
- Install `perl` and `jq`
|
- Install `perl`
|
||||||
- Install `openconnect >= 8.20` and `libopenconnect-dev` (or `openconnect-devel` on RPM-based distributions)
|
- Install `openconnect >= 8.20` and `libopenconnect-dev` (or `openconnect-devel` on RPM-based distributions)
|
||||||
- Install `pkexec`, `gnome-keyring` (or `pam_kwallet` on KDE)
|
- Install `pkexec`, `gnome-keyring` (or `pam_kwallet` on KDE)
|
||||||
- Install `nodejs` and `pnpm` (optional only if you downloaded the source tarball from the release page and run with the `BUILD_FE=0` flag, see below)
|
- Install `nodejs` and `pnpm` (optional only if you downloaded the source tarball from the release page and run with the `BUILD_FE=0` flag, see below)
|
||||||
|
|||||||
@@ -95,6 +95,9 @@ pub(crate) struct ConnectArgs {
|
|||||||
#[arg(long, help = "If not specified, it will be computed based on the --os option")]
|
#[arg(long, help = "If not specified, it will be computed based on the --os option")]
|
||||||
os_version: Option<String>,
|
os_version: Option<String>,
|
||||||
|
|
||||||
|
#[arg(long, help = "The GP client version to emulate, e.g., '6.2.4-49'")]
|
||||||
|
client_version: Option<String>,
|
||||||
|
|
||||||
#[arg(long, help = "Disable DTLS and ESP")]
|
#[arg(long, help = "Disable DTLS and ESP")]
|
||||||
no_dtls: bool,
|
no_dtls: bool,
|
||||||
|
|
||||||
@@ -276,7 +279,11 @@ impl<'a> ConnectHandler<'a> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.connect_gateway(gateway, &cookie).await
|
// Use the client version from the command line argument if specified, otherwise
|
||||||
|
// use the version from the portal config if available
|
||||||
|
let client_version = self.args.client_version.as_deref().or_else(|| portal_config.version());
|
||||||
|
|
||||||
|
self.connect_gateway(gateway, &cookie, client_version).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn connect_gateway_with_prelogin(&self, gateway: &str) -> anyhow::Result<()> {
|
async fn connect_gateway_with_prelogin(&self, gateway: &str) -> anyhow::Result<()> {
|
||||||
@@ -290,7 +297,10 @@ impl<'a> ConnectHandler<'a> {
|
|||||||
|
|
||||||
let cookie = self.login_gateway(gateway, &cred, &gp_params).await?;
|
let cookie = self.login_gateway(gateway, &cred, &gp_params).await?;
|
||||||
|
|
||||||
self.connect_gateway(gateway, &cookie).await
|
// When logging in to a gateway directly, there is no portal config to get the client version from
|
||||||
|
let client_version = self.args.client_version.as_deref();
|
||||||
|
|
||||||
|
self.connect_gateway(gateway, &cookie, client_version).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn login_gateway(&self, gateway: &str, cred: &Credential, gp_params: &GpParams) -> anyhow::Result<String> {
|
async fn login_gateway(&self, gateway: &str, cred: &Credential, gp_params: &GpParams) -> anyhow::Result<String> {
|
||||||
@@ -310,7 +320,7 @@ impl<'a> ConnectHandler<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn connect_gateway(&self, gateway: &str, cookie: &str) -> anyhow::Result<()> {
|
async fn connect_gateway(&self, gateway: &str, cookie: &str, client_version: Option<&str>) -> anyhow::Result<()> {
|
||||||
let mtu = self.args.mtu.unwrap_or(0);
|
let mtu = self.args.mtu.unwrap_or(0);
|
||||||
let csd_uid = get_csd_uid(&self.args.csd_user)?;
|
let csd_uid = get_csd_uid(&self.args.csd_user)?;
|
||||||
let (hip, csd_wrapper) = if let Some(csd_wrapper) = &self.args.csd_wrapper {
|
let (hip, csd_wrapper) = if let Some(csd_wrapper) = &self.args.csd_wrapper {
|
||||||
@@ -322,12 +332,14 @@ impl<'a> ConnectHandler<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let os = ClientOs::from(&self.args.os).to_openconnect_os().to_string();
|
let os = ClientOs::from(&self.args.os).to_openconnect_os().to_string();
|
||||||
|
let client_version = client_version.map(|s| s.to_owned());
|
||||||
let vpn = Vpn::builder(gateway, cookie)
|
let vpn = Vpn::builder(gateway, cookie)
|
||||||
.script(self.args.script.clone())
|
.script(self.args.script.clone())
|
||||||
.interface(self.args.interface.clone())
|
.interface(self.args.interface.clone())
|
||||||
.script_tun(self.args.script_tun)
|
.script_tun(self.args.script_tun)
|
||||||
.user_agent(self.args.user_agent.clone())
|
.user_agent(self.args.user_agent.clone())
|
||||||
.os(Some(os))
|
.os(Some(os))
|
||||||
|
.client_version(client_version)
|
||||||
.certificate(self.args.certificate.clone())
|
.certificate(self.args.certificate.clone())
|
||||||
.sslkey(self.args.sslkey.clone())
|
.sslkey(self.args.sslkey.clone())
|
||||||
.key_password(self.latest_key_password.borrow().clone())
|
.key_password(self.latest_key_password.borrow().clone())
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ impl VpnTaskContext {
|
|||||||
.script(args.vpnc_script())
|
.script(args.vpnc_script())
|
||||||
.user_agent(args.user_agent())
|
.user_agent(args.user_agent())
|
||||||
.os(args.openconnect_os())
|
.os(args.openconnect_os())
|
||||||
|
.client_version(args.client_version())
|
||||||
.certificate(args.certificate())
|
.certificate(args.certificate())
|
||||||
.sslkey(args.sslkey())
|
.sslkey(args.sslkey())
|
||||||
.key_password(args.key_password())
|
.key_password(args.key_password())
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
use dns_lookup::lookup_addr;
|
use dns_lookup::lookup_addr;
|
||||||
use log::{info, warn};
|
use log::{debug, info, warn};
|
||||||
use reqwest::{Client, StatusCode};
|
use reqwest::{Client, StatusCode};
|
||||||
use roxmltree::{Document, Node};
|
use roxmltree::{Document, Node};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@@ -9,7 +9,7 @@ use specta::Type;
|
|||||||
use crate::{
|
use crate::{
|
||||||
credential::{AuthCookieCredential, Credential},
|
credential::{AuthCookieCredential, Credential},
|
||||||
error::PortalError,
|
error::PortalError,
|
||||||
gateway::{parse_gateways, Gateway},
|
gateway::{Gateway, parse_gateways},
|
||||||
gp_params::GpParams,
|
gp_params::GpParams,
|
||||||
utils::{normalize_server, parse_gp_response, remove_url_scheme, xml::NodeExt},
|
utils::{normalize_server, parse_gp_response, remove_url_scheme, xml::NodeExt},
|
||||||
};
|
};
|
||||||
@@ -29,6 +29,10 @@ pub struct PortalConfig {
|
|||||||
* - Some(true): Internal host detection is supported and the user is connected to the internal network
|
* - Some(true): Internal host detection is supported and the user is connected to the internal network
|
||||||
*/
|
*/
|
||||||
internal_host_detection: Option<bool>,
|
internal_host_detection: Option<bool>,
|
||||||
|
/**
|
||||||
|
* The version returned by the portal config, if any
|
||||||
|
*/
|
||||||
|
version: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PortalConfig {
|
impl PortalConfig {
|
||||||
@@ -52,6 +56,10 @@ impl PortalConfig {
|
|||||||
self.internal_host_detection
|
self.internal_host_detection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn version(&self) -> Option<&str> {
|
||||||
|
self.version.as_deref()
|
||||||
|
}
|
||||||
|
|
||||||
/// In-place sort the gateways by region
|
/// In-place sort the gateways by region
|
||||||
pub fn sort_gateways(&mut self, region: &str) {
|
pub fn sort_gateways(&mut self, region: &str) {
|
||||||
let preferred_gateway = self.find_preferred_gateway(region);
|
let preferred_gateway = self.find_preferred_gateway(region);
|
||||||
@@ -133,6 +141,7 @@ pub async fn retrieve_config(portal: &str, cred: &Credential, gp_params: &GpPara
|
|||||||
bail!(PortalError::ConfigError("Empty portal config response".to_string()))
|
bail!(PortalError::ConfigError("Empty portal config response".to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug!("Portal config response: {}", res_xml);
|
||||||
let doc = Document::parse(&res_xml).map_err(|e| PortalError::ConfigError(e.to_string()))?;
|
let doc = Document::parse(&res_xml).map_err(|e| PortalError::ConfigError(e.to_string()))?;
|
||||||
let root = doc.root();
|
let root = doc.root();
|
||||||
|
|
||||||
@@ -158,6 +167,9 @@ pub async fn retrieve_config(portal: &str, cred: &Credential, gp_params: &GpPara
|
|||||||
gateways.push(Gateway::new(server.to_string(), server.to_string()));
|
gateways.push(Gateway::new(server.to_string(), server.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let version = root.descendant_text("version").map(|s| s.to_string());
|
||||||
|
info!("Detected portal version: {:?}", version);
|
||||||
|
|
||||||
Ok(PortalConfig {
|
Ok(PortalConfig {
|
||||||
portal: server.to_string(),
|
portal: server.to_string(),
|
||||||
auth_cookie: AuthCookieCredential::new(cred.username(), user_auth_cookie, prelogon_user_auth_cookie),
|
auth_cookie: AuthCookieCredential::new(cred.username(), user_auth_cookie, prelogon_user_auth_cookie),
|
||||||
@@ -165,6 +177,7 @@ pub async fn retrieve_config(portal: &str, cred: &Credential, gp_params: &GpPara
|
|||||||
gateways,
|
gateways,
|
||||||
config_digest: config_digest.map(|s| s.to_string()),
|
config_digest: config_digest.map(|s| s.to_string()),
|
||||||
internal_host_detection: if ihd_enabled { Some(prefer_internal) } else { None },
|
internal_host_detection: if ihd_enabled { Some(prefer_internal) } else { None },
|
||||||
|
version,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,14 +31,19 @@ impl LaunchGuiRequest {
|
|||||||
pub struct ConnectArgs {
|
pub struct ConnectArgs {
|
||||||
cookie: String,
|
cookie: String,
|
||||||
vpnc_script: Option<String>,
|
vpnc_script: Option<String>,
|
||||||
|
|
||||||
user_agent: Option<String>,
|
user_agent: Option<String>,
|
||||||
os: Option<ClientOs>,
|
os: Option<ClientOs>,
|
||||||
|
client_version: Option<String>,
|
||||||
|
|
||||||
certificate: Option<String>,
|
certificate: Option<String>,
|
||||||
sslkey: Option<String>,
|
sslkey: Option<String>,
|
||||||
key_password: Option<String>,
|
key_password: Option<String>,
|
||||||
|
|
||||||
hip: bool,
|
hip: bool,
|
||||||
csd_uid: u32,
|
csd_uid: u32,
|
||||||
csd_wrapper: Option<String>,
|
csd_wrapper: Option<String>,
|
||||||
|
|
||||||
reconnect_timeout: u32,
|
reconnect_timeout: u32,
|
||||||
mtu: u32,
|
mtu: u32,
|
||||||
disable_ipv6: bool,
|
disable_ipv6: bool,
|
||||||
@@ -52,6 +57,7 @@ impl ConnectArgs {
|
|||||||
vpnc_script: None,
|
vpnc_script: None,
|
||||||
user_agent: None,
|
user_agent: None,
|
||||||
os: None,
|
os: None,
|
||||||
|
client_version: None,
|
||||||
certificate: None,
|
certificate: None,
|
||||||
sslkey: None,
|
sslkey: None,
|
||||||
key_password: None,
|
key_password: None,
|
||||||
@@ -81,6 +87,10 @@ impl ConnectArgs {
|
|||||||
self.os.as_ref().map(|os| os.to_openconnect_os().to_string())
|
self.os.as_ref().map(|os| os.to_openconnect_os().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn client_version(&self) -> Option<String> {
|
||||||
|
self.client_version.clone()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn certificate(&self) -> Option<String> {
|
pub fn certificate(&self) -> Option<String> {
|
||||||
self.certificate.clone()
|
self.certificate.clone()
|
||||||
}
|
}
|
||||||
@@ -166,6 +176,11 @@ impl ConnectRequest {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_client_version(mut self, client_version: &str) -> Self {
|
||||||
|
self.args.client_version = Some(client_version.to_string());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_certificate<T: Into<Option<String>>>(mut self, certificate: T) -> Self {
|
pub fn with_certificate<T: Into<Option<String>>>(mut self, certificate: T) -> Self {
|
||||||
self.args.certificate = certificate.into();
|
self.args.certificate = certificate.into();
|
||||||
self
|
self
|
||||||
|
|||||||
@@ -11,3 +11,6 @@ is_executable.workspace = true
|
|||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cc = "1"
|
cc = "1"
|
||||||
|
autotools = "0.2"
|
||||||
|
pkg-config = "0.3"
|
||||||
|
fs_extra = "1"
|
||||||
@@ -1,14 +1,91 @@
|
|||||||
|
use std::{env, path::PathBuf, process::Command};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Link to the native openconnect library
|
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
println!("cargo:rustc-link-lib=openconnect");
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
println!("cargo:rustc-link-search=/opt/homebrew/lib"); // Homebrew path
|
let deps_dir = PathBuf::from(&manifest_dir).join("../../deps");
|
||||||
|
let openconnect_dir = deps_dir.join("openconnect");
|
||||||
|
let gp_version_patch = deps_dir.join("patches/openconnect-gp-version.patch");
|
||||||
|
|
||||||
|
// The temporary location where we will build
|
||||||
|
let build_src = out_dir.join("openconnect_build");
|
||||||
|
|
||||||
|
// Track changes so cargo rebuilds if patch or submodule changes
|
||||||
|
println!("cargo:rerun-if-changed={}", openconnect_dir.display());
|
||||||
|
println!("cargo:rerun-if-changed={}", gp_version_patch.display());
|
||||||
|
|
||||||
|
// Prepare the build directory
|
||||||
|
// If the directory exists from a previous run, remove it to ensure a clean slate
|
||||||
|
if build_src.exists() {
|
||||||
|
std::fs::remove_dir_all(&build_src).unwrap();
|
||||||
|
}
|
||||||
|
std::fs::create_dir_all(&build_src).unwrap();
|
||||||
|
|
||||||
|
// Copy the source code to OUT_DIR
|
||||||
|
// We use fs_extra options to copy contents recursively
|
||||||
|
let mut options = fs_extra::dir::CopyOptions::new();
|
||||||
|
options.overwrite = true;
|
||||||
|
options.content_only = true; // Copy content of src into dest, not src folder itself
|
||||||
|
|
||||||
|
fs_extra::dir::copy(&openconnect_dir, &build_src, &options).expect("Failed to copy C source code to OUT_DIR");
|
||||||
|
|
||||||
|
// Apply the Patch
|
||||||
|
// We use the system `patch` command.
|
||||||
|
let status = Command::new("patch")
|
||||||
|
.arg("-p1") // Strip one level of path (standard for git diffs)
|
||||||
|
.arg("-i") // Input file
|
||||||
|
.arg(&gp_version_patch)
|
||||||
|
.current_dir(&build_src) // Run INSIDE the copied dir
|
||||||
|
.status()
|
||||||
|
.expect("Failed to execute patch command");
|
||||||
|
|
||||||
|
if !status.success() {
|
||||||
|
panic!("Failed to apply patch file: {}", gp_version_patch.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the OpenConnect library using autotools
|
||||||
|
// We explicitly enable static and disable shared to ensure we get a .a file.
|
||||||
|
// .reconf("-ivf") is CRITICAL for git submodules because 'configure'
|
||||||
|
// usually doesn't exist yet and needs to be generated.
|
||||||
|
let dst = autotools::Config::new(&build_src)
|
||||||
|
.reconf("-ivf")
|
||||||
|
.enable_static()
|
||||||
|
.disable_shared()
|
||||||
|
.disable("nls", None) // disable translations to save space
|
||||||
|
.disable("docs", None)
|
||||||
|
.disable("dsa-tests", None)
|
||||||
|
.without("libproxy", None)
|
||||||
|
.without("stoken", None)
|
||||||
|
.without("libpcsclite", None)
|
||||||
|
.without("libpskc", None)
|
||||||
|
.without("gssapi", None)
|
||||||
|
.with("gnutls-tss2", Some("no"))
|
||||||
|
.with("vpnc-script", Some("/etc/vpnc/vpnc-script")) // Specify vpnc-script, otherwise it will fail on macOS
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// Link the 'openconnect' static library
|
||||||
|
println!("cargo:rustc-link-search=native={}/lib", dst.display());
|
||||||
|
println!("cargo:rustc-link-lib=static=openconnect");
|
||||||
|
|
||||||
|
// Using pkg-config to find system deps
|
||||||
|
pkg_config::probe_library("libxml-2.0").unwrap();
|
||||||
|
pkg_config::probe_library("zlib").unwrap();
|
||||||
|
pkg_config::probe_library("liblz4").unwrap();
|
||||||
|
pkg_config::probe_library("gnutls").unwrap();
|
||||||
|
|
||||||
|
// Below are required by gnutls
|
||||||
|
pkg_config::probe_library("p11-kit-1").unwrap();
|
||||||
|
pkg_config::probe_library("hogweed").unwrap();
|
||||||
|
pkg_config::probe_library("nettle").unwrap();
|
||||||
|
pkg_config::probe_library("gmp").unwrap();
|
||||||
|
|
||||||
|
// Compile the vpn.c file
|
||||||
println!("cargo:rerun-if-changed=src/ffi/vpn.c");
|
println!("cargo:rerun-if-changed=src/ffi/vpn.c");
|
||||||
println!("cargo:rerun-if-changed=src/ffi/vpn.h");
|
println!("cargo:rerun-if-changed=src/ffi/vpn.h");
|
||||||
|
|
||||||
// Compile the vpn.c file
|
|
||||||
cc::Build::new()
|
cc::Build::new()
|
||||||
.file("src/ffi/vpn.c")
|
.file("src/ffi/vpn.c")
|
||||||
.include("src/ffi")
|
.include("src/ffi")
|
||||||
.include("/opt/homebrew/include") // Homebrew path
|
.include(&dst.join("include"))
|
||||||
.compile("vpn");
|
.compile("vpn");
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ use crate::Vpn;
|
|||||||
use log::{debug, info, trace, warn};
|
use log::{debug, info, trace, warn};
|
||||||
use std::ffi::{c_char, c_int, c_void};
|
use std::ffi::{c_char, c_int, c_void};
|
||||||
|
|
||||||
|
/// ConnectOptions struct for FFI, the field names and order must match the C definition.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct ConnectOptions {
|
pub(crate) struct ConnectOptions {
|
||||||
@@ -9,12 +10,15 @@ pub(crate) struct ConnectOptions {
|
|||||||
|
|
||||||
pub server: *const c_char,
|
pub server: *const c_char,
|
||||||
pub cookie: *const c_char,
|
pub cookie: *const c_char,
|
||||||
|
|
||||||
pub user_agent: *const c_char,
|
pub user_agent: *const c_char,
|
||||||
|
pub os: *const c_char,
|
||||||
|
pub client_version: *const c_char,
|
||||||
|
|
||||||
pub script: *const c_char,
|
pub script: *const c_char,
|
||||||
pub interface: *const c_char,
|
pub interface: *const c_char,
|
||||||
pub script_tun: u32,
|
pub script_tun: u32,
|
||||||
pub os: *const c_char,
|
|
||||||
pub certificate: *const c_char,
|
pub certificate: *const c_char,
|
||||||
pub sslkey: *const c_char,
|
pub sslkey: *const c_char,
|
||||||
pub key_password: *const c_char,
|
pub key_password: *const c_char,
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ static void setup_tun_handler(void *_vpninfo)
|
|||||||
/* Initialize VPN connection */
|
/* Initialize VPN connection */
|
||||||
int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
||||||
{
|
{
|
||||||
INFO("openconnect version: %s", openconnect_get_version());
|
|
||||||
struct openconnect_info *vpninfo;
|
struct openconnect_info *vpninfo;
|
||||||
struct utsname utsbuf;
|
struct utsname utsbuf;
|
||||||
|
|
||||||
@@ -70,6 +69,7 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
|||||||
|
|
||||||
INFO("USER_AGENT: %s", options->user_agent);
|
INFO("USER_AGENT: %s", options->user_agent);
|
||||||
INFO("OS: %s", options->os);
|
INFO("OS: %s", options->os);
|
||||||
|
INFO("CLIENT_VERSION: %s", options->client_version);
|
||||||
INFO("VPNC_SCRIPT: %s", options->script);
|
INFO("VPNC_SCRIPT: %s", options->script);
|
||||||
INFO("SCRIPT_TUN: %d", g_script_tun);
|
INFO("SCRIPT_TUN: %d", g_script_tun);
|
||||||
INFO("CSD_USER: %d", options->csd_uid);
|
INFO("CSD_USER: %d", options->csd_uid);
|
||||||
@@ -99,6 +99,11 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
|||||||
openconnect_set_reported_os(vpninfo, options->os);
|
openconnect_set_reported_os(vpninfo, options->os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options->client_version) {
|
||||||
|
openconnect_set_gp_app_version(vpninfo,
|
||||||
|
options->client_version);
|
||||||
|
}
|
||||||
|
|
||||||
if (options->certificate) {
|
if (options->certificate) {
|
||||||
INFO("Setting client certificate: %s", options->certificate);
|
INFO("Setting client certificate: %s", options->certificate);
|
||||||
openconnect_set_client_cert(vpninfo, options->certificate,
|
openconnect_set_client_cert(vpninfo, options->certificate,
|
||||||
|
|||||||
@@ -7,14 +7,18 @@ typedef void (*vpn_connected_callback)(int cmd_pipe_fd, void *user_data);
|
|||||||
|
|
||||||
typedef struct vpn_options {
|
typedef struct vpn_options {
|
||||||
void *user_data;
|
void *user_data;
|
||||||
|
|
||||||
const char *server;
|
const char *server;
|
||||||
const char *cookie;
|
const char *cookie;
|
||||||
|
|
||||||
const char *user_agent;
|
const char *user_agent;
|
||||||
|
const char *os;
|
||||||
|
const char *client_version;
|
||||||
|
|
||||||
const char *script;
|
const char *script;
|
||||||
const char *interface;
|
const char *interface;
|
||||||
const int script_tun;
|
const int script_tun;
|
||||||
const char *os;
|
|
||||||
const char *certificate;
|
const char *certificate;
|
||||||
const char *sslkey;
|
const char *sslkey;
|
||||||
const char *key_password;
|
const char *key_password;
|
||||||
|
|||||||
@@ -14,11 +14,15 @@ type OnConnectedCallback = Arc<RwLock<Option<Box<dyn FnOnce() + 'static + Send +
|
|||||||
pub struct Vpn {
|
pub struct Vpn {
|
||||||
server: CString,
|
server: CString,
|
||||||
cookie: CString,
|
cookie: CString,
|
||||||
|
|
||||||
user_agent: CString,
|
user_agent: CString,
|
||||||
|
os: CString,
|
||||||
|
client_version: Option<CString>,
|
||||||
|
|
||||||
script: CString,
|
script: CString,
|
||||||
interface: Option<CString>,
|
interface: Option<CString>,
|
||||||
script_tun: bool,
|
script_tun: bool,
|
||||||
os: CString,
|
|
||||||
certificate: Option<CString>,
|
certificate: Option<CString>,
|
||||||
sslkey: Option<CString>,
|
sslkey: Option<CString>,
|
||||||
key_password: Option<CString>,
|
key_password: Option<CString>,
|
||||||
@@ -67,11 +71,14 @@ impl Vpn {
|
|||||||
|
|
||||||
server: self.server.as_ptr(),
|
server: self.server.as_ptr(),
|
||||||
cookie: self.cookie.as_ptr(),
|
cookie: self.cookie.as_ptr(),
|
||||||
|
|
||||||
user_agent: self.user_agent.as_ptr(),
|
user_agent: self.user_agent.as_ptr(),
|
||||||
|
os: self.os.as_ptr(),
|
||||||
|
client_version: Self::option_to_ptr(&self.client_version),
|
||||||
|
|
||||||
script: self.script.as_ptr(),
|
script: self.script.as_ptr(),
|
||||||
interface: Self::option_to_ptr(&self.interface),
|
interface: Self::option_to_ptr(&self.interface),
|
||||||
script_tun: self.script_tun as u32,
|
script_tun: self.script_tun as u32,
|
||||||
os: self.os.as_ptr(),
|
|
||||||
|
|
||||||
certificate: Self::option_to_ptr(&self.certificate),
|
certificate: Self::option_to_ptr(&self.certificate),
|
||||||
sslkey: Self::option_to_ptr(&self.sslkey),
|
sslkey: Self::option_to_ptr(&self.sslkey),
|
||||||
@@ -125,6 +132,7 @@ pub struct VpnBuilder {
|
|||||||
|
|
||||||
user_agent: Option<String>,
|
user_agent: Option<String>,
|
||||||
os: Option<String>,
|
os: Option<String>,
|
||||||
|
client_version: Option<String>,
|
||||||
|
|
||||||
certificate: Option<String>,
|
certificate: Option<String>,
|
||||||
sslkey: Option<String>,
|
sslkey: Option<String>,
|
||||||
@@ -153,6 +161,7 @@ impl VpnBuilder {
|
|||||||
|
|
||||||
user_agent: None,
|
user_agent: None,
|
||||||
os: None,
|
os: None,
|
||||||
|
client_version: None,
|
||||||
|
|
||||||
certificate: None,
|
certificate: None,
|
||||||
sslkey: None,
|
sslkey: None,
|
||||||
@@ -195,6 +204,11 @@ impl VpnBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn client_version<T: Into<Option<String>>>(mut self, client_version: T) -> Self {
|
||||||
|
self.client_version = client_version.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn certificate<T: Into<Option<String>>>(mut self, certificate: T) -> Self {
|
pub fn certificate<T: Into<Option<String>>>(mut self, certificate: T) -> Self {
|
||||||
self.certificate = certificate.into();
|
self.certificate = certificate.into();
|
||||||
self
|
self
|
||||||
@@ -287,11 +301,14 @@ impl VpnBuilder {
|
|||||||
Ok(Vpn {
|
Ok(Vpn {
|
||||||
server: Self::to_cstring(&self.server),
|
server: Self::to_cstring(&self.server),
|
||||||
cookie: Self::to_cstring(&self.cookie),
|
cookie: Self::to_cstring(&self.cookie),
|
||||||
|
|
||||||
user_agent: Self::to_cstring(&user_agent),
|
user_agent: Self::to_cstring(&user_agent),
|
||||||
|
os: Self::to_cstring(&os),
|
||||||
|
client_version: self.client_version.as_deref().map(Self::to_cstring),
|
||||||
|
|
||||||
script: Self::to_cstring(&script),
|
script: Self::to_cstring(&script),
|
||||||
interface: self.interface.as_deref().map(Self::to_cstring),
|
interface: self.interface.as_deref().map(Self::to_cstring),
|
||||||
script_tun: self.script_tun,
|
script_tun: self.script_tun,
|
||||||
os: Self::to_cstring(&os),
|
|
||||||
|
|
||||||
certificate: self.certificate.as_deref().map(Self::to_cstring),
|
certificate: self.certificate.as_deref().map(Self::to_cstring),
|
||||||
sslkey: self.sslkey.as_deref().map(Self::to_cstring),
|
sslkey: self.sslkey.as_deref().map(Self::to_cstring),
|
||||||
|
|||||||
+1
Submodule deps/openconnect added at 0dcdff87db.
+71
@@ -0,0 +1,71 @@
|
|||||||
|
diff --git a/gpst.c b/gpst.c
|
||||||
|
index 244aaf04..205bec1d 100644
|
||||||
|
--- a/gpst.c
|
||||||
|
+++ b/gpst.c
|
||||||
|
@@ -650,8 +650,11 @@ static int gpst_get_config(struct openconnect_info *vpninfo)
|
||||||
|
|
||||||
|
|
||||||
|
/* submit getconfig request */
|
||||||
|
+ char *app_version = vpninfo->csd_ticket ? : (vpninfo->gp_app_version ? : "6.3.0-33");
|
||||||
|
+ vpn_progress(vpninfo, PRG_DEBUG, _("Using GlobalProtect app version: %s\n"), app_version);
|
||||||
|
+
|
||||||
|
buf_append(request_body, "client-type=1&protocol-version=p1&internal=no");
|
||||||
|
- append_opt(request_body, "app-version", vpninfo->csd_ticket ? : "6.3.0-33");
|
||||||
|
+ append_opt(request_body, "app-version", app_version);
|
||||||
|
append_opt(request_body, "ipv6-support", vpninfo->disable_ipv6 ? "no" : "yes");
|
||||||
|
append_opt(request_body, "clientos", gpst_os_name(vpninfo));
|
||||||
|
append_opt(request_body, "os-version", vpninfo->platname);
|
||||||
|
diff --git a/library.c b/library.c
|
||||||
|
index b5e74e9b..fff28f77 100644
|
||||||
|
--- a/library.c
|
||||||
|
+++ b/library.c
|
||||||
|
@@ -896,6 +896,7 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)
|
||||||
|
|
||||||
|
free(vpninfo->localname);
|
||||||
|
free(vpninfo->useragent);
|
||||||
|
+ free(vpninfo->gp_app_version);
|
||||||
|
free(vpninfo->authgroup);
|
||||||
|
#ifdef HAVE_LIBSTOKEN
|
||||||
|
if (vpninfo->stoken_pin)
|
||||||
|
@@ -1019,6 +1020,15 @@ int openconnect_set_useragent(struct openconnect_info *vpninfo,
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
+int openconnect_set_gp_app_version(struct openconnect_info *vpninfo,
|
||||||
|
+ const char *gp_app_version)
|
||||||
|
+{
|
||||||
|
+ UTF8CHECK(gp_app_version);
|
||||||
|
+
|
||||||
|
+ STRDUP(vpninfo->gp_app_version, gp_app_version);
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
int openconnect_set_urlpath(struct openconnect_info *vpninfo,
|
||||||
|
const char *urlpath)
|
||||||
|
{
|
||||||
|
diff --git a/openconnect-internal.h b/openconnect-internal.h
|
||||||
|
index abf45bbd..85933f4a 100644
|
||||||
|
--- a/openconnect-internal.h
|
||||||
|
+++ b/openconnect-internal.h
|
||||||
|
@@ -786,6 +786,7 @@ struct openconnect_info {
|
||||||
|
int is_dyndns; /* Attempt to redo DNS lookup on each CSTP reconnect */
|
||||||
|
char *useragent;
|
||||||
|
char *version_string;
|
||||||
|
+ char *gp_app_version;
|
||||||
|
|
||||||
|
const char *quit_reason;
|
||||||
|
const char *delay_tunnel_reason; /* If non-null, provides a reason why protocol is not yet ready for tunnel setup */
|
||||||
|
diff --git a/openconnect.h b/openconnect.h
|
||||||
|
index 136f181a..67fc1283 100644
|
||||||
|
--- a/openconnect.h
|
||||||
|
+++ b/openconnect.h
|
||||||
|
@@ -470,6 +470,9 @@ int openconnect_set_http_proxy(struct openconnect_info *vpninfo,
|
||||||
|
int openconnect_set_useragent(struct openconnect_info *vpninfo,
|
||||||
|
const char *useragent);
|
||||||
|
|
||||||
|
+int openconnect_set_gp_app_version(struct openconnect_info *vpninfo,
|
||||||
|
+ const char *gp_app_version);
|
||||||
|
+
|
||||||
|
int openconnect_passphrase_from_fsid(struct openconnect_info *vpninfo);
|
||||||
|
int openconnect_obtain_cookie(struct openconnect_info *vpninfo);
|
||||||
|
int openconnect_init_ssl(void);
|
||||||
@@ -5,7 +5,6 @@ Maintainer: Kevin Yue <[email protected]>
|
|||||||
Standards-Version: 4.1.4
|
Standards-Version: 4.1.4
|
||||||
Build-Depends: debhelper (>= 9),
|
Build-Depends: debhelper (>= 9),
|
||||||
pkg-config,
|
pkg-config,
|
||||||
jq (>= 1),
|
|
||||||
make (>= 4),
|
make (>= 4),
|
||||||
libssl-dev,
|
libssl-dev,
|
||||||
libsecret-1-0,
|
libsecret-1-0,
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ pkgdesc="A GUI for GlobalProtect VPN, based on OpenConnect, supports the SSO aut
|
|||||||
arch=('x86_64' 'aarch64')
|
arch=('x86_64' 'aarch64')
|
||||||
url="https://github.com/yuezk/GlobalProtect-openconnect"
|
url="https://github.com/yuezk/GlobalProtect-openconnect"
|
||||||
license=('GPL3')
|
license=('GPL3')
|
||||||
makedepends=('make' 'pkg-config' 'rust' 'cargo' 'jq' 'webkit2gtk-4.1' 'curl' 'wget' 'file' 'openssl' 'appmenu-gtk-module' 'libappindicator-gtk3' 'librsvg' 'openconnect' 'libsecret')
|
makedepends=('make' 'pkg-config' 'rust' 'cargo' 'file')
|
||||||
depends=('openconnect>=8.20' webkit2gtk-4.1 libappindicator-gtk3 libsecret)
|
depends=('webkit2gtk-4.1' 'libappindicator-gtk3' 'librsvg' 'libsecret' 'openssl' 'appmenu-gtk-module'
|
||||||
|
'gnutls' 'libxml2' 'vpnc' 'lz4' 'libp11-kit' 'nettle' 'xdg-utils'
|
||||||
|
'openconnect>=8.20')
|
||||||
optdepends=('wmctrl: for window management')
|
optdepends=('wmctrl: for window management')
|
||||||
|
|
||||||
provides=('globalprotect-openconnect' 'gpclient' 'gpservice' 'gpauth' 'gpgui')
|
provides=('globalprotect-openconnect' 'gpclient' 'gpservice' 'gpauth' 'gpgui')
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ Source: @SOURCE@
|
|||||||
BuildRequires: make
|
BuildRequires: make
|
||||||
BuildRequires: rust
|
BuildRequires: rust
|
||||||
BuildRequires: cargo
|
BuildRequires: cargo
|
||||||
BuildRequires: jq
|
|
||||||
BuildRequires: pkg-config
|
BuildRequires: pkg-config
|
||||||
BuildRequires: openconnect-devel
|
BuildRequires: openconnect-devel
|
||||||
BuildRequires: (openssl-devel or libopenssl-devel)
|
BuildRequires: (openssl-devel or libopenssl-devel)
|
||||||
|
|||||||
Reference in new issue
Block a user