mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 14:36:15 -05:00
fix: improve CSC criteria support
This commit is contained in:
10 files changed
+460
-106
No files matched your search
@@ -154,11 +154,11 @@ fn init_logger(cli: &Cli) {
|
|||||||
// Output the log messages to a file if the command is the auth callback
|
// Output the log messages to a file if the command is the auth callback
|
||||||
if let CliCommand::LaunchGui(args) = &cli.command {
|
if let CliCommand::LaunchGui(args) = &cli.command {
|
||||||
let auth_data = args.auth_data.as_deref().unwrap_or_default();
|
let auth_data = args.auth_data.as_deref().unwrap_or_default();
|
||||||
if !auth_data.is_empty() {
|
if !auth_data.is_empty()
|
||||||
if let Ok(log_file) = File::create(temp_dir().join("gpcallback.log")) {
|
&& let Ok(log_file) = File::create(temp_dir().join("gpcallback.log"))
|
||||||
let target = Box::new(log_file);
|
{
|
||||||
builder.target(env_logger::Target::Pipe(target));
|
let target = Box::new(log_file);
|
||||||
}
|
builder.target(env_logger::Target::Pipe(target));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use std::{
|
|||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
fs,
|
fs,
|
||||||
|
str::FromStr,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -41,6 +42,36 @@ struct GatewayLoginSession {
|
|||||||
extension_auth: SessionExtensionAuth,
|
extension_auth: SessionExtensionAuth,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
struct CscPreferenceArg {
|
||||||
|
domain: String,
|
||||||
|
key: String,
|
||||||
|
value: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for CscPreferenceArg {
|
||||||
|
type Err = String;
|
||||||
|
|
||||||
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
|
let (name, value) = input
|
||||||
|
.split_once('=')
|
||||||
|
.ok_or_else(|| "expected <domain>:<key>=<value>".to_string())?;
|
||||||
|
let (domain, key) = name
|
||||||
|
.split_once(':')
|
||||||
|
.ok_or_else(|| "expected <domain>:<key>=<value>".to_string())?;
|
||||||
|
|
||||||
|
if domain.is_empty() || key.is_empty() || value.is_empty() {
|
||||||
|
return Err("domain, key, and value must be non-empty".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
domain: domain.to_string(),
|
||||||
|
key: key.to_string(),
|
||||||
|
value: value.to_string(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
pub(crate) struct ConnectArgs {
|
pub(crate) struct ConnectArgs {
|
||||||
#[arg(help = "The portal server to connect to")]
|
#[arg(help = "The portal server to connect to")]
|
||||||
@@ -133,6 +164,13 @@ pub(crate) struct ConnectArgs {
|
|||||||
)]
|
)]
|
||||||
local_hostname: Option<String>,
|
local_hostname: Option<String>,
|
||||||
|
|
||||||
|
#[arg(
|
||||||
|
long = "csc-preference",
|
||||||
|
help = "Override a Mac CSC plist preference value, in the form <domain>:<key>=<value>",
|
||||||
|
value_name = "DOMAIN:KEY=VALUE"
|
||||||
|
)]
|
||||||
|
csc_preferences: Vec<CscPreferenceArg>,
|
||||||
|
|
||||||
#[arg(
|
#[arg(
|
||||||
long = "force-dpd",
|
long = "force-dpd",
|
||||||
help = "Same as the '--force-dpd' option in the openconnect command"
|
help = "Same as the '--force-dpd' option in the openconnect command"
|
||||||
@@ -237,6 +275,10 @@ impl<'a> ConnectHandler<'a> {
|
|||||||
builder.computer(local_hostname);
|
builder.computer(local_hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for preference in &self.args.csc_preferences {
|
||||||
|
builder.csc_preference_override(&preference.domain, &preference.key, &preference.value);
|
||||||
|
}
|
||||||
|
|
||||||
builder.build()
|
builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -583,7 +625,7 @@ impl<'a> ConnectHandler<'a> {
|
|||||||
.saml_request(prelogin.saml_request())
|
.saml_request(prelogin.saml_request())
|
||||||
.user_agent(&user_agent)
|
.user_agent(&user_agent)
|
||||||
.os(self.args.os.as_str())
|
.os(self.args.os.as_str())
|
||||||
.os_version(Some(&os_version))
|
.os_version(Some(os_version))
|
||||||
.fix_openssl(self.shared_args.fix_openssl)
|
.fix_openssl(self.shared_args.fix_openssl)
|
||||||
.ignore_tls_errors(self.shared_args.ignore_tls_errors)
|
.ignore_tls_errors(self.shared_args.ignore_tls_errors)
|
||||||
.browser(browser)
|
.browser(browser)
|
||||||
@@ -705,3 +747,31 @@ fn get_uid(user: &Option<String>) -> anyhow::Result<u32> {
|
|||||||
get_non_root_user().map_or_else(|_| Ok(0), |user| Ok(user.uid()))
|
get_non_root_user().map_or_else(|_| Ok(0), |user| Ok(user.uid()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_csc_preference_override() {
|
||||||
|
let preference = CscPreferenceArg::from_str("com.example.settings:ExampleKey=ExampleValue").unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
preference,
|
||||||
|
CscPreferenceArg {
|
||||||
|
domain: "com.example.settings".to_string(),
|
||||||
|
key: "ExampleKey".to_string(),
|
||||||
|
value: "ExampleValue".to_string(),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_invalid_csc_preference_override() {
|
||||||
|
assert!(CscPreferenceArg::from_str("com.example.settings:ExampleKey").is_err());
|
||||||
|
assert!(CscPreferenceArg::from_str("com.example.settings=ExampleValue").is_err());
|
||||||
|
assert!(CscPreferenceArg::from_str(":ExampleKey=ExampleValue").is_err());
|
||||||
|
assert!(CscPreferenceArg::from_str("com.example.settings:=ExampleValue").is_err());
|
||||||
|
assert!(CscPreferenceArg::from_str("com.example.settings:ExampleKey=").is_err());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -262,6 +262,18 @@ impl From<PasswordCredential> for Credential {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<&AuthCookieCredential> for Credential {
|
||||||
|
fn from(value: &AuthCookieCredential) -> Self {
|
||||||
|
Self::AuthCookie(value.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&CachedCredential> for Credential {
|
||||||
|
fn from(value: &CachedCredential) -> Self {
|
||||||
|
Self::Cached(value.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -300,15 +312,3 @@ mod tests {
|
|||||||
assert_eq!(params.get("token"), Some(&"cas-token"));
|
assert_eq!(params.get("token"), Some(&"cas-token"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&AuthCookieCredential> for Credential {
|
|
||||||
fn from(value: &AuthCookieCredential) -> Self {
|
|
||||||
Self::AuthCookie(value.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&CachedCredential> for Credential {
|
|
||||||
fn from(value: &CachedCredential) -> Self {
|
|
||||||
Self::Cached(value.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -35,7 +35,7 @@ pub(crate) fn parse_gateways(element: &Element, prefer_internal: bool) -> Option
|
|||||||
let priority = parse_priority(gateway_item);
|
let priority = parse_priority(gateway_item);
|
||||||
let priority_rules = gateway_item
|
let priority_rules = gateway_item
|
||||||
.child("priority-rule")
|
.child("priority-rule")
|
||||||
.map(|n| parse_priority_rules(n))
|
.map(parse_priority_rules)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
Gateway {
|
Gateway {
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ pub struct GpParams {
|
|||||||
certificate: Option<String>,
|
certificate: Option<String>,
|
||||||
sslkey: Option<String>,
|
sslkey: Option<String>,
|
||||||
key_password: Option<String>,
|
key_password: Option<String>,
|
||||||
|
csc_preference_overrides: HashMap<String, String>,
|
||||||
// Used for MFA
|
// Used for MFA
|
||||||
input_str: Option<String>,
|
input_str: Option<String>,
|
||||||
otp: Option<String>,
|
otp: Option<String>,
|
||||||
@@ -100,6 +101,13 @@ impl GpParams {
|
|||||||
self.client_version.as_deref()
|
self.client_version.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn csc_preference_override(&self, domain: &str, key: &str) -> Option<&str> {
|
||||||
|
self
|
||||||
|
.csc_preference_overrides
|
||||||
|
.get(&csc_preference_key(domain, key))
|
||||||
|
.map(String::as_str)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_input_str(&mut self, input_str: &str) {
|
pub fn set_input_str(&mut self, input_str: &str) {
|
||||||
self.input_str = Some(input_str.to_string());
|
self.input_str = Some(input_str.to_string());
|
||||||
}
|
}
|
||||||
@@ -152,6 +160,7 @@ pub struct GpParamsBuilder {
|
|||||||
certificate: Option<String>,
|
certificate: Option<String>,
|
||||||
sslkey: Option<String>,
|
sslkey: Option<String>,
|
||||||
key_password: Option<String>,
|
key_password: Option<String>,
|
||||||
|
csc_preference_overrides: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GpParamsBuilder {
|
impl GpParamsBuilder {
|
||||||
@@ -169,6 +178,7 @@ impl GpParamsBuilder {
|
|||||||
certificate: Default::default(),
|
certificate: Default::default(),
|
||||||
sslkey: Default::default(),
|
sslkey: Default::default(),
|
||||||
key_password: Default::default(),
|
key_password: Default::default(),
|
||||||
|
csc_preference_overrides: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,6 +232,13 @@ impl GpParamsBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn csc_preference_override(&mut self, domain: &str, key: &str, value: &str) -> &mut Self {
|
||||||
|
self
|
||||||
|
.csc_preference_overrides
|
||||||
|
.insert(csc_preference_key(domain, key), value.to_string());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build(&self) -> GpParams {
|
pub fn build(&self) -> GpParams {
|
||||||
GpParams {
|
GpParams {
|
||||||
is_gateway: self.is_gateway,
|
is_gateway: self.is_gateway,
|
||||||
@@ -234,12 +251,17 @@ impl GpParamsBuilder {
|
|||||||
certificate: self.certificate.clone(),
|
certificate: self.certificate.clone(),
|
||||||
sslkey: self.sslkey.clone(),
|
sslkey: self.sslkey.clone(),
|
||||||
key_password: self.key_password.clone(),
|
key_password: self.key_password.clone(),
|
||||||
|
csc_preference_overrides: self.csc_preference_overrides.clone(),
|
||||||
input_str: Default::default(),
|
input_str: Default::default(),
|
||||||
otp: Default::default(),
|
otp: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn csc_preference_key(domain: &str, key: &str) -> String {
|
||||||
|
format!("{domain}:{key}")
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for GpParamsBuilder {
|
impl Default for GpParamsBuilder {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ async fn retrieve_csc_config(
|
|||||||
let params = csc::csc_params(&csc_req, username, gp_params, &swg_nonce);
|
let params = csc::csc_params(&csc_req, username, gp_params, &swg_nonce);
|
||||||
let url = format!("{}/global-protect/getconfig_csc.esp", portal);
|
let url = format!("{}/global-protect/getconfig_csc.esp", portal);
|
||||||
|
|
||||||
|
info!("Portal CSC config request summary: {}", csc_req.summary());
|
||||||
info!("Portal CSC config request params: {}", redact_params(¶ms));
|
info!("Portal CSC config request params: {}", redact_params(¶ms));
|
||||||
|
|
||||||
let res = client.post(&url).form(¶ms).send().await.map_err(|e| {
|
let res = client.post(&url).form(¶ms).send().await.map_err(|e| {
|
||||||
@@ -252,7 +253,7 @@ fn parse_portal_config(server: &str, cred: &Credential, root: Element) -> anyhow
|
|||||||
let mut prefer_internal = false;
|
let mut prefer_internal = false;
|
||||||
if let Some(ihd_node) = root.descendant("internal-host-detection") {
|
if let Some(ihd_node) = root.descendant("internal-host-detection") {
|
||||||
ihd_enabled = true;
|
ihd_enabled = true;
|
||||||
prefer_internal = internal_host_detect(&ihd_node)
|
prefer_internal = internal_host_detect(ihd_node)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut gateways = parse_gateways(&root, prefer_internal).unwrap_or_else(|| {
|
let mut gateways = parse_gateways(&root, prefer_internal).unwrap_or_else(|| {
|
||||||
@@ -313,23 +314,24 @@ fn internal_host_detect(element: &Element) -> bool {
|
|||||||
info!("Found internal-host-detection, performing DNS lookup");
|
info!("Found internal-host-detection, performing DNS lookup");
|
||||||
|
|
||||||
for (ip_address, host) in ip_info.iter() {
|
for (ip_address, host) in ip_info.iter() {
|
||||||
if let (Some(ip_address), Some(host)) = (ip_address.as_deref(), host.as_deref()) {
|
if let (Some(ip_address), Some(host)) = (ip_address.as_deref(), host.as_deref())
|
||||||
if !ip_address.is_empty() && !host.is_empty() {
|
&& !ip_address.is_empty()
|
||||||
match ip_address.parse::<std::net::IpAddr>() {
|
&& !host.is_empty()
|
||||||
Ok(ip) => match lookup_addr(&ip) {
|
{
|
||||||
Ok(host_lookup) if host_lookup.to_lowercase() == host.to_lowercase() => {
|
match ip_address.parse::<std::net::IpAddr>() {
|
||||||
return true;
|
Ok(ip) => match lookup_addr(&ip) {
|
||||||
}
|
Ok(host_lookup) if host_lookup.to_lowercase() == host.to_lowercase() => {
|
||||||
Ok(host_lookup) => {
|
return true;
|
||||||
info!(
|
}
|
||||||
"rDNS lookup for {} returned {}, expected {}",
|
Ok(host_lookup) => {
|
||||||
ip_address, host_lookup, host
|
info!(
|
||||||
);
|
"rDNS lookup for {} returned {}, expected {}",
|
||||||
}
|
ip_address, host_lookup, host
|
||||||
Err(err) => warn!("rDNS lookup failed for {}: {}", ip_address, err),
|
);
|
||||||
},
|
}
|
||||||
Err(err) => warn!("Invalid IP address {}: {}", ip_address, err),
|
Err(err) => warn!("rDNS lookup failed for {}: {}", ip_address, err),
|
||||||
}
|
},
|
||||||
|
Err(err) => warn!("Invalid IP address {}: {}", ip_address, err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+314
-58
@@ -1,5 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
fmt::Write,
|
||||||
fs,
|
fs,
|
||||||
process::Command,
|
process::Command,
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
@@ -19,20 +20,62 @@ pub(super) struct CscRequest {
|
|||||||
pub(super) config_digest: String,
|
pub(super) config_digest: String,
|
||||||
pub(super) csc_digest: String,
|
pub(super) csc_digest: String,
|
||||||
pub(super) csc_data: String,
|
pub(super) csc_data: String,
|
||||||
|
summary: CscBuildSummary,
|
||||||
host_id: String,
|
host_id: String,
|
||||||
serial_number: String,
|
serial_number: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) trait PreferenceReader {
|
impl CscRequest {
|
||||||
fn read_preference(&self, domain: &str, key: &str) -> Option<String>;
|
pub(super) fn summary(&self) -> String {
|
||||||
|
format!(
|
||||||
|
"digest_len={}, xml_len={}, plist_entries={}, plist_present={}, plist_missing={}, process_entries={}, process_present={}, process_missing={}",
|
||||||
|
self.csc_digest.len(),
|
||||||
|
self.csc_data.len(),
|
||||||
|
self.summary.plist_entries,
|
||||||
|
self.summary.plist_present,
|
||||||
|
self.summary.plist_missing,
|
||||||
|
self.summary.process_entries,
|
||||||
|
self.summary.process_present,
|
||||||
|
self.summary.process_missing,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SystemPreferenceReader;
|
#[derive(Default)]
|
||||||
|
struct CscBuildSummary {
|
||||||
|
plist_entries: usize,
|
||||||
|
plist_present: usize,
|
||||||
|
plist_missing: usize,
|
||||||
|
process_entries: usize,
|
||||||
|
process_present: usize,
|
||||||
|
process_missing: usize,
|
||||||
|
}
|
||||||
|
|
||||||
impl PreferenceReader for SystemPreferenceReader {
|
struct CscDataInput<'a> {
|
||||||
|
criteria: &'a Element,
|
||||||
|
auth_cookie: &'a str,
|
||||||
|
username: &'a str,
|
||||||
|
gp_params: &'a GpParams,
|
||||||
|
host_id: &'a str,
|
||||||
|
serial_number: &'a str,
|
||||||
|
csc_digest: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) trait CscDataReader {
|
||||||
|
fn read_preference(&self, domain: &str, key: &str) -> Option<String>;
|
||||||
|
fn process_exists(&self, name: &str) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SystemCscDataReader;
|
||||||
|
|
||||||
|
impl CscDataReader for SystemCscDataReader {
|
||||||
fn read_preference(&self, domain: &str, key: &str) -> Option<String> {
|
fn read_preference(&self, domain: &str, key: &str) -> Option<String> {
|
||||||
read_macos_preference(domain, key)
|
read_macos_preference(domain, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn process_exists(&self, name: &str) -> bool {
|
||||||
|
linux_process_names().iter().any(|process_name| process_name == name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn swg_nonce() -> String {
|
pub(super) fn swg_nonce() -> String {
|
||||||
@@ -49,7 +92,7 @@ pub(super) fn is_config_criteria(root: &Element) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn build_csc_request(root: &Element, username: &str, gp_params: &GpParams) -> anyhow::Result<CscRequest> {
|
pub(super) fn build_csc_request(root: &Element, username: &str, gp_params: &GpParams) -> anyhow::Result<CscRequest> {
|
||||||
let reader = SystemPreferenceReader;
|
let reader = SystemCscDataReader;
|
||||||
build_csc_request_with_reader(root, username, gp_params, &reader)
|
build_csc_request_with_reader(root, username, gp_params, &reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +100,7 @@ pub(super) fn build_csc_request_with_reader(
|
|||||||
root: &Element,
|
root: &Element,
|
||||||
username: &str,
|
username: &str,
|
||||||
gp_params: &GpParams,
|
gp_params: &GpParams,
|
||||||
reader: &dyn PreferenceReader,
|
reader: &dyn CscDataReader,
|
||||||
) -> anyhow::Result<CscRequest> {
|
) -> anyhow::Result<CscRequest> {
|
||||||
let auth_cookie = root
|
let auth_cookie = root
|
||||||
.descendant_text("portal-csc-auth-cookie")
|
.descendant_text("portal-csc-auth-cookie")
|
||||||
@@ -67,17 +110,21 @@ pub(super) fn build_csc_request_with_reader(
|
|||||||
let host_id = collect_host_id(gp_params);
|
let host_id = collect_host_id(gp_params);
|
||||||
let serial_number = collect_serial_number();
|
let serial_number = collect_serial_number();
|
||||||
|
|
||||||
|
let mut summary = CscBuildSummary::default();
|
||||||
let csc_data = build_csc_data(
|
let csc_data = build_csc_data(
|
||||||
root,
|
CscDataInput {
|
||||||
&auth_cookie,
|
criteria: root,
|
||||||
username,
|
auth_cookie: &auth_cookie,
|
||||||
gp_params,
|
username,
|
||||||
&host_id,
|
gp_params,
|
||||||
&serial_number,
|
host_id: &host_id,
|
||||||
DIGEST_PLACEHOLDER,
|
serial_number: &serial_number,
|
||||||
|
csc_digest: DIGEST_PLACEHOLDER,
|
||||||
|
},
|
||||||
reader,
|
reader,
|
||||||
|
&mut summary,
|
||||||
)?;
|
)?;
|
||||||
let csc_digest = format!("{:x}", md5::compute(csc_data.as_bytes()));
|
let csc_digest = pan_md5_hex(csc_data.as_bytes());
|
||||||
let csc_data = csc_data.replace(DIGEST_PLACEHOLDER, &csc_digest);
|
let csc_data = csc_data.replace(DIGEST_PLACEHOLDER, &csc_digest);
|
||||||
|
|
||||||
Ok(CscRequest {
|
Ok(CscRequest {
|
||||||
@@ -85,6 +132,7 @@ pub(super) fn build_csc_request_with_reader(
|
|||||||
config_digest,
|
config_digest,
|
||||||
csc_digest,
|
csc_digest,
|
||||||
csc_data,
|
csc_data,
|
||||||
|
summary,
|
||||||
host_id,
|
host_id,
|
||||||
serial_number,
|
serial_number,
|
||||||
})
|
})
|
||||||
@@ -115,26 +163,24 @@ pub(super) fn csc_params<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn build_csc_data(
|
fn build_csc_data(
|
||||||
criteria: &Element,
|
input: CscDataInput<'_>,
|
||||||
auth_cookie: &str,
|
reader: &dyn CscDataReader,
|
||||||
username: &str,
|
summary: &mut CscBuildSummary,
|
||||||
gp_params: &GpParams,
|
|
||||||
host_id: &str,
|
|
||||||
serial_number: &str,
|
|
||||||
csc_digest: &str,
|
|
||||||
reader: &dyn PreferenceReader,
|
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
let mut root = Element::new("hip-report");
|
let mut root = Element::new("hip-report");
|
||||||
push_text(&mut root, "portal-csc-auth-cookie", auth_cookie);
|
push_text(&mut root, "portal-csc-auth-cookie", input.auth_cookie);
|
||||||
push_text(&mut root, "user-name", &urlencoding::encode(username));
|
push_text(&mut root, "user-name", &urlencoding::encode(input.username));
|
||||||
push_text(&mut root, "client-os", &client_os_report_value(gp_params));
|
push_text(&mut root, "client-os", &client_os_report_value(input.gp_params));
|
||||||
push_text(&mut root, "host-id", host_id);
|
push_text(&mut root, "host-id", input.host_id);
|
||||||
push_text(&mut root, "device-serial-number", serial_number);
|
push_text(&mut root, "device-serial-number", input.serial_number);
|
||||||
push_text(&mut root, "csc-digest", csc_digest);
|
push_text(&mut root, "csc-digest", input.csc_digest);
|
||||||
root.children.push(XMLNode::Element(Element::new("categories")));
|
root.children.push(XMLNode::Element(Element::new("categories")));
|
||||||
root
|
root.children.push(XMLNode::Element(build_custom_checks(
|
||||||
.children
|
input.criteria,
|
||||||
.push(XMLNode::Element(build_custom_checks(criteria, gp_params, reader)));
|
input.gp_params,
|
||||||
|
reader,
|
||||||
|
summary,
|
||||||
|
)));
|
||||||
|
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
root.write_with_config(
|
root.write_with_config(
|
||||||
@@ -147,26 +193,49 @@ fn build_csc_data(
|
|||||||
String::from_utf8(bytes).map_err(Into::into)
|
String::from_utf8(bytes).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_custom_checks(criteria: &Element, gp_params: &GpParams, reader: &dyn PreferenceReader) -> Element {
|
fn build_custom_checks(
|
||||||
|
criteria: &Element,
|
||||||
|
gp_params: &GpParams,
|
||||||
|
reader: &dyn CscDataReader,
|
||||||
|
summary: &mut CscBuildSummary,
|
||||||
|
) -> Element {
|
||||||
let mut custom_checks = Element::new("custom-checks");
|
let mut custom_checks = Element::new("custom-checks");
|
||||||
let Some(requested_checks) = criteria.descendant("custom-checks") else {
|
let Some(requested_checks) = criteria.descendant("custom-checks") else {
|
||||||
return custom_checks;
|
return custom_checks;
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(mac_os) = requested_checks.child("mac-os") {
|
if gp_params.client_os() == "Mac"
|
||||||
if let Some(plist) = mac_os.child("plist") {
|
&& let Some(plist) = requested_checks
|
||||||
custom_checks.children.push(XMLNode::Element(build_plist_checks(
|
.child("mac-os")
|
||||||
plist,
|
.and_then(|mac_os| mac_os.child("plist"))
|
||||||
gp_params.client_os() == "Mac",
|
{
|
||||||
reader,
|
custom_checks
|
||||||
)));
|
.children
|
||||||
}
|
.push(XMLNode::Element(build_plist_checks(plist, gp_params, reader, summary)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if gp_params.client_os() == "Linux"
|
||||||
|
&& let Some(process_list) = requested_checks
|
||||||
|
.child("linux")
|
||||||
|
.and_then(|linux| linux.child("process-list"))
|
||||||
|
.or_else(|| requested_checks.child("process-list"))
|
||||||
|
{
|
||||||
|
custom_checks.children.push(XMLNode::Element(build_process_list_checks(
|
||||||
|
process_list,
|
||||||
|
reader,
|
||||||
|
summary,
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
custom_checks
|
custom_checks
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_plist_checks(plist: &Element, can_read: bool, reader: &dyn PreferenceReader) -> Element {
|
fn build_plist_checks(
|
||||||
|
plist: &Element,
|
||||||
|
gp_params: &GpParams,
|
||||||
|
reader: &dyn CscDataReader,
|
||||||
|
summary: &mut CscBuildSummary,
|
||||||
|
) -> Element {
|
||||||
let mut out = Element::new("plist");
|
let mut out = Element::new("plist");
|
||||||
|
|
||||||
for entry in plist.children("entry") {
|
for entry in plist.children("entry") {
|
||||||
@@ -178,15 +247,17 @@ fn build_plist_checks(plist: &Element, can_read: bool, reader: &dyn PreferenceRe
|
|||||||
let values: Vec<_> = keys
|
let values: Vec<_> = keys
|
||||||
.iter()
|
.iter()
|
||||||
.map(|key| {
|
.map(|key| {
|
||||||
let value = if can_read {
|
let value = gp_params
|
||||||
reader.read_preference(domain, key)
|
.csc_preference_override(domain, key)
|
||||||
} else {
|
.map(str::to_string)
|
||||||
None
|
.or_else(|| reader.read_preference(domain, key));
|
||||||
};
|
|
||||||
(key.as_str(), value)
|
(key.as_str(), value)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let plist_exists = values.iter().any(|(_, value)| value.is_some());
|
let plist_exists = values.iter().any(|(_, value)| value.is_some());
|
||||||
|
summary.plist_entries += keys.len();
|
||||||
|
summary.plist_present += values.iter().filter(|(_, value)| value.is_some()).count();
|
||||||
|
summary.plist_missing += values.iter().filter(|(_, value)| value.is_none()).count();
|
||||||
|
|
||||||
push_text(&mut out_entry, "exist", yes_no(plist_exists));
|
push_text(&mut out_entry, "exist", yes_no(plist_exists));
|
||||||
push_text(&mut out_entry, "value", "");
|
push_text(&mut out_entry, "value", "");
|
||||||
@@ -207,6 +278,32 @@ fn build_plist_checks(plist: &Element, can_read: bool, reader: &dyn PreferenceRe
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_process_list_checks(
|
||||||
|
process_list: &Element,
|
||||||
|
reader: &dyn CscDataReader,
|
||||||
|
summary: &mut CscBuildSummary,
|
||||||
|
) -> Element {
|
||||||
|
let mut out = Element::new("process-list");
|
||||||
|
|
||||||
|
for process_name in process_list_names(process_list) {
|
||||||
|
let exists = reader.process_exists(&process_name);
|
||||||
|
summary.process_entries += 1;
|
||||||
|
if exists {
|
||||||
|
summary.process_present += 1;
|
||||||
|
} else {
|
||||||
|
summary.process_missing += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut entry = Element::new("entry");
|
||||||
|
entry.attributes.insert("name".to_string(), process_name.clone());
|
||||||
|
push_text(&mut entry, "exist", yes_no(exists));
|
||||||
|
push_text(&mut entry, "value", if exists { &process_name } else { "" });
|
||||||
|
out.children.push(XMLNode::Element(entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
fn plist_entry_keys(entry: &Element) -> Vec<String> {
|
fn plist_entry_keys(entry: &Element) -> Vec<String> {
|
||||||
let keys: Vec<String> = entry
|
let keys: Vec<String> = entry
|
||||||
.descendants("member")
|
.descendants("member")
|
||||||
@@ -225,6 +322,37 @@ fn plist_entry_keys(entry: &Element) -> Vec<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn process_list_names(process_list: &Element) -> Vec<String> {
|
||||||
|
let mut names: Vec<String> = process_list
|
||||||
|
.descendants("member")
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|element| element.get_text())
|
||||||
|
.map(|text| text.trim().to_string())
|
||||||
|
.filter(|text| !text.is_empty())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
names.extend(
|
||||||
|
process_list
|
||||||
|
.children("entry")
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|entry| entry.attr("name"))
|
||||||
|
.map(str::to_string),
|
||||||
|
);
|
||||||
|
|
||||||
|
names.sort();
|
||||||
|
names.dedup();
|
||||||
|
names
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pan_md5_hex(value: &[u8]) -> String {
|
||||||
|
let digest = md5::compute(value);
|
||||||
|
let mut out = String::new();
|
||||||
|
for byte in digest.0 {
|
||||||
|
write!(&mut out, "{:x}", byte).expect("writing to String should not fail");
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
fn collect_host_id(gp_params: &GpParams) -> String {
|
fn collect_host_id(gp_params: &GpParams) -> String {
|
||||||
match gp_params.client_os() {
|
match gp_params.client_os() {
|
||||||
"Mac" => netdev::get_default_interface()
|
"Mac" => netdev::get_default_interface()
|
||||||
@@ -298,6 +426,30 @@ fn read_macos_preference(domain: &str, key: &str) -> Option<String> {
|
|||||||
.filter(|value| !value.is_empty())
|
.filter(|value| !value.is_empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn linux_process_names() -> Vec<String> {
|
||||||
|
let Ok(entries) = fs::read_dir("/proc") else {
|
||||||
|
return Vec::new();
|
||||||
|
};
|
||||||
|
|
||||||
|
entries
|
||||||
|
.filter_map(Result::ok)
|
||||||
|
.filter_map(|entry| {
|
||||||
|
entry
|
||||||
|
.file_name()
|
||||||
|
.to_str()
|
||||||
|
.filter(|name| name.chars().all(|ch| ch.is_ascii_digit()))
|
||||||
|
.map(|_| entry.path().join("stat"))
|
||||||
|
})
|
||||||
|
.filter_map(|path| fs::read_to_string(path).ok())
|
||||||
|
.filter_map(|stat| {
|
||||||
|
let start = stat.find('(')?;
|
||||||
|
let end = stat.rfind(')')?;
|
||||||
|
stat.get(start + 1..end).map(str::to_string)
|
||||||
|
})
|
||||||
|
.filter(|name| !name.is_empty())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
fn client_os_report_value(gp_params: &GpParams) -> String {
|
fn client_os_report_value(gp_params: &GpParams) -> String {
|
||||||
gp_params
|
gp_params
|
||||||
.os_version()
|
.os_version()
|
||||||
@@ -320,14 +472,19 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::gp_params::{ClientOs, GpParams};
|
use crate::gp_params::{ClientOs, GpParams};
|
||||||
|
|
||||||
struct TestPreferenceReader {
|
struct TestCscDataReader {
|
||||||
values: HashMap<String, String>,
|
values: HashMap<String, String>,
|
||||||
|
processes: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PreferenceReader for TestPreferenceReader {
|
impl CscDataReader for TestCscDataReader {
|
||||||
fn read_preference(&self, domain: &str, key: &str) -> Option<String> {
|
fn read_preference(&self, domain: &str, key: &str) -> Option<String> {
|
||||||
self.values.get(&format!("{domain}:{key}")).cloned()
|
self.values.get(&format!("{domain}:{key}")).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn process_exists(&self, name: &str) -> bool {
|
||||||
|
self.processes.iter().any(|process| process == name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_xml(xml: &str) -> Element {
|
fn parse_xml(xml: &str) -> Element {
|
||||||
@@ -354,8 +511,8 @@ mod tests {
|
|||||||
<custom-checks>
|
<custom-checks>
|
||||||
<mac-os>
|
<mac-os>
|
||||||
<plist>
|
<plist>
|
||||||
<entry name="com.paloaltonetworks.GlobalProtect.settings">
|
<entry name="com.example.settings">
|
||||||
<key><member>HipID</member></key>
|
<key><member>ExampleKey</member></key>
|
||||||
</entry>
|
</entry>
|
||||||
</plist>
|
</plist>
|
||||||
</mac-os>
|
</mac-os>
|
||||||
@@ -363,11 +520,12 @@ mod tests {
|
|||||||
<portal-csc-auth-cookie>cookie</portal-csc-auth-cookie>
|
<portal-csc-auth-cookie>cookie</portal-csc-auth-cookie>
|
||||||
</config-criteria>"#,
|
</config-criteria>"#,
|
||||||
);
|
);
|
||||||
let reader = TestPreferenceReader {
|
let reader = TestCscDataReader {
|
||||||
values: HashMap::from([(
|
values: HashMap::from([(
|
||||||
"com.paloaltonetworks.GlobalProtect.settings:HipID".to_string(),
|
"com.example.settings:ExampleKey".to_string(),
|
||||||
"MicroStrategyGP".to_string(),
|
"ExampleValue".to_string(),
|
||||||
)]),
|
)]),
|
||||||
|
processes: Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let req = build_csc_request_with_reader(&root, "[email protected]", &gp_params(ClientOs::Mac), &reader).unwrap();
|
let req = build_csc_request_with_reader(&root, "[email protected]", &gp_params(ClientOs::Mac), &reader).unwrap();
|
||||||
@@ -376,7 +534,7 @@ mod tests {
|
|||||||
assert!(req.csc_data.contains("<user-name>alice%40example.com</user-name>"));
|
assert!(req.csc_data.contains("<user-name>alice%40example.com</user-name>"));
|
||||||
assert!(req.csc_data.contains("<client-os>Apple+Mac+OS+X+26.4.1</client-os>"));
|
assert!(req.csc_data.contains("<client-os>Apple+Mac+OS+X+26.4.1</client-os>"));
|
||||||
assert!(req.csc_data.contains("<exist>yes</exist>"));
|
assert!(req.csc_data.contains("<exist>yes</exist>"));
|
||||||
assert!(req.csc_data.contains("<value>MicroStrategyGP</value>"));
|
assert!(req.csc_data.contains("<value>ExampleValue</value>"));
|
||||||
assert!(
|
assert!(
|
||||||
req
|
req
|
||||||
.csc_data
|
.csc_data
|
||||||
@@ -399,7 +557,10 @@ mod tests {
|
|||||||
<portal-csc-auth-cookie>cookie</portal-csc-auth-cookie>
|
<portal-csc-auth-cookie>cookie</portal-csc-auth-cookie>
|
||||||
</config-criteria>"#,
|
</config-criteria>"#,
|
||||||
);
|
);
|
||||||
let reader = TestPreferenceReader { values: HashMap::new() };
|
let reader = TestCscDataReader {
|
||||||
|
values: HashMap::new(),
|
||||||
|
processes: Vec::new(),
|
||||||
|
};
|
||||||
|
|
||||||
let req = build_csc_request_with_reader(&root, "alice", &gp_params(ClientOs::Mac), &reader).unwrap();
|
let req = build_csc_request_with_reader(&root, "alice", &gp_params(ClientOs::Mac), &reader).unwrap();
|
||||||
|
|
||||||
@@ -408,7 +569,37 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unsupported_client_os_reports_macos_plist_missing() {
|
fn macos_plist_override_works_without_native_preference() {
|
||||||
|
let root = parse_xml(
|
||||||
|
r#"<config-criteria>
|
||||||
|
<custom-checks>
|
||||||
|
<mac-os>
|
||||||
|
<plist>
|
||||||
|
<entry name="com.example.settings"><key><member>ExampleKey</member></key></entry>
|
||||||
|
</plist>
|
||||||
|
</mac-os>
|
||||||
|
</custom-checks>
|
||||||
|
<portal-csc-auth-cookie>cookie</portal-csc-auth-cookie>
|
||||||
|
</config-criteria>"#,
|
||||||
|
);
|
||||||
|
let reader = TestCscDataReader {
|
||||||
|
values: HashMap::new(),
|
||||||
|
processes: Vec::new(),
|
||||||
|
};
|
||||||
|
let gp_params = GpParams::builder()
|
||||||
|
.client_os(ClientOs::Mac)
|
||||||
|
.os_version(Some("Apple Mac OS X 26.4.1".to_string()))
|
||||||
|
.csc_preference_override("com.example.settings", "ExampleKey", "ExampleValue")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let req = build_csc_request_with_reader(&root, "alice", &gp_params, &reader).unwrap();
|
||||||
|
|
||||||
|
assert!(req.csc_data.contains("<exist>yes</exist>"));
|
||||||
|
assert!(req.csc_data.contains("<value>ExampleValue</value>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unsupported_client_os_ignores_macos_plist_branch() {
|
||||||
let root = parse_xml(
|
let root = parse_xml(
|
||||||
r#"<config-criteria>
|
r#"<config-criteria>
|
||||||
<custom-checks>
|
<custom-checks>
|
||||||
@@ -421,16 +612,54 @@ mod tests {
|
|||||||
<portal-csc-auth-cookie>cookie</portal-csc-auth-cookie>
|
<portal-csc-auth-cookie>cookie</portal-csc-auth-cookie>
|
||||||
</config-criteria>"#,
|
</config-criteria>"#,
|
||||||
);
|
);
|
||||||
let reader = TestPreferenceReader {
|
let reader = TestCscDataReader {
|
||||||
values: HashMap::from([("com.example:HipID".to_string(), "present".to_string())]),
|
values: HashMap::from([("com.example:HipID".to_string(), "present".to_string())]),
|
||||||
|
processes: Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let req = build_csc_request_with_reader(&root, "alice", &gp_params(ClientOs::Linux), &reader).unwrap();
|
let req = build_csc_request_with_reader(&root, "alice", &gp_params(ClientOs::Linux), &reader).unwrap();
|
||||||
|
|
||||||
assert!(req.csc_data.contains("<exist>no</exist>"));
|
assert!(!req.csc_data.contains("<plist>"));
|
||||||
|
assert!(!req.csc_data.contains("<exist>no</exist>"));
|
||||||
assert!(!req.csc_data.contains("present"));
|
assert!(!req.csc_data.contains("present"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn builds_linux_process_list_report() {
|
||||||
|
let root = parse_xml(
|
||||||
|
r#"<config-criteria>
|
||||||
|
<custom-checks>
|
||||||
|
<linux>
|
||||||
|
<process-list>
|
||||||
|
<entry name="present-process" />
|
||||||
|
<entry name="missing-process" />
|
||||||
|
</process-list>
|
||||||
|
</linux>
|
||||||
|
</custom-checks>
|
||||||
|
<portal-csc-auth-cookie>cookie</portal-csc-auth-cookie>
|
||||||
|
</config-criteria>"#,
|
||||||
|
);
|
||||||
|
let reader = TestCscDataReader {
|
||||||
|
values: HashMap::new(),
|
||||||
|
processes: vec!["present-process".to_string()],
|
||||||
|
};
|
||||||
|
|
||||||
|
let req = build_csc_request_with_reader(&root, "alice", &gp_params(ClientOs::Linux), &reader).unwrap();
|
||||||
|
|
||||||
|
assert!(req.csc_data.contains(r#"<entry name="present-process">"#));
|
||||||
|
assert!(req.csc_data.contains("<value>present-process</value>"));
|
||||||
|
assert!(req.csc_data.contains(r#"<entry name="missing-process">"#));
|
||||||
|
assert!(req.summary().contains("process_entries=2"));
|
||||||
|
assert!(req.summary().contains("process_present=1"));
|
||||||
|
assert!(req.summary().contains("process_missing=1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn uses_pan_non_padded_md5_digest() {
|
||||||
|
assert_eq!(pan_md5_hex(b""), "d41d8cd98f0b24e980998ecf8427e");
|
||||||
|
assert_ne!(pan_md5_hex(b""), format!("{:x}", md5::compute(b"")));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn builds_getconfig_csc_params() {
|
fn builds_getconfig_csc_params() {
|
||||||
let req = CscRequest {
|
let req = CscRequest {
|
||||||
@@ -439,6 +668,7 @@ mod tests {
|
|||||||
csc_digest: "csc-digest".to_string(),
|
csc_digest: "csc-digest".to_string(),
|
||||||
csc_data: "<hip-report><host-id>host</host-id><device-serial-number>serial</device-serial-number></hip-report>"
|
csc_data: "<hip-report><host-id>host</host-id><device-serial-number>serial</device-serial-number></hip-report>"
|
||||||
.to_string(),
|
.to_string(),
|
||||||
|
summary: CscBuildSummary::default(),
|
||||||
host_id: "host".to_string(),
|
host_id: "host".to_string(),
|
||||||
serial_number: "serial".to_string(),
|
serial_number: "serial".to_string(),
|
||||||
};
|
};
|
||||||
@@ -456,4 +686,30 @@ mod tests {
|
|||||||
assert_eq!(params.get("swg-auth-token"), Some(&"0"));
|
assert_eq!(params.get("swg-auth-token"), Some(&"0"));
|
||||||
assert_eq!(params.get("swg-nonce"), Some(&"123"));
|
assert_eq!(params.get("swg-nonce"), Some(&"123"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn generated_getconfig_csc_params_include_final_digest_and_data() {
|
||||||
|
let root = parse_xml(
|
||||||
|
r#"<config-criteria>
|
||||||
|
<custom-checks />
|
||||||
|
<portal-csc-auth-cookie>cookie</portal-csc-auth-cookie>
|
||||||
|
</config-criteria>"#,
|
||||||
|
);
|
||||||
|
let reader = TestCscDataReader {
|
||||||
|
values: HashMap::new(),
|
||||||
|
processes: Vec::new(),
|
||||||
|
};
|
||||||
|
let gp_params = gp_params(ClientOs::Linux);
|
||||||
|
let req = build_csc_request_with_reader(&root, "alice", &gp_params, &reader).unwrap();
|
||||||
|
let params = csc_params(&req, "alice", &gp_params, "123");
|
||||||
|
|
||||||
|
assert_eq!(params.get("csc-digest"), Some(&req.csc_digest.as_str()));
|
||||||
|
assert_eq!(params.get("csc-data"), Some(&req.csc_data.as_str()));
|
||||||
|
assert!(
|
||||||
|
req
|
||||||
|
.csc_data
|
||||||
|
.contains(&format!("<csc-digest>{}</csc-digest>", req.csc_digest))
|
||||||
|
);
|
||||||
|
assert!(!req.csc_data.contains(DIGEST_PLACEHOLDER));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -46,10 +46,10 @@ impl ElementExt for Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for child in &self.children {
|
for child in &self.children {
|
||||||
if let Some(element) = child.as_element() {
|
if let Some(element) = child.as_element()
|
||||||
if let Some(found) = element.descendant(name) {
|
&& let Some(found) = element.descendant(name)
|
||||||
return Some(found);
|
{
|
||||||
}
|
return Some(found);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
use std::{env, path::PathBuf, process::Command};
|
use std::{
|
||||||
|
env,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
process::Command,
|
||||||
|
};
|
||||||
|
|
||||||
fn apply_patches(patches_dir: &PathBuf, build_src: &PathBuf) {
|
fn apply_patches(patches_dir: &Path, build_src: &Path) {
|
||||||
let patches = std::fs::read_dir(patches_dir)
|
let patches = std::fs::read_dir(patches_dir)
|
||||||
.expect("Failed to read patches directory")
|
.expect("Failed to read patches directory")
|
||||||
.filter_map(|entry| entry.ok())
|
.filter_map(|entry| entry.ok())
|
||||||
@@ -30,7 +34,7 @@ fn apply_patches(patches_dir: &PathBuf, build_src: &PathBuf) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_libxml2(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
fn build_libxml2(deps_dir: &Path, out_dir: &Path) -> PathBuf {
|
||||||
let libxml2_dir = deps_dir.join("libxml2");
|
let libxml2_dir = deps_dir.join("libxml2");
|
||||||
|
|
||||||
// The temporary location where we will build
|
// The temporary location where we will build
|
||||||
@@ -89,7 +93,7 @@ fn build_libxml2(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
|||||||
dst
|
dst
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
fn build_openconnect(deps_dir: &Path, out_dir: &Path) -> PathBuf {
|
||||||
let openconnect_dir = deps_dir.join("openconnect");
|
let openconnect_dir = deps_dir.join("openconnect");
|
||||||
let patches_dir = deps_dir.join("patches");
|
let patches_dir = deps_dir.join("patches");
|
||||||
|
|
||||||
@@ -200,6 +204,6 @@ fn main() {
|
|||||||
cc::Build::new()
|
cc::Build::new()
|
||||||
.file("src/ffi/vpn.c")
|
.file("src/ffi/vpn.c")
|
||||||
.include("src/ffi")
|
.include("src/ffi")
|
||||||
.include(&oc_dst.join("include"))
|
.include(oc_dst.join("include"))
|
||||||
.compile("vpn");
|
.compile("vpn");
|
||||||
}
|
}
|
||||||
@@ -44,11 +44,11 @@ fn find_executable(locations: &[&'static str]) -> Option<&'static str> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_vpnc_script() -> Option<&'static str> {
|
pub fn find_vpnc_script() -> Option<&'static str> {
|
||||||
find_executable(&VPNC_SCRIPT_LOCATIONS)
|
find_executable(VPNC_SCRIPT_LOCATIONS)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_csd_wrapper() -> Option<&'static str> {
|
pub fn find_csd_wrapper() -> Option<&'static str> {
|
||||||
find_executable(&CSD_WRAPPER_LOCATIONS)
|
find_executable(CSD_WRAPPER_LOCATIONS)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If file exists, check if it is executable
|
/// If file exists, check if it is executable
|
||||||
|
|||||||
Reference in new issue
Block a user