mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 14:36:15 -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
@@ -2,6 +2,7 @@ use crate::Vpn;
|
||||
use log::{debug, info, trace, warn};
|
||||
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)]
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct ConnectOptions {
|
||||
@@ -9,12 +10,15 @@ pub(crate) struct ConnectOptions {
|
||||
|
||||
pub server: *const c_char,
|
||||
pub cookie: *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 interface: *const c_char,
|
||||
pub script_tun: u32,
|
||||
pub os: *const c_char,
|
||||
|
||||
pub certificate: *const c_char,
|
||||
pub sslkey: *const c_char,
|
||||
pub key_password: *const c_char,
|
||||
|
||||
@@ -58,7 +58,6 @@ static void setup_tun_handler(void *_vpninfo)
|
||||
/* Initialize VPN connection */
|
||||
int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
||||
{
|
||||
INFO("openconnect version: %s", openconnect_get_version());
|
||||
struct openconnect_info *vpninfo;
|
||||
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("OS: %s", options->os);
|
||||
INFO("CLIENT_VERSION: %s", options->client_version);
|
||||
INFO("VPNC_SCRIPT: %s", options->script);
|
||||
INFO("SCRIPT_TUN: %d", g_script_tun);
|
||||
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);
|
||||
}
|
||||
|
||||
if (options->client_version) {
|
||||
openconnect_set_gp_app_version(vpninfo,
|
||||
options->client_version);
|
||||
}
|
||||
|
||||
if (options->certificate) {
|
||||
INFO("Setting client certificate: %s", 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 {
|
||||
void *user_data;
|
||||
|
||||
const char *server;
|
||||
const char *cookie;
|
||||
|
||||
const char *user_agent;
|
||||
const char *os;
|
||||
const char *client_version;
|
||||
|
||||
const char *script;
|
||||
const char *interface;
|
||||
const int script_tun;
|
||||
const char *os;
|
||||
|
||||
const char *certificate;
|
||||
const char *sslkey;
|
||||
const char *key_password;
|
||||
|
||||
@@ -14,11 +14,15 @@ type OnConnectedCallback = Arc<RwLock<Option<Box<dyn FnOnce() + 'static + Send +
|
||||
pub struct Vpn {
|
||||
server: CString,
|
||||
cookie: CString,
|
||||
|
||||
user_agent: CString,
|
||||
os: CString,
|
||||
client_version: Option<CString>,
|
||||
|
||||
script: CString,
|
||||
interface: Option<CString>,
|
||||
script_tun: bool,
|
||||
os: CString,
|
||||
|
||||
certificate: Option<CString>,
|
||||
sslkey: Option<CString>,
|
||||
key_password: Option<CString>,
|
||||
@@ -67,11 +71,14 @@ impl Vpn {
|
||||
|
||||
server: self.server.as_ptr(),
|
||||
cookie: self.cookie.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(),
|
||||
interface: Self::option_to_ptr(&self.interface),
|
||||
script_tun: self.script_tun as u32,
|
||||
os: self.os.as_ptr(),
|
||||
|
||||
certificate: Self::option_to_ptr(&self.certificate),
|
||||
sslkey: Self::option_to_ptr(&self.sslkey),
|
||||
@@ -125,6 +132,7 @@ pub struct VpnBuilder {
|
||||
|
||||
user_agent: Option<String>,
|
||||
os: Option<String>,
|
||||
client_version: Option<String>,
|
||||
|
||||
certificate: Option<String>,
|
||||
sslkey: Option<String>,
|
||||
@@ -153,6 +161,7 @@ impl VpnBuilder {
|
||||
|
||||
user_agent: None,
|
||||
os: None,
|
||||
client_version: None,
|
||||
|
||||
certificate: None,
|
||||
sslkey: None,
|
||||
@@ -195,6 +204,11 @@ impl VpnBuilder {
|
||||
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 {
|
||||
self.certificate = certificate.into();
|
||||
self
|
||||
@@ -287,11 +301,14 @@ impl VpnBuilder {
|
||||
Ok(Vpn {
|
||||
server: Self::to_cstring(&self.server),
|
||||
cookie: Self::to_cstring(&self.cookie),
|
||||
|
||||
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),
|
||||
interface: self.interface.as_deref().map(Self::to_cstring),
|
||||
script_tun: self.script_tun,
|
||||
os: Self::to_cstring(&os),
|
||||
|
||||
certificate: self.certificate.as_deref().map(Self::to_cstring),
|
||||
sslkey: self.sslkey.as_deref().map(Self::to_cstring),
|
||||
|
||||
Reference in new issue
Block a user