mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 22:46:14 -05:00
refactor: remove unused iOS OpenConnect integration
Remove the iOS native-library build adapter and unused packet-endpoint builder and Rust/C FFI path. Keep the desktop build in build.rs with explicit macOS, Linux, FreeBSD and OpenBSD support. Preserve desktop device and script-tunnel behavior, shared protocol profiles, certificate pin checks and the pinned native conformance reference.
This commit is contained in:
7 files changed
+255
-339
No files matched your search
+253
-8
@@ -1,12 +1,257 @@
|
|||||||
#[path = "build/desktop.rs"]
|
use std::{env, path::PathBuf};
|
||||||
mod desktop;
|
|
||||||
#[path = "build/ios.rs"]
|
fn build_libxml2(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||||
mod ios;
|
let libxml2_dir = deps_dir.join("libxml2");
|
||||||
|
let install_dir = out_dir.join("libxml2_install");
|
||||||
|
|
||||||
|
// The temporary location where we will build
|
||||||
|
let build_src = out_dir.join("libxml2_build");
|
||||||
|
|
||||||
|
// Track changes so cargo rebuilds if submodule changes
|
||||||
|
println!("cargo:rerun-if-changed={}", libxml2_dir.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();
|
||||||
|
}
|
||||||
|
if install_dir.exists() {
|
||||||
|
std::fs::remove_dir_all(&install_dir).unwrap();
|
||||||
|
}
|
||||||
|
std::fs::create_dir_all(&install_dir).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(&libxml2_dir, &build_src, &options).expect("Failed to copy C source code to OUT_DIR");
|
||||||
|
|
||||||
|
// Build the libxml2 library using autotools
|
||||||
|
let dst = {
|
||||||
|
let mut config = autotools::Config::new(&build_src);
|
||||||
|
config
|
||||||
|
.out_dir(&install_dir)
|
||||||
|
.reconf("-ivf")
|
||||||
|
.enable_static()
|
||||||
|
.disable_shared()
|
||||||
|
// Disable optional features that complicate static builds
|
||||||
|
.with("python", Some("no"))
|
||||||
|
.with("icu", Some("no"))
|
||||||
|
.with("http", Some("no"))
|
||||||
|
.with("ftp", Some("no"))
|
||||||
|
.with("catalog", Some("no"))
|
||||||
|
.with("docbook", Some("no"))
|
||||||
|
.with("legacy", Some("no"))
|
||||||
|
.with("threads", Some("no"))
|
||||||
|
.with("zlib", Some("no"))
|
||||||
|
.with("lzma", Some("no"))
|
||||||
|
// Ensure position-independent code (safe for static linking)
|
||||||
|
.cflag("-fPIC");
|
||||||
|
config.build()
|
||||||
|
};
|
||||||
|
|
||||||
|
let lib_dir = dst.join("lib");
|
||||||
|
let include_dir = dst.join("include/libxml2");
|
||||||
|
|
||||||
|
// Tell rustc where to find the static library
|
||||||
|
println!("cargo:rustc-link-search=native={}", lib_dir.display());
|
||||||
|
|
||||||
|
// Static linking of libxml2
|
||||||
|
println!("cargo:rustc-link-lib=static=xml2");
|
||||||
|
|
||||||
|
// Export include path for downstream use (bindgen / cc)
|
||||||
|
println!("cargo:include={}", include_dir.display());
|
||||||
|
|
||||||
|
dst
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||||
|
let openconnect_dir = deps_dir.join("openconnect");
|
||||||
|
let install_dir = out_dir.join("openconnect_install");
|
||||||
|
|
||||||
|
// The temporary location where we will build
|
||||||
|
let build_src = out_dir.join("openconnect_build");
|
||||||
|
|
||||||
|
// Track changes so cargo rebuilds if submodule changes
|
||||||
|
println!("cargo:rerun-if-changed={}", openconnect_dir.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();
|
||||||
|
}
|
||||||
|
if install_dir.exists() {
|
||||||
|
std::fs::remove_dir_all(&install_dir).unwrap();
|
||||||
|
}
|
||||||
|
std::fs::create_dir_all(&install_dir).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");
|
||||||
|
|
||||||
|
// Build the OpenConnect library using autotools. Keep the upstream LGPL
|
||||||
|
// library dynamically linked on macOS so it remains replaceable in the app
|
||||||
|
// bundle. Other platforms retain the existing static-link behavior.
|
||||||
|
let mut config = autotools::Config::new(&build_src);
|
||||||
|
config
|
||||||
|
.out_dir(&install_dir)
|
||||||
|
.reconf("-ivf")
|
||||||
|
.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
|
||||||
|
|
||||||
|
if target_os() == "macos" {
|
||||||
|
config
|
||||||
|
.disable_static()
|
||||||
|
.enable_shared()
|
||||||
|
.with("gnutls", None)
|
||||||
|
.without("openssl", None);
|
||||||
|
config.ldflag("-liconv");
|
||||||
|
config.env("LIBS", "-liconv");
|
||||||
|
}
|
||||||
|
|
||||||
|
if target_os() != "macos" {
|
||||||
|
config.enable_static().disable_shared();
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches!(target_os().as_str(), "freebsd" | "openbsd") {
|
||||||
|
config.ldflag("-L/usr/local/lib");
|
||||||
|
config.ldflag("-liconv");
|
||||||
|
config.env("LIBS", "-liconv");
|
||||||
|
}
|
||||||
|
|
||||||
|
let dst = config.build();
|
||||||
|
|
||||||
|
let lib_dir = dst.join("lib");
|
||||||
|
let include_dir = dst.join("include");
|
||||||
|
|
||||||
|
if target_os() == "macos" {
|
||||||
|
let configuration = std::fs::read_to_string(dst.join("build/config.h"))
|
||||||
|
.expect("Failed to read the OpenConnect TLS backend configuration");
|
||||||
|
assert!(
|
||||||
|
configuration.lines().any(|line| line == "#define OPENCONNECT_GNUTLS 1")
|
||||||
|
&& !configuration
|
||||||
|
.lines()
|
||||||
|
.any(|line| line == "#define OPENCONNECT_OPENSSL 1"),
|
||||||
|
"macOS OpenConnect must use GnuTLS"
|
||||||
|
);
|
||||||
|
// Do not embed Cargo's temporary build directory in consumers of this library.
|
||||||
|
let library = std::fs::canonicalize(lib_dir.join("libopenconnect.dylib")).unwrap();
|
||||||
|
let library_name = library.file_name().unwrap().to_str().unwrap();
|
||||||
|
let status = std::process::Command::new("install_name_tool")
|
||||||
|
.arg("-id")
|
||||||
|
.arg(format!("@rpath/{library_name}"))
|
||||||
|
.arg(&library)
|
||||||
|
.status()
|
||||||
|
.expect("Failed to update the OpenConnect dylib install name");
|
||||||
|
assert!(status.success(), "Failed to update the OpenConnect dylib install name");
|
||||||
|
let status = std::process::Command::new("codesign")
|
||||||
|
.args(["--force", "--sign", "-"])
|
||||||
|
.arg(&library)
|
||||||
|
.status()
|
||||||
|
.expect("Failed to sign the OpenConnect dylib");
|
||||||
|
assert!(status.success(), "Failed to sign the OpenConnect dylib");
|
||||||
|
println!("cargo:lib_dir={}", lib_dir.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("cargo:rustc-link-search=native={}", lib_dir.display());
|
||||||
|
|
||||||
|
if target_os() == "macos" {
|
||||||
|
println!("cargo:rustc-link-lib=dylib=openconnect");
|
||||||
|
}
|
||||||
|
|
||||||
|
if target_os() != "macos" {
|
||||||
|
println!("cargo:rustc-link-lib=static=openconnect");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export include path for downstream use (bindgen / cc)
|
||||||
|
println!("cargo:include={}", include_dir.display());
|
||||||
|
|
||||||
|
dst
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match std::env::var("CARGO_CFG_TARGET_OS").as_deref() {
|
let target = target_os();
|
||||||
Ok("ios") => ios::build(),
|
assert!(
|
||||||
Ok("macos" | "linux" | "freebsd" | "openbsd") => desktop::build(),
|
matches!(target.as_str(), "macos" | "linux" | "freebsd" | "openbsd"),
|
||||||
target => panic!("Unsupported OpenConnect target: {target:?}"),
|
"Unsupported OpenConnect target: {target}"
|
||||||
|
);
|
||||||
|
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
|
let deps_dir = PathBuf::from(manifest_dir).join("deps");
|
||||||
|
|
||||||
|
let oc_dst = build_openconnect(&deps_dir, &out_dir);
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-env=OPENCONNECT_PROTOCOL_BUILD={}",
|
||||||
|
oc_dst.join("build").display()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-env=OPENCONNECT_PROTOCOL_SOURCE={}",
|
||||||
|
out_dir.join("openconnect_build").display()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Only statically link libxml2 if `LIBXML2_STATIC` is set
|
||||||
|
if env::var("LIBXML2_STATIC").is_ok() {
|
||||||
|
let _libxml2_dst = build_libxml2(&deps_dir, &out_dir);
|
||||||
|
} else {
|
||||||
|
// Using pkg-config to find system libxml2
|
||||||
|
pkg_config::probe_library("libxml-2.0").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Using pkg-config to find system deps
|
||||||
|
pkg_config::probe_library("zlib").unwrap();
|
||||||
|
if target_os() == "macos" {
|
||||||
|
pkg_config::probe_library("gnutls").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if target_os() != "macos" {
|
||||||
|
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.h");
|
||||||
|
|
||||||
|
if matches!(target_os().as_str(), "freebsd" | "openbsd") {
|
||||||
|
println!("cargo:rustc-link-search=native=/usr/local/lib");
|
||||||
|
println!("cargo:rustc-link-lib=iconv");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent silent fallback to dynamic libraries
|
||||||
|
if target_os() == "linux" {
|
||||||
|
println!("cargo:rustc-link-arg=-Wl,-Bstatic");
|
||||||
|
println!("cargo:rustc-link-arg=-Wl,-Bdynamic");
|
||||||
|
}
|
||||||
|
|
||||||
|
cc::Build::new()
|
||||||
|
.file("src/ffi/vpn.c")
|
||||||
|
.include("src/ffi")
|
||||||
|
.include(&oc_dst.join("include"))
|
||||||
|
.compile("vpn");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn target_os() -> String {
|
||||||
|
env::var("CARGO_CFG_TARGET_OS").expect("Cargo target OS")
|
||||||
}
|
}
|
||||||
@@ -1,252 +0,0 @@
|
|||||||
use std::{env, path::PathBuf};
|
|
||||||
|
|
||||||
fn build_libxml2(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
|
||||||
let libxml2_dir = deps_dir.join("libxml2");
|
|
||||||
let install_dir = out_dir.join("libxml2_install");
|
|
||||||
|
|
||||||
// The temporary location where we will build
|
|
||||||
let build_src = out_dir.join("libxml2_build");
|
|
||||||
|
|
||||||
// Track changes so cargo rebuilds if submodule changes
|
|
||||||
println!("cargo:rerun-if-changed={}", libxml2_dir.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();
|
|
||||||
}
|
|
||||||
if install_dir.exists() {
|
|
||||||
std::fs::remove_dir_all(&install_dir).unwrap();
|
|
||||||
}
|
|
||||||
std::fs::create_dir_all(&install_dir).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(&libxml2_dir, &build_src, &options).expect("Failed to copy C source code to OUT_DIR");
|
|
||||||
|
|
||||||
// Build the libxml2 library using autotools
|
|
||||||
let dst = {
|
|
||||||
let mut config = autotools::Config::new(&build_src);
|
|
||||||
config
|
|
||||||
.out_dir(&install_dir)
|
|
||||||
.reconf("-ivf")
|
|
||||||
.enable_static()
|
|
||||||
.disable_shared()
|
|
||||||
// Disable optional features that complicate static builds
|
|
||||||
.with("python", Some("no"))
|
|
||||||
.with("icu", Some("no"))
|
|
||||||
.with("http", Some("no"))
|
|
||||||
.with("ftp", Some("no"))
|
|
||||||
.with("catalog", Some("no"))
|
|
||||||
.with("docbook", Some("no"))
|
|
||||||
.with("legacy", Some("no"))
|
|
||||||
.with("threads", Some("no"))
|
|
||||||
.with("zlib", Some("no"))
|
|
||||||
.with("lzma", Some("no"))
|
|
||||||
// Ensure position-independent code (safe for static linking)
|
|
||||||
.cflag("-fPIC");
|
|
||||||
config.build()
|
|
||||||
};
|
|
||||||
|
|
||||||
let lib_dir = dst.join("lib");
|
|
||||||
let include_dir = dst.join("include/libxml2");
|
|
||||||
|
|
||||||
// Tell rustc where to find the static library
|
|
||||||
println!("cargo:rustc-link-search=native={}", lib_dir.display());
|
|
||||||
|
|
||||||
// Static linking of libxml2
|
|
||||||
println!("cargo:rustc-link-lib=static=xml2");
|
|
||||||
|
|
||||||
// Export include path for downstream use (bindgen / cc)
|
|
||||||
println!("cargo:include={}", include_dir.display());
|
|
||||||
|
|
||||||
dst
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
|
||||||
let openconnect_dir = deps_dir.join("openconnect");
|
|
||||||
let install_dir = out_dir.join("openconnect_install");
|
|
||||||
|
|
||||||
// The temporary location where we will build
|
|
||||||
let build_src = out_dir.join("openconnect_build");
|
|
||||||
|
|
||||||
// Track changes so cargo rebuilds if submodule changes
|
|
||||||
println!("cargo:rerun-if-changed={}", openconnect_dir.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();
|
|
||||||
}
|
|
||||||
if install_dir.exists() {
|
|
||||||
std::fs::remove_dir_all(&install_dir).unwrap();
|
|
||||||
}
|
|
||||||
std::fs::create_dir_all(&install_dir).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");
|
|
||||||
|
|
||||||
// Build the OpenConnect library using autotools. Keep the upstream LGPL
|
|
||||||
// library dynamically linked on macOS so it remains replaceable in the app
|
|
||||||
// bundle. Other platforms retain the existing static-link behavior.
|
|
||||||
let mut config = autotools::Config::new(&build_src);
|
|
||||||
config
|
|
||||||
.out_dir(&install_dir)
|
|
||||||
.reconf("-ivf")
|
|
||||||
.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
|
|
||||||
|
|
||||||
if target_os() == "macos" {
|
|
||||||
config
|
|
||||||
.disable_static()
|
|
||||||
.enable_shared()
|
|
||||||
.with("gnutls", None)
|
|
||||||
.without("openssl", None);
|
|
||||||
config.ldflag("-liconv");
|
|
||||||
config.env("LIBS", "-liconv");
|
|
||||||
}
|
|
||||||
|
|
||||||
if target_os() != "macos" {
|
|
||||||
config.enable_static().disable_shared();
|
|
||||||
}
|
|
||||||
|
|
||||||
if matches!(target_os().as_str(), "freebsd" | "openbsd") {
|
|
||||||
config.ldflag("-L/usr/local/lib");
|
|
||||||
config.ldflag("-liconv");
|
|
||||||
config.env("LIBS", "-liconv");
|
|
||||||
}
|
|
||||||
|
|
||||||
let dst = config.build();
|
|
||||||
|
|
||||||
let lib_dir = dst.join("lib");
|
|
||||||
let include_dir = dst.join("include");
|
|
||||||
|
|
||||||
if target_os() == "macos" {
|
|
||||||
let configuration = std::fs::read_to_string(dst.join("build/config.h"))
|
|
||||||
.expect("Failed to read the OpenConnect TLS backend configuration");
|
|
||||||
assert!(
|
|
||||||
configuration.lines().any(|line| line == "#define OPENCONNECT_GNUTLS 1")
|
|
||||||
&& !configuration
|
|
||||||
.lines()
|
|
||||||
.any(|line| line == "#define OPENCONNECT_OPENSSL 1"),
|
|
||||||
"macOS OpenConnect must use GnuTLS"
|
|
||||||
);
|
|
||||||
// Do not embed Cargo's temporary build directory in consumers of this library.
|
|
||||||
let library = std::fs::canonicalize(lib_dir.join("libopenconnect.dylib")).unwrap();
|
|
||||||
let library_name = library.file_name().unwrap().to_str().unwrap();
|
|
||||||
let status = std::process::Command::new("install_name_tool")
|
|
||||||
.arg("-id")
|
|
||||||
.arg(format!("@rpath/{library_name}"))
|
|
||||||
.arg(&library)
|
|
||||||
.status()
|
|
||||||
.expect("Failed to update the OpenConnect dylib install name");
|
|
||||||
assert!(status.success(), "Failed to update the OpenConnect dylib install name");
|
|
||||||
let status = std::process::Command::new("codesign")
|
|
||||||
.args(["--force", "--sign", "-"])
|
|
||||||
.arg(&library)
|
|
||||||
.status()
|
|
||||||
.expect("Failed to sign the OpenConnect dylib");
|
|
||||||
assert!(status.success(), "Failed to sign the OpenConnect dylib");
|
|
||||||
println!("cargo:lib_dir={}", lib_dir.display());
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("cargo:rustc-link-search=native={}", lib_dir.display());
|
|
||||||
|
|
||||||
if target_os() == "macos" {
|
|
||||||
println!("cargo:rustc-link-lib=dylib=openconnect");
|
|
||||||
}
|
|
||||||
|
|
||||||
if target_os() != "macos" {
|
|
||||||
println!("cargo:rustc-link-lib=static=openconnect");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Export include path for downstream use (bindgen / cc)
|
|
||||||
println!("cargo:include={}", include_dir.display());
|
|
||||||
|
|
||||||
dst
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build() {
|
|
||||||
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
||||||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
|
||||||
let deps_dir = PathBuf::from(manifest_dir).join("deps");
|
|
||||||
|
|
||||||
let oc_dst = build_openconnect(&deps_dir, &out_dir);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=OPENCONNECT_PROTOCOL_BUILD={}",
|
|
||||||
oc_dst.join("build").display()
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=OPENCONNECT_PROTOCOL_SOURCE={}",
|
|
||||||
out_dir.join("openconnect_build").display()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Only statically link libxml2 if `LIBXML2_STATIC` is set
|
|
||||||
if env::var("LIBXML2_STATIC").is_ok() {
|
|
||||||
let _libxml2_dst = build_libxml2(&deps_dir, &out_dir);
|
|
||||||
} else {
|
|
||||||
// Using pkg-config to find system libxml2
|
|
||||||
pkg_config::probe_library("libxml-2.0").unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Using pkg-config to find system deps
|
|
||||||
pkg_config::probe_library("zlib").unwrap();
|
|
||||||
if target_os() == "macos" {
|
|
||||||
pkg_config::probe_library("gnutls").unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
if target_os() != "macos" {
|
|
||||||
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.h");
|
|
||||||
|
|
||||||
if matches!(target_os().as_str(), "freebsd" | "openbsd") {
|
|
||||||
println!("cargo:rustc-link-search=native=/usr/local/lib");
|
|
||||||
println!("cargo:rustc-link-lib=iconv");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prevent silent fallback to dynamic libraries
|
|
||||||
if target_os() == "linux" {
|
|
||||||
println!("cargo:rustc-link-arg=-Wl,-Bstatic");
|
|
||||||
println!("cargo:rustc-link-arg=-Wl,-Bdynamic");
|
|
||||||
}
|
|
||||||
|
|
||||||
cc::Build::new()
|
|
||||||
.file("src/ffi/vpn.c")
|
|
||||||
.include("src/ffi")
|
|
||||||
.include(&oc_dst.join("include"))
|
|
||||||
.compile("vpn");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn target_os() -> String {
|
|
||||||
env::var("CARGO_CFG_TARGET_OS").expect("Cargo target OS")
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
use std::{env, path::PathBuf};
|
|
||||||
|
|
||||||
pub fn build() {
|
|
||||||
println!("cargo:rerun-if-env-changed=GP_IOS_NATIVE_PREFIX");
|
|
||||||
let prefix = PathBuf::from(env::var_os("GP_IOS_NATIVE_PREFIX").expect(
|
|
||||||
"Set GP_IOS_NATIVE_PREFIX to target-built OpenConnect/GnuTLS libraries with an aarch64-apple-ios target.txt receipt",
|
|
||||||
));
|
|
||||||
let target = std::fs::read_to_string(prefix.join("target.txt")).expect("Missing iOS native target receipt");
|
|
||||||
assert_eq!(
|
|
||||||
target.trim(),
|
|
||||||
env::var("TARGET").unwrap(),
|
|
||||||
"Native library target mismatch"
|
|
||||||
);
|
|
||||||
for name in ["openconnect", "gnutls", "hogweed", "nettle", "gmp"] {
|
|
||||||
let archive = prefix.join(format!("lib/lib{name}.a"));
|
|
||||||
assert!(archive.is_file(), "Missing {}", archive.display());
|
|
||||||
println!("cargo:rerun-if-changed={}", archive.display());
|
|
||||||
}
|
|
||||||
println!("cargo:rerun-if-changed=src/ffi/vpn.c");
|
|
||||||
println!("cargo:rerun-if-changed=src/ffi/vpn.h");
|
|
||||||
cc::Build::new()
|
|
||||||
.file("src/ffi/vpn.c")
|
|
||||||
.include("src/ffi")
|
|
||||||
.include(prefix.join("include"))
|
|
||||||
.flag("-fapplication-extension")
|
|
||||||
.compile("vpn");
|
|
||||||
println!("cargo:rustc-link-search=native={}", prefix.join("lib").display());
|
|
||||||
for name in ["openconnect", "gnutls", "hogweed", "nettle", "gmp"] {
|
|
||||||
println!("cargo:rustc-link-lib=static={name}");
|
|
||||||
}
|
|
||||||
for name in ["xml2", "z", "iconv", "resolv"] {
|
|
||||||
println!("cargo:rustc-link-lib={name}");
|
|
||||||
}
|
|
||||||
println!("cargo:rustc-link-lib=framework=Security");
|
|
||||||
println!("cargo:rustc-link-lib=framework=CoreFoundation");
|
|
||||||
}
|
|
||||||
@@ -44,7 +44,6 @@ pub(crate) struct ConnectOptions {
|
|||||||
pub interface: *const c_char,
|
pub interface: *const c_char,
|
||||||
pub script_tun: u32,
|
pub script_tun: u32,
|
||||||
pub script_tun_launch: *const ScriptTunLaunchRaw,
|
pub script_tun_launch: *const ScriptTunLaunchRaw,
|
||||||
pub packet_fd: c_int,
|
|
||||||
|
|
||||||
pub certificate: *const c_char,
|
pub certificate: *const c_char,
|
||||||
pub sslkey: *const c_char,
|
pub sslkey: *const c_char,
|
||||||
|
|||||||
@@ -86,10 +86,7 @@ static void setup_tun_handler(void *private_data)
|
|||||||
struct openconnect_info *_vpninfo = context->vpninfo;
|
struct openconnect_info *_vpninfo = context->vpninfo;
|
||||||
const vpn_options *options = context->options;
|
const vpn_options *options = context->options;
|
||||||
int ret;
|
int ret;
|
||||||
if (options->packet_fd >= 0) {
|
if (options->script_tun) {
|
||||||
int fd = dup(options->packet_fd);
|
|
||||||
ret = fd < 0 ? -errno : openconnect_setup_tun_fd_with_config(_vpninfo, fd);
|
|
||||||
} else if (options->script_tun) {
|
|
||||||
const struct openconnect_script_tun_launch *launch = options->script_tun_launch;
|
const struct openconnect_script_tun_launch *launch = options->script_tun_launch;
|
||||||
if (launch) {
|
if (launch) {
|
||||||
ret = openconnect_setup_tun_script_exec(_vpninfo, launch);
|
ret = openconnect_setup_tun_script_exec(_vpninfo, launch);
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ typedef struct vpn_options {
|
|||||||
const char *interface;
|
const char *interface;
|
||||||
const int script_tun;
|
const int script_tun;
|
||||||
const struct openconnect_script_tun_launch *script_tun_launch;
|
const struct openconnect_script_tun_launch *script_tun_launch;
|
||||||
const int packet_fd;
|
|
||||||
|
|
||||||
const char *certificate;
|
const char *certificate;
|
||||||
const char *sslkey;
|
const char *sslkey;
|
||||||
|
|||||||
@@ -151,7 +151,6 @@ pub struct Vpn {
|
|||||||
interface: Option<CString>,
|
interface: Option<CString>,
|
||||||
script_tun: bool,
|
script_tun: bool,
|
||||||
script_tun_launch: Option<ScriptTunLaunch>,
|
script_tun_launch: Option<ScriptTunLaunch>,
|
||||||
packet_endpoint: Option<OwnedFd>,
|
|
||||||
|
|
||||||
certificate: Option<CString>,
|
certificate: Option<CString>,
|
||||||
sslkey: Option<CString>,
|
sslkey: Option<CString>,
|
||||||
@@ -315,7 +314,6 @@ impl Vpn {
|
|||||||
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,
|
||||||
script_tun_launch: std::ptr::null(),
|
script_tun_launch: std::ptr::null(),
|
||||||
packet_fd: self.packet_endpoint.as_ref().map_or(-1, AsRawFd::as_raw_fd),
|
|
||||||
|
|
||||||
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),
|
||||||
@@ -384,7 +382,6 @@ pub struct VpnBuilder {
|
|||||||
interface: Option<String>,
|
interface: Option<String>,
|
||||||
script_tun: bool,
|
script_tun: bool,
|
||||||
script_tun_launch: Option<ScriptTunLaunch>,
|
script_tun_launch: Option<ScriptTunLaunch>,
|
||||||
packet_endpoint: Option<OwnedFd>,
|
|
||||||
|
|
||||||
user_agent: Option<String>,
|
user_agent: Option<String>,
|
||||||
os: Option<String>,
|
os: Option<String>,
|
||||||
@@ -396,7 +393,6 @@ pub struct VpnBuilder {
|
|||||||
certificate: Option<String>,
|
certificate: Option<String>,
|
||||||
sslkey: Option<String>,
|
sslkey: Option<String>,
|
||||||
key_password: Option<String>,
|
key_password: Option<String>,
|
||||||
servercert: Option<String>,
|
|
||||||
|
|
||||||
hip_source: Arc<HipSource>,
|
hip_source: Arc<HipSource>,
|
||||||
|
|
||||||
@@ -421,7 +417,6 @@ impl VpnBuilder {
|
|||||||
interface: None,
|
interface: None,
|
||||||
script_tun: false,
|
script_tun: false,
|
||||||
script_tun_launch: None,
|
script_tun_launch: None,
|
||||||
packet_endpoint: None,
|
|
||||||
|
|
||||||
user_agent: None,
|
user_agent: None,
|
||||||
os: None,
|
os: None,
|
||||||
@@ -433,7 +428,6 @@ impl VpnBuilder {
|
|||||||
certificate: None,
|
certificate: None,
|
||||||
sslkey: None,
|
sslkey: None,
|
||||||
key_password: None,
|
key_password: None,
|
||||||
servercert: None,
|
|
||||||
|
|
||||||
hip_source: Arc::new(HipSource::Disabled),
|
hip_source: Arc::new(HipSource::Disabled),
|
||||||
|
|
||||||
@@ -447,16 +441,6 @@ impl VpnBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use an application-owned packet descriptor. OpenConnect borrows a duplicate
|
|
||||||
/// during connect; this owner remains alive until the Vpn is dropped. Apple/BSD
|
|
||||||
/// endpoints use the native four-byte, network-order address-family prefix.
|
|
||||||
/// Requires callback configuration and a SHA-256 server public-key pin.
|
|
||||||
pub fn packet_endpoint(mut self, endpoint: OwnedFd, server_pin: String) -> Self {
|
|
||||||
self.packet_endpoint = Some(endpoint);
|
|
||||||
self.servercert = Some(server_pin);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn script<T: Into<Option<String>>>(mut self, script: T) -> Self {
|
pub fn script<T: Into<Option<String>>>(mut self, script: T) -> Self {
|
||||||
self.script = script.into();
|
self.script = script.into();
|
||||||
self.script_is_path = false;
|
self.script_is_path = false;
|
||||||
@@ -634,24 +618,6 @@ impl VpnBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(self) -> Result<Vpn, VpnError> {
|
pub fn build(self) -> Result<Vpn, VpnError> {
|
||||||
if self.packet_endpoint.is_some() {
|
|
||||||
let pin = self.servercert.as_deref().unwrap_or_default();
|
|
||||||
if self.network_configuration_handler.is_none()
|
|
||||||
|| self.interface.is_some()
|
|
||||||
|| self.script.is_some()
|
|
||||||
|| self.script_tun
|
|
||||||
|| self.script_tun_launch.is_some()
|
|
||||||
{
|
|
||||||
return Err(VpnError::new(
|
|
||||||
"Packet endpoint requires callback configuration and no device/script options".into(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if !pin.starts_with("pin-sha256:") || pin.len() != 55 || pin.contains('\0') {
|
|
||||||
return Err(VpnError::new(
|
|
||||||
"Packet endpoint requires a pin-sha256 server public-key fingerprint".into(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if self.script_tun_launch.is_some() && !self.script_tun {
|
if self.script_tun_launch.is_some() && !self.script_tun {
|
||||||
return Err(VpnError::new("Child identity requires script-tun".into()));
|
return Err(VpnError::new("Child identity requires script-tun".into()));
|
||||||
}
|
}
|
||||||
@@ -677,12 +643,11 @@ impl VpnBuilder {
|
|||||||
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,
|
||||||
script_tun_launch: self.script_tun_launch,
|
script_tun_launch: self.script_tun_launch,
|
||||||
packet_endpoint: self.packet_endpoint,
|
|
||||||
|
|
||||||
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),
|
||||||
key_password: self.key_password.as_deref().map(Self::to_cstring),
|
key_password: self.key_password.as_deref().map(Self::to_cstring),
|
||||||
servercert: self.servercert.as_deref().map(Self::to_cstring),
|
servercert: None,
|
||||||
|
|
||||||
hip_source: self.hip_source,
|
hip_source: self.hip_source,
|
||||||
|
|
||||||
@@ -810,7 +775,6 @@ mod tests {
|
|||||||
interface: None,
|
interface: None,
|
||||||
script_tun: false,
|
script_tun: false,
|
||||||
script_tun_launch: None,
|
script_tun_launch: None,
|
||||||
packet_endpoint: None,
|
|
||||||
certificate: None,
|
certificate: None,
|
||||||
sslkey: None,
|
sslkey: None,
|
||||||
key_password: None,
|
key_password: None,
|
||||||
|
|||||||
Reference in new issue
Block a user