mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-23 07:46:13 -05:00
feat: add hip parameter to ConnectArgs and VpnBuilder, update connection logic
This commit is contained in:
4 files changed
+52
-14
No files matched your search
@@ -312,12 +312,12 @@ impl<'a> ConnectHandler<'a> {
|
|||||||
async fn connect_gateway(&self, gateway: &str, cookie: &str) -> anyhow::Result<()> {
|
async fn connect_gateway(&self, gateway: &str, cookie: &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 csd_wrapper = if self.args.csd_wrapper.is_some() {
|
let (hip, csd_wrapper) = if let Some(csd_wrapper) = &self.args.csd_wrapper {
|
||||||
self.args.csd_wrapper.clone()
|
(true, Some(csd_wrapper.clone()))
|
||||||
} else if self.args.hip {
|
} else if self.args.hip {
|
||||||
find_csd_wrapper()
|
(true, None)
|
||||||
} else {
|
} else {
|
||||||
None
|
(false, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
let os = ClientOs::from(&self.args.os).to_openconnect_os().to_string();
|
let os = ClientOs::from(&self.args.os).to_openconnect_os().to_string();
|
||||||
@@ -329,6 +329,7 @@ impl<'a> ConnectHandler<'a> {
|
|||||||
.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())
|
||||||
|
.hip(hip)
|
||||||
.csd_uid(csd_uid)
|
.csd_uid(csd_uid)
|
||||||
.csd_wrapper(csd_wrapper)
|
.csd_wrapper(csd_wrapper)
|
||||||
.reconnect_timeout(self.args.reconnect_timeout)
|
.reconnect_timeout(self.args.reconnect_timeout)
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ impl VpnTaskContext {
|
|||||||
.certificate(args.certificate())
|
.certificate(args.certificate())
|
||||||
.sslkey(args.sslkey())
|
.sslkey(args.sslkey())
|
||||||
.key_password(args.key_password())
|
.key_password(args.key_password())
|
||||||
|
.hip(args.hip())
|
||||||
.csd_uid(args.csd_uid())
|
.csd_uid(args.csd_uid())
|
||||||
.csd_wrapper(args.csd_wrapper())
|
.csd_wrapper(args.csd_wrapper())
|
||||||
.reconnect_timeout(args.reconnect_timeout())
|
.reconnect_timeout(args.reconnect_timeout())
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ pub struct ConnectArgs {
|
|||||||
certificate: Option<String>,
|
certificate: Option<String>,
|
||||||
sslkey: Option<String>,
|
sslkey: Option<String>,
|
||||||
key_password: Option<String>,
|
key_password: Option<String>,
|
||||||
|
hip: bool,
|
||||||
csd_uid: u32,
|
csd_uid: u32,
|
||||||
csd_wrapper: Option<String>,
|
csd_wrapper: Option<String>,
|
||||||
reconnect_timeout: u32,
|
reconnect_timeout: u32,
|
||||||
@@ -54,6 +55,7 @@ impl ConnectArgs {
|
|||||||
certificate: None,
|
certificate: None,
|
||||||
sslkey: None,
|
sslkey: None,
|
||||||
key_password: None,
|
key_password: None,
|
||||||
|
hip: false,
|
||||||
csd_uid: 0,
|
csd_uid: 0,
|
||||||
csd_wrapper: None,
|
csd_wrapper: None,
|
||||||
reconnect_timeout: 300,
|
reconnect_timeout: 300,
|
||||||
@@ -91,6 +93,10 @@ impl ConnectArgs {
|
|||||||
self.key_password.clone()
|
self.key_password.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hip(&self) -> bool {
|
||||||
|
self.hip
|
||||||
|
}
|
||||||
|
|
||||||
pub fn csd_uid(&self) -> u32 {
|
pub fn csd_uid(&self) -> u32 {
|
||||||
self.csd_uid
|
self.csd_uid
|
||||||
}
|
}
|
||||||
@@ -135,6 +141,11 @@ impl ConnectRequest {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_hip(mut self, hip: bool) -> Self {
|
||||||
|
self.args.hip = hip;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_csd_uid(mut self, csd_uid: u32) -> Self {
|
pub fn with_csd_uid(mut self, csd_uid: u32) -> Self {
|
||||||
self.args.csd_uid = csd_uid;
|
self.args.csd_uid = csd_uid;
|
||||||
self
|
self
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ pub struct VpnBuilder {
|
|||||||
sslkey: Option<String>,
|
sslkey: Option<String>,
|
||||||
key_password: Option<String>,
|
key_password: Option<String>,
|
||||||
|
|
||||||
|
hip: bool,
|
||||||
csd_uid: u32,
|
csd_uid: u32,
|
||||||
csd_wrapper: Option<String>,
|
csd_wrapper: Option<String>,
|
||||||
|
|
||||||
@@ -153,6 +154,7 @@ impl VpnBuilder {
|
|||||||
sslkey: None,
|
sslkey: None,
|
||||||
key_password: None,
|
key_password: None,
|
||||||
|
|
||||||
|
hip: false,
|
||||||
csd_uid: 0,
|
csd_uid: 0,
|
||||||
csd_wrapper: None,
|
csd_wrapper: None,
|
||||||
|
|
||||||
@@ -199,6 +201,11 @@ impl VpnBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hip(mut self, hip: bool) -> Self {
|
||||||
|
self.hip = hip;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn csd_uid(mut self, csd_uid: u32) -> Self {
|
pub fn csd_uid(mut self, csd_uid: u32) -> Self {
|
||||||
self.csd_uid = csd_uid;
|
self.csd_uid = csd_uid;
|
||||||
self
|
self
|
||||||
@@ -234,18 +241,36 @@ impl VpnBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(self) -> Result<Vpn, VpnError> {
|
fn determine_script(&self) -> Result<String, VpnError> {
|
||||||
let script = match self.script {
|
match &self.script {
|
||||||
Some(script) => {
|
Some(script) => {
|
||||||
check_executable(&script).map_err(|e| VpnError::new(e.to_string()))?;
|
check_executable(script).map_err(|e| VpnError::new(e.to_string()))?;
|
||||||
script
|
Ok(script.clone())
|
||||||
}
|
}
|
||||||
None => find_vpnc_script().ok_or_else(|| VpnError::new(String::from("Failed to find vpnc-script")))?,
|
None => find_vpnc_script().ok_or_else(|| VpnError::new(String::from("Failed to find vpnc-script"))),
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(csd_wrapper) = &self.csd_wrapper {
|
|
||||||
check_executable(csd_wrapper).map_err(|e| VpnError::new(e.to_string()))?;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn determine_csd_wrapper(&self) -> Result<Option<String>, VpnError> {
|
||||||
|
if !self.hip {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
match &self.csd_wrapper {
|
||||||
|
Some(csd_wrapper) if !csd_wrapper.is_empty() => {
|
||||||
|
check_executable(csd_wrapper).map_err(|e| VpnError::new(e.to_string()))?;
|
||||||
|
Ok(Some(csd_wrapper.clone()))
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
let s = find_csd_wrapper().ok_or_else(|| VpnError::new(String::from("Failed to find csd wrapper")))?;
|
||||||
|
Ok(Some(s))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build(self) -> Result<Vpn, VpnError> {
|
||||||
|
let script = self.determine_script()?;
|
||||||
|
let csd_wrapper = self.determine_csd_wrapper()?;
|
||||||
|
|
||||||
let user_agent = self.user_agent.unwrap_or_default();
|
let user_agent = self.user_agent.unwrap_or_default();
|
||||||
let os = self.os.unwrap_or("linux".to_string());
|
let os = self.os.unwrap_or("linux".to_string());
|
||||||
@@ -264,7 +289,7 @@ impl VpnBuilder {
|
|||||||
servercert: None,
|
servercert: None,
|
||||||
|
|
||||||
csd_uid: self.csd_uid,
|
csd_uid: self.csd_uid,
|
||||||
csd_wrapper: self.csd_wrapper.as_deref().map(Self::to_cstring),
|
csd_wrapper: csd_wrapper.as_deref().map(Self::to_cstring),
|
||||||
|
|
||||||
reconnect_timeout: self.reconnect_timeout,
|
reconnect_timeout: self.reconnect_timeout,
|
||||||
mtu: self.mtu,
|
mtu: self.mtu,
|
||||||
|
|||||||
Reference in new issue
Block a user