Prove actual Windows agent process identity under SYSTEM diagnostic
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
//! Negative, read-only raw Probe clients. Never SDK self-refusal as server proof.
|
||||
//! The permanent services, their tokens/configuration and private state stay intact.
|
||||
// Compile the unchanged production proof in this diagnostic crate. Keeping the
|
||||
// module public avoids hiding its public transport API behind dead-code lint;
|
||||
// no new API is exported from the agent library.
|
||||
#[cfg(all(windows, feature = "system-helper"))]
|
||||
#[path = "../src/helper_ipc.rs"]
|
||||
pub mod helper_ipc;
|
||||
#[cfg(all(windows, feature = "system-helper"))]
|
||||
pub use rmm_agent_windows::SERVICE_NAME;
|
||||
#[cfg(all(windows, feature = "system-helper"))]
|
||||
mod platform {
|
||||
use crate::helper_ipc as ipc;
|
||||
use anyhow::{Result, ensure};
|
||||
use rmm_agent_windows::helper_ipc as ipc;
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
use std::{
|
||||
@@ -35,6 +43,7 @@ mod platform {
|
||||
const ROOT: &str = r"C:\ProgramData\RustDiscoveryPeerControls";
|
||||
static CASE: OnceLock<uuid::Uuid> = OnceLock::new();
|
||||
static IS_PARENT: OnceLock<bool> = OnceLock::new();
|
||||
static DIRECT_PEER_PROOF: OnceLock<bool> = OnceLock::new();
|
||||
static STATUS: AtomicUsize = AtomicUsize::new(0);
|
||||
fn wide(s: &str) -> Vec<u16> {
|
||||
s.encode_utf16().chain(Some(0)).collect()
|
||||
@@ -866,6 +875,33 @@ mod platform {
|
||||
&json!({"schema_version":1,"case_id":case,"source":"own_system_fixed_child_controller","result":result,"no_jobs":true,"read_only":true,"token_exported":false}),
|
||||
)
|
||||
}
|
||||
fn direct_peer_proof(case: uuid::Uuid) -> Result<()> {
|
||||
let identity = token("parent")?;
|
||||
save(case, "parent-token.json", &identity)?;
|
||||
let input = read_input(case)?;
|
||||
let began = Instant::now();
|
||||
let proof = (|| -> Result<serde_json::Value> {
|
||||
let mut peer = ipc::PeerProof::for_service(&input.pin.agent, input.expected_agent_pid)?;
|
||||
ensure!(
|
||||
peer.identity().creation_ticks == input.expected_agent_creation,
|
||||
"CONTROL_ORIGINAL_AGENT_BIRTH"
|
||||
);
|
||||
ensure!(!peer.exited()?, "CONTROL_ORIGINAL_AGENT_EXITED");
|
||||
peer.check()?;
|
||||
Ok(serde_json::to_value(peer.identity())?)
|
||||
})();
|
||||
let result = match proof {
|
||||
Ok(actual) => json!({"direct_agent_peer_proof":true,"verified":true,"identity":actual}),
|
||||
Err(error) => {
|
||||
json!({"direct_agent_peer_proof":true,"verified":false,"error_codes":codes(&error)})
|
||||
}
|
||||
};
|
||||
save(
|
||||
case,
|
||||
"parent-result.json",
|
||||
&json!({"schema_version":1,"case_id":case,"source":"own_system_direct_production_agent_peer_proof","result":result,"elapsed_ms":began.elapsed().as_millis(),"expected_agent_pid":input.expected_agent_pid,"expected_agent_creation":input.expected_agent_creation,"no_jobs":true,"read_only":true,"pipe_used":false,"token_duplicated":false,"token_exported":false,"service_or_process_acl_changed":false}),
|
||||
)
|
||||
}
|
||||
fn status(state: u32, error: u32) {
|
||||
let handle = STATUS.load(Ordering::SeqCst) as SERVICE_STATUS_HANDLE;
|
||||
if handle.is_null() {
|
||||
@@ -911,7 +947,11 @@ mod platform {
|
||||
STATUS.store(handle as usize, Ordering::SeqCst);
|
||||
status(SERVICE_RUNNING, 0);
|
||||
let result = if *IS_PARENT.get().unwrap_or(&false) {
|
||||
parent(*CASE.get().unwrap())
|
||||
if *DIRECT_PEER_PROOF.get().unwrap_or(&false) {
|
||||
direct_peer_proof(*CASE.get().unwrap())
|
||||
} else {
|
||||
parent(*CASE.get().unwrap())
|
||||
}
|
||||
} else {
|
||||
run(*CASE.get().unwrap(), "service")
|
||||
};
|
||||
@@ -924,7 +964,7 @@ mod platform {
|
||||
args.len() == 2
|
||||
&& matches!(
|
||||
args[0].as_str(),
|
||||
"--admin" | "--service" | "--agent-child" | "--parent"
|
||||
"--admin" | "--service" | "--agent-child" | "--parent" | "--peer-proof"
|
||||
),
|
||||
"CONTROL_FIXED_MODE"
|
||||
);
|
||||
@@ -940,11 +980,14 @@ mod platform {
|
||||
return run(case, "child");
|
||||
}
|
||||
IS_PARENT
|
||||
.set(args[0] == "--parent")
|
||||
.set(matches!(args[0].as_str(), "--parent" | "--peer-proof"))
|
||||
.map_err(|_| anyhow::anyhow!("CONTROL_MODE_ALREADY_SET"))?;
|
||||
DIRECT_PEER_PROOF
|
||||
.set(args[0] == "--peer-proof")
|
||||
.map_err(|_| anyhow::anyhow!("CONTROL_MODE_ALREADY_SET"))?;
|
||||
CASE.set(case)
|
||||
.map_err(|_| anyhow::anyhow!("CONTROL_CASE_ALREADY_SET"))?;
|
||||
let mut name = wide(if args[0] == "--parent" {
|
||||
let mut name = wide(if matches!(args[0].as_str(), "--parent" | "--peer-proof") {
|
||||
PARENT_NAME
|
||||
} else {
|
||||
NAME
|
||||
|
||||
Reference in New Issue
Block a user