mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 06:26:14 -05:00
feat(hip): manage reports and script execution
This commit is contained in:
54 files changed
+3122
-967
No files matched your search
@@ -1,96 +0,0 @@
|
||||
use std::process::Stdio;
|
||||
|
||||
use anyhow::bail;
|
||||
use tokio::process::Command;
|
||||
|
||||
pub struct HipLauncher<'a> {
|
||||
program: &'a str,
|
||||
cookie: Option<&'a str>,
|
||||
client_ip: Option<&'a str>,
|
||||
md5: Option<&'a str>,
|
||||
client_os: Option<&'a str>,
|
||||
client_version: Option<&'a str>,
|
||||
}
|
||||
|
||||
impl<'a> HipLauncher<'a> {
|
||||
pub fn new(program: &'a str) -> Self {
|
||||
Self {
|
||||
program,
|
||||
cookie: None,
|
||||
client_ip: None,
|
||||
md5: None,
|
||||
client_os: None,
|
||||
client_version: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cookie(mut self, cookie: &'a str) -> Self {
|
||||
self.cookie = Some(cookie);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn client_ip(mut self, client_ip: &'a str) -> Self {
|
||||
self.client_ip = Some(client_ip);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn md5(mut self, md5: &'a str) -> Self {
|
||||
self.md5 = Some(md5);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn client_os(mut self, client_os: &'a str) -> Self {
|
||||
self.client_os = Some(client_os);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn client_version(mut self, client_version: Option<&'a str>) -> Self {
|
||||
self.client_version = client_version;
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn launch(&self) -> anyhow::Result<String> {
|
||||
let mut cmd = Command::new(self.program);
|
||||
|
||||
if let Some(cookie) = self.cookie {
|
||||
cmd.arg("--cookie").arg(cookie);
|
||||
}
|
||||
|
||||
if let Some(client_ip) = self.client_ip {
|
||||
cmd.arg("--client-ip").arg(client_ip);
|
||||
}
|
||||
|
||||
if let Some(md5) = self.md5 {
|
||||
cmd.arg("--md5").arg(md5);
|
||||
}
|
||||
|
||||
if let Some(client_os) = self.client_os {
|
||||
cmd.arg("--client-os").arg(client_os);
|
||||
}
|
||||
|
||||
if let Some(client_version) = self.client_version {
|
||||
cmd.env("APP_VERSION", client_version);
|
||||
}
|
||||
|
||||
let child = cmd.kill_on_drop(true).stdout(Stdio::piped()).spawn();
|
||||
|
||||
let child = match child {
|
||||
Ok(child) => child,
|
||||
Err(err) => bail!("Failed to spawn {}: {}", self.program, err),
|
||||
};
|
||||
|
||||
let output = child.wait_with_output().await?;
|
||||
|
||||
if let Some(exit_status) = output.status.code() {
|
||||
if exit_status != 0 {
|
||||
bail!("HIP report generation failed with exit code {}", exit_status);
|
||||
}
|
||||
|
||||
let report = String::from_utf8(output.stdout)?;
|
||||
|
||||
Ok(report)
|
||||
} else {
|
||||
bail!("HIP report generation failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,5 @@ pub use command_traits::CommandExt;
|
||||
|
||||
pub mod auth_launcher;
|
||||
pub mod gui_launcher;
|
||||
pub mod hip_launcher;
|
||||
pub mod service_launcher;
|
||||
pub mod users;
|
||||
@@ -0,0 +1,47 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
|
||||
/// The GUI's choice of HIP report source. gpservice resolves execution details.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, Type, PartialEq, Eq)]
|
||||
#[serde(tag = "source", rename_all = "camelCase", rename_all_fields = "camelCase")]
|
||||
pub enum HipSource {
|
||||
#[default]
|
||||
Disabled,
|
||||
Generated,
|
||||
Edited {
|
||||
report_id: String,
|
||||
},
|
||||
UserScript {
|
||||
path: String,
|
||||
},
|
||||
ApprovedRootScript {
|
||||
approval_id: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Type, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum HipApprovalStatus {
|
||||
Valid,
|
||||
Revoked,
|
||||
Corrupt,
|
||||
OtherUser,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn source_round_trips_without_execution_uid_or_wrapper() {
|
||||
let source = HipSource::ApprovedRootScript {
|
||||
approval_id: "approved-1".into(),
|
||||
};
|
||||
let json = serde_json::to_value(&source).unwrap();
|
||||
assert_eq!(
|
||||
json,
|
||||
serde_json::json!({ "source": "approvedRootScript", "approvalId": "approved-1" })
|
||||
);
|
||||
assert_eq!(serde_json::from_value::<HipSource>(json).unwrap(), source);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod event;
|
||||
pub mod hip;
|
||||
pub mod request;
|
||||
pub mod transport;
|
||||
pub mod vpn_env;
|
||||
|
||||
@@ -9,10 +9,32 @@ use crate::{
|
||||
os_profile::{ClientOs, OsProfile},
|
||||
};
|
||||
|
||||
use super::vpn_state::ConnectInfo;
|
||||
use super::{hip::HipSource, vpn_state::ConnectInfo};
|
||||
|
||||
pub const MAX_CLIENT_IDENTITY_DATA: usize = 32 * 1024;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct StoreEditedHipReportChunkRequest {
|
||||
pub upload_id: Option<String>,
|
||||
pub offset: usize,
|
||||
pub xml: String,
|
||||
pub complete: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct PreviewHipReportRequest {
|
||||
pub source: HipSource,
|
||||
pub client_os: ClientOs,
|
||||
pub client_version: String,
|
||||
pub host_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct ReadHipPreviewChunkRequest {
|
||||
pub preview_id: String,
|
||||
pub offset: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct LaunchGuiRequest {
|
||||
user: String,
|
||||
@@ -50,9 +72,7 @@ pub struct ConnectArgs {
|
||||
sslkey_data: Option<String>,
|
||||
key_password: Option<String>,
|
||||
|
||||
hip: bool,
|
||||
csd_uid: u32,
|
||||
csd_wrapper: Option<String>,
|
||||
hip_source: HipSource,
|
||||
|
||||
reconnect_timeout: u32,
|
||||
mtu: u32,
|
||||
@@ -80,9 +100,7 @@ impl ConnectArgs {
|
||||
certificate_data: None,
|
||||
sslkey_data: None,
|
||||
key_password: None,
|
||||
hip: false,
|
||||
csd_uid: 0,
|
||||
csd_wrapper: None,
|
||||
hip_source: HipSource::Disabled,
|
||||
reconnect_timeout: 300,
|
||||
mtu: 0,
|
||||
disable_ipv6: false,
|
||||
@@ -154,16 +172,8 @@ impl ConnectArgs {
|
||||
self.key_password.clone()
|
||||
}
|
||||
|
||||
pub fn hip(&self) -> bool {
|
||||
self.hip
|
||||
}
|
||||
|
||||
pub fn csd_uid(&self) -> u32 {
|
||||
self.csd_uid
|
||||
}
|
||||
|
||||
pub fn csd_wrapper(&self) -> Option<String> {
|
||||
self.csd_wrapper.clone()
|
||||
pub fn hip_source(&self) -> &HipSource {
|
||||
&self.hip_source
|
||||
}
|
||||
|
||||
pub fn reconnect_timeout(&self) -> u32 {
|
||||
@@ -212,9 +222,7 @@ impl fmt::Debug for ConnectArgs {
|
||||
"client_auth_data",
|
||||
&(self.certificate_data.is_some() || self.sslkey_data.is_some()),
|
||||
)
|
||||
.field("hip", &self.hip)
|
||||
.field("csd_uid", &self.csd_uid)
|
||||
.field("csd_wrapper", &self.csd_wrapper)
|
||||
.field("hip_source", &self.hip_source)
|
||||
.field("reconnect_timeout", &self.reconnect_timeout)
|
||||
.field("mtu", &self.mtu)
|
||||
.field("disable_ipv6", &self.disable_ipv6)
|
||||
@@ -252,18 +260,8 @@ impl ConnectRequest {
|
||||
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 {
|
||||
self.args.csd_uid = csd_uid;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_csd_wrapper<T: Into<Option<String>>>(mut self, csd_wrapper: T) -> Self {
|
||||
self.args.csd_wrapper = csd_wrapper.into();
|
||||
pub fn with_hip_source(mut self, hip_source: HipSource) -> Self {
|
||||
self.args.hip_source = hip_source;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -371,6 +369,11 @@ pub struct UpdateLogLevelRequest(pub String);
|
||||
pub enum WsRequest {
|
||||
Connect(Box<ConnectRequest>),
|
||||
Disconnect(DisconnectRequest),
|
||||
StoreEditedHipReportChunk(StoreEditedHipReportChunkRequest),
|
||||
PreviewHipReport(PreviewHipReportRequest),
|
||||
GetHipApprovalStatus { approval_id: String },
|
||||
ReadHipPreviewChunk(ReadHipPreviewChunkRequest),
|
||||
GetLastSubmittedHipReport,
|
||||
UpdateLogLevel(UpdateLogLevelRequest),
|
||||
RestartGui,
|
||||
UpdateGui(UpdateGuiRequest),
|
||||
|
||||
@@ -22,6 +22,7 @@ pub enum TransportError {
|
||||
#[serde(tag = "type", rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub enum HandshakeRejection {
|
||||
VersionMismatch { client: String, service: String },
|
||||
HipProtocolMismatch { client: u16, service: u16 },
|
||||
ServiceRestarted { service_instance_id: Uuid },
|
||||
ReconnectSuperseded,
|
||||
Unauthorized,
|
||||
|
||||
@@ -7,6 +7,8 @@ use super::{HandshakeRejection, MAX_PRELUDE, MAX_PRODUCT_VERSION, TransportError
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ClientPrelude {
|
||||
pub product_version: String,
|
||||
#[serde(default)]
|
||||
pub hip_protocol_version: u16,
|
||||
pub service_instance_id: Uuid,
|
||||
pub session_id: Uuid,
|
||||
}
|
||||
@@ -71,9 +73,16 @@ mod tests {
|
||||
r#"{{"product_version":"2.6.4","service_instance_id":"{instance}","session_id":"{session}","extra":true}}"#
|
||||
);
|
||||
assert!(ClientPrelude::decode(unknown.as_bytes()).is_err());
|
||||
let legacy =
|
||||
format!(r#"{{"product_version":"2.6.4","service_instance_id":"{instance}","session_id":"{session}"}}"#);
|
||||
assert_eq!(
|
||||
ClientPrelude::decode(legacy.as_bytes()).unwrap().hip_protocol_version,
|
||||
0
|
||||
);
|
||||
assert!(
|
||||
ClientPrelude {
|
||||
product_version: String::new(),
|
||||
hip_protocol_version: super::super::HIP_PROTOCOL_VERSION,
|
||||
service_instance_id: instance,
|
||||
session_id: session,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::service::hip::HipApprovalStatus;
|
||||
use crate::service::{event::WsEvent, request::WsRequest, vpn_env::VpnEnv, vpnc_script::VpncScriptMetadata};
|
||||
|
||||
use super::{MAX_PLAINTEXT, MAX_SERVICE_MESSAGE, ServiceErrorCode, TransportError};
|
||||
@@ -39,6 +40,20 @@ pub enum ServerMessage {
|
||||
#[serde(tag = "type", content = "data", rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub enum ServiceResult {
|
||||
Accepted,
|
||||
StoredHipReport {
|
||||
report_id: String,
|
||||
},
|
||||
HipUploadProgress {
|
||||
upload_id: String,
|
||||
},
|
||||
HipPreviewChunk {
|
||||
preview_id: String,
|
||||
offset: usize,
|
||||
xml: String,
|
||||
complete: bool,
|
||||
},
|
||||
HipApprovalStatus(HipApprovalStatus),
|
||||
NoSubmittedHipReport,
|
||||
VpncScriptMetadata(Option<VpncScriptMetadata>),
|
||||
Rejected(ServiceRejection),
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ pub use noise::{NoiseInitiator, NoiseResponder, NoiseTransport};
|
||||
pub const MAX_CREDENTIAL_FRAME: usize = 512;
|
||||
pub const MAX_PRELUDE: usize = 256;
|
||||
pub const MAX_PRODUCT_VERSION: usize = 64;
|
||||
pub const HIP_PROTOCOL_VERSION: u16 = 1;
|
||||
pub const MAX_PLAINTEXT: usize = 60 * 1024;
|
||||
pub const MAX_WS_MESSAGE: usize = u16::MAX as usize;
|
||||
pub const MAX_SERVICE_MESSAGE: usize = 256;
|
||||
@@ -24,9 +24,6 @@ pub struct VpnEnv {
|
||||
/// The default VPN script path
|
||||
pub vpnc_script: Option<String>,
|
||||
|
||||
/// The default CSD wrapper script path
|
||||
pub csd_wrapper: Option<String>,
|
||||
|
||||
/// The gpauth executable path
|
||||
/// Used by the client to launch gpauth for authentication
|
||||
pub auth_executable: String,
|
||||
|
||||
Reference in new issue
Block a user