feat: release GP Connect 3.3.0 with Native Shell support

This commit is contained in:
Kevin Yue committed 2026-11-05 23:05:14 +08:00
1 parent d12d677208
commit fd08cdbe66
226 files changed
+7700 -5225

No files matched your search

+1
View File
@@ -2,6 +2,7 @@
name = "openconnect"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license = "MIT"
links = "openconnect"
+34 -26
View File
@@ -112,25 +112,22 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
.without("libpcsclite", None)
.without("libpskc", None)
.without("gssapi", None)
.with("gnutls", None)
.without("openssl", None)
.with("gnutls-tss2", Some("no"))
.with("vpnc-script", Some("/etc/vpnc/vpnc-script")); // Specify vpnc-script, otherwise it will fail on macOS
#[cfg(target_os = "macos")]
{
config
.disable_static()
.enable_shared()
.with("gnutls", None)
.without("openssl", None);
if target_os() == "macos" {
config.disable_static().enable_shared();
config.ldflag("-liconv");
config.env("LIBS", "-liconv");
}
#[cfg(not(target_os = "macos"))]
config.enable_static().disable_shared();
if target_os() != "macos" {
config.enable_static().disable_shared();
}
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
{
if matches!(target_os().as_str(), "freebsd" | "openbsd") {
config.ldflag("-L/usr/local/lib");
config.ldflag("-liconv");
config.env("LIBS", "-liconv");
@@ -141,7 +138,6 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
let lib_dir = dst.join("lib");
let include_dir = dst.join("include");
#[cfg(target_os = "macos")]
{
let configuration = std::fs::read_to_string(dst.join("build/config.h"))
.expect("Failed to read the OpenConnect TLS backend configuration");
@@ -150,8 +146,11 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
&& !configuration
.lines()
.any(|line| line == "#define OPENCONNECT_OPENSSL 1"),
"macOS OpenConnect must use GnuTLS"
"OpenConnect must use GnuTLS"
);
}
if target_os() == "macos" {
// 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();
@@ -173,11 +172,13 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
println!("cargo:rustc-link-search=native={}", lib_dir.display());
#[cfg(target_os = "macos")]
println!("cargo:rustc-link-lib=dylib=openconnect");
if target_os() == "macos" {
println!("cargo:rustc-link-lib=dylib=openconnect");
}
#[cfg(not(target_os = "macos"))]
println!("cargo:rustc-link-lib=static=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());
@@ -186,6 +187,11 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
}
fn main() {
let target = target_os();
assert!(
matches!(target.as_str(), "macos" | "linux" | "freebsd" | "openbsd"),
"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");
@@ -210,15 +216,15 @@ fn main() {
// Using pkg-config to find system deps
pkg_config::probe_library("zlib").unwrap();
#[cfg(target_os = "macos")]
pkg_config::probe_library("gnutls").unwrap();
if target_os() == "macos" {
pkg_config::probe_library("gnutls").unwrap();
}
#[cfg(not(target_os = "macos"))]
{
if target_os() != "macos" {
pkg_config::probe_library("liblz4").unwrap();
pkg_config::probe_library("gnutls").unwrap();
// Below are required by gnutls
// OpenConnect also uses Hogweed/GMP directly for its GnuTLS backend.
pkg_config::probe_library("p11-kit-1").unwrap();
pkg_config::probe_library("hogweed").unwrap();
pkg_config::probe_library("nettle").unwrap();
@@ -229,15 +235,13 @@ fn main() {
println!("cargo:rerun-if-changed=src/ffi/vpn.c");
println!("cargo:rerun-if-changed=src/ffi/vpn.h");
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
{
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
#[cfg(target_os = "linux")]
{
if target_os() == "linux" {
println!("cargo:rustc-link-arg=-Wl,-Bstatic");
println!("cargo:rustc-link-arg=-Wl,-Bdynamic");
}
@@ -248,3 +252,7 @@ fn main() {
.include(&oc_dst.join("include"))
.compile("vpn");
}
fn target_os() -> String {
env::var("CARGO_CFG_TARGET_OS").expect("Cargo target OS")
}
+8 -1
View File
@@ -52,9 +52,13 @@ static void observe_statistics(void *private_data, const struct oc_stats *stats)
}
/* Validate the peer certificate */
static int validate_peer_cert(__attribute__((unused)) void *_vpninfo,
static int validate_peer_cert(void *private_data,
const char *reason)
{
struct vpn_context *context = private_data;
if (context->options->servercert)
return openconnect_check_peer_cert_hash(context->vpninfo,
context->options->servercert);
INFO("Accepting the server certificate though %s", reason);
return 0;
}
@@ -156,6 +160,9 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
}
context.vpninfo = vpninfo;
/* A supplied pin is authoritative even when the system would trust a CA. */
if (options->servercert)
openconnect_set_system_trust(vpninfo, 0);
openconnect_set_tunnel_handler(vpninfo, observe_tunnel);
openconnect_set_reconnected_handler(vpninfo, observe_reconnected);
openconnect_set_stats_handler(vpninfo, observe_statistics);
+53
View File
@@ -75,6 +75,58 @@ int inspect_esp_packet(struct openconnect_info *vpninfo, struct pkt *pkt, uint8_
return 1;
}
/* Check the real request builder without a VPN server. Desktop payloads stay exact. */
static void getconfig_profile_parameters(void)
{
const char *platforms[] = { "linux", "mac-intel", "win", "apple-ios" };
const char *names[] = { "Linux", "Mac", "Windows", "iOS" };
int i;
for (i = 0; i < 4; i++) {
struct openconnect_info *vpninfo = openconnect_vpninfo_new("test", NULL, NULL, NULL, NULL, NULL);
struct oc_text_buf *body = buf_alloc();
char expected[2048];
assert(vpninfo && body);
assert(!openconnect_set_reported_os(vpninfo, platforms[i]));
assert(!openconnect_set_gp_app_version(vpninfo, "6.3.5-28"));
assert(!openconnect_set_gp_os_version(vpninfo, "test-os"));
assert(!openconnect_set_gp_host_id(vpninfo, "HOSTID"));
assert(!openconnect_set_cookie(vpninfo, "user=test&portal=portal&authcookie=fixture&computer=Phone&preferred-ip=192.0.2.5"));
assert(!gpst_build_getconfig_request(vpninfo, body));
if (i == 3) {
assert(strstr(body->data, "clientos=iOS"));
assert(strstr(body->data, "vpn-type=App%20Level%20VPN"));
assert(strstr(body->data, "client-ip=&client-ipv6=&serialno=&joined-domain="));
assert(strstr(body->data, "user=test") && strstr(body->data, "authcookie=fixture"));
assert(strstr(body->data, "preferred-ip=192.0.2.5"));
assert(!strstr(body->data, "host-id=") && !strstr(body->data, "clientgpversion=") && !strstr(body->data, "computer="));
buf_truncate(body);
vpninfo->ip_info.addr = strdup("192.0.2.6");
assert(!gpst_build_getconfig_request(vpninfo, body));
assert(strstr(body->data, "preferred-ip=192.0.2.6"));
assert(!strstr(body->data, "192.0.2.5"));
/* The connected HTTPS socket supplies the actual local client address. */
int fd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in local = { .sin_family = AF_INET, .sin_addr.s_addr = htonl(INADDR_LOOPBACK) };
assert(fd >= 0 && !bind(fd, (struct sockaddr *)&local, sizeof(local)));
vpninfo->ssl_fd = fd;
buf_truncate(body);
assert(!gpst_build_getconfig_request(vpninfo, body));
assert(strstr(body->data, "client-ip=127.0.0.1&client-ipv6="));
vpninfo->ssl_fd = -1;
close(fd);
} else {
snprintf(expected, sizeof(expected),
"client-type=1&protocol-version=p1&internal=no&app-version=6.3.5-28&ipv6-support=yes"
"&clientos=%s&os-version=test-os&hmac-algo=sha1%%2c&enc-algo=aes-256-gcm%%2caes-128-gcm%%2caes-128-cbc%%2c"
"&clientgpversion=6.3.5-28&host-id=HOSTID&user=test&portal=portal&authcookie=fixture&computer=Phone&preferred-ip=192.0.2.5",
names[i]);
assert(!strcmp(body->data, expected));
}
buf_free(body);
openconnect_vpninfo_free(vpninfo);
}
}
int main(int argc, char **argv)
{
static const char key[] =
@@ -92,6 +144,7 @@ int main(int argc, char **argv)
int sockets[2], nlb, invalid, length;
assert(argc == 2);
getconfig_profile_parameters();
nlb = !strncmp(argv[1], "nlb-", 4);
invalid = !strcmp(argv[1], "regular-invalid") || !strcmp(argv[1], "regular-missing");
if (!strcmp(argv[1], "regular-address") || !strcmp(argv[1], "nlb-address"))
@@ -160,6 +160,59 @@ static void reconnect_refusal_propagates(void)
openconnect_vpninfo_free(vpninfo);
}
static void external_packets_and_configuration(void)
{
struct state state = { .parent = getpid(), .reason = "connect" };
struct openconnect_info *vpninfo = new_vpn(&state);
int fds[2], families[] = { AF_INET, AF_INET6 };
int creations = device_creations;
assert(!socketpair(AF_UNIX, SOCK_DGRAM, 0, fds));
assert(!openconnect_setup_tun_fd_with_config(vpninfo, fds[0]));
assert(device_creations == creations);
assert(state.calls == 1);
for (int i = 0; i < 2; i++) {
unsigned char frame[1504] = {0}, received[1504];
struct pkt *packet = alloc_pkt(vpninfo, 1500);
int prefix = 0, length = i ? 40 : 20;
#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__)
uint32_t family = htonl(families[i]);
memcpy(frame, &family, 4);
prefix = 4;
#endif
frame[prefix] = i ? 0x60 : 0x45;
assert(write(fds[1], frame, length + prefix) == length + prefix);
packet->len = 1500;
assert(!os_read_tun(vpninfo, packet));
assert(packet->len == length);
assert(!memcmp(packet->data, frame + prefix, length));
assert(!os_write_tun(vpninfo, packet));
assert(read(fds[1], received, sizeof(received)) == length + prefix);
assert(!memcmp(received, frame, length + prefix));
free_pkt(vpninfo, packet);
}
state.reason = "disconnect";
openconnect_vpninfo_free(vpninfo);
assert(state.calls == 2);
assert(fcntl(fds[0], F_GETFD) == -1 && errno == EBADF);
close(fds[1]);
state.calls = 0;
state.reason = "connect";
state.failure_reason = "connect";
state.result = -EPERM;
const char *reasons[] = { "connect", "disconnect" };
state.expected_reasons = reasons;
state.expected_count = 2;
vpninfo = new_vpn(&state);
assert(!socketpair(AF_UNIX, SOCK_DGRAM, 0, fds));
assert(openconnect_setup_tun_fd_with_config(vpninfo, fds[0]) == -EPERM);
assert(vpninfo->tun_fd == -1);
assert(fcntl(fds[0], F_GETFD) == -1 && errno == EBADF);
openconnect_vpninfo_free(vpninfo);
assert(state.calls == 2);
close(fds[1]);
}
int main(void)
{
const char *reasons[] = { "pre-init", "connect", "attempt-reconnect", "reconnect", "disconnect" };
@@ -199,5 +252,6 @@ int main(void)
openconnect_vpninfo_free(vpninfo);
connect_failure_rolls_back();
reconnect_refusal_propagates();
external_packets_and_configuration();
return 0;
}