Integrate signed agent catalog, tenant enrollment and HTTPS installers
This commit is contained in:
@@ -36,8 +36,8 @@ pub const PIPE_NAME: &str = r"\\.\pipe\RustDiscovery-System-v2";
|
||||
pub const TIME_PIPE_NAME: &str = r"\\.\pipe\RustDiscovery-System-Time-v1";
|
||||
const FRAME_TAG: [u8; 8] = *b"RDPIPC02";
|
||||
const DRAIN_TAG: [u8; 8] = *b"RDPACK02";
|
||||
const FRAME_HEADER_LEN: usize = 12;
|
||||
const DRAIN_RECEIPT_LEN: usize = 56;
|
||||
pub(crate) const FRAME_HEADER_LEN: usize = 12;
|
||||
pub(crate) const DRAIN_RECEIPT_LEN: usize = 56;
|
||||
pub const FRAME_LIMIT: usize = 1024 * 1024;
|
||||
pub const CLIENT_PIPE_RIGHTS: u32 = 0x0012_0083; // data R/W, attributes R, RC, synchronize; no bit4
|
||||
const READ_MASK: u32 = 0x0012_00a9;
|
||||
@@ -302,6 +302,8 @@ pub enum Operation {
|
||||
generation: u64,
|
||||
},
|
||||
Probe {},
|
||||
UpdateObserve {request:crate::update_observer::Request},
|
||||
UpdateHealth {request:rmm_agent_core::update_handoff::NativeControlRequest},
|
||||
Snapshot {
|
||||
generation: u64,
|
||||
},
|
||||
@@ -361,10 +363,17 @@ pub enum ReplyBody {
|
||||
ready: bool,
|
||||
ledger: FileIdentity,
|
||||
lock: FileIdentity,
|
||||
#[serde(default,skip_serializing_if="Option::is_none")]
|
||||
reboot_privilege_available:Option<bool>,
|
||||
/// Passive protocol negotiation only; no update capability/readiness.
|
||||
#[serde(default,skip_serializing_if="Option::is_none")]
|
||||
update_observer_configured:Option<bool>,
|
||||
},
|
||||
Snapshot {
|
||||
snapshot: Snapshot,
|
||||
},
|
||||
UpdateObservation {response:Box<crate::update_observer::Response>},
|
||||
UpdateHealth {reply:Box<rmm_agent_core::update_handoff::NativeControlReply>},
|
||||
Applied {
|
||||
snapshot: Snapshot,
|
||||
unlocked_grants: Vec<Uuid>,
|
||||
@@ -374,6 +383,9 @@ pub enum ReplyBody {
|
||||
Executed {
|
||||
outcome: Outcome,
|
||||
},
|
||||
UpdateAccepted {
|
||||
accepted: crate::update_admission::Accepted,
|
||||
},
|
||||
Abandoned {
|
||||
outcome: Outcome,
|
||||
},
|
||||
@@ -408,7 +420,7 @@ pub fn binding_hash(b: &Binding) -> Result<String> {
|
||||
pub fn wide(s: impl AsRef<std::ffi::OsStr>) -> Vec<u16> {
|
||||
s.as_ref().encode_wide().chain(Some(0)).collect()
|
||||
}
|
||||
fn owned(raw: HANDLE) -> Result<OwnedHandle> {
|
||||
pub(crate) fn owned(raw: HANDLE) -> Result<OwnedHandle> {
|
||||
if raw.is_null() || raw == INVALID_HANDLE_VALUE {
|
||||
return Err(api_failure("HELPER_HANDLE"));
|
||||
}
|
||||
@@ -540,7 +552,7 @@ pub fn require_self(peer: &PeerPin) -> Result<()> {
|
||||
let token = owned(token)?;
|
||||
verify_token(token.as_raw_handle(), &peer.user_sid, &peer.service_sid)
|
||||
}
|
||||
fn check_acl(
|
||||
pub(crate) fn check_acl(
|
||||
handle: HANDLE,
|
||||
readers: &[String],
|
||||
writers: &[String],
|
||||
@@ -801,7 +813,7 @@ impl Drop for ServiceHandle {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn service_status(pin: &PeerPin) -> Result<u32> {
|
||||
pub(crate) fn service_status(pin: &PeerPin) -> Result<u32> {
|
||||
let manager =
|
||||
ServiceHandle(unsafe { OpenSCManagerW(ptr::null(), ptr::null(), SC_MANAGER_CONNECT) });
|
||||
ensure!(!manager.0.is_null(), "HELPER_SCM_MANAGER");
|
||||
@@ -906,7 +918,7 @@ impl ProcessIdentity {
|
||||
}
|
||||
}
|
||||
impl PeerProof {
|
||||
fn capture(pipe: HANDLE, pin: &PeerPin, client: bool) -> Result<Self> {
|
||||
pub(crate) fn capture(pipe: HANDLE, pin: &PeerPin, client: bool) -> Result<Self> {
|
||||
let mut pid = 0;
|
||||
ensure!(
|
||||
unsafe {
|
||||
@@ -923,7 +935,7 @@ impl PeerProof {
|
||||
}
|
||||
/// Internal fixture admission shares the exact same live-process proof as
|
||||
/// both pipe peers. The caller supplies the PID read from its held SCM handle.
|
||||
pub(crate) fn for_service(pin: &PeerPin, pid: u32) -> Result<Self> {
|
||||
pub fn for_service(pin: &PeerPin, pid: u32) -> Result<Self> {
|
||||
ensure!(pid == service_status(pin)?, "HELPER_PIPE_SCM_PID");
|
||||
let process =
|
||||
owned(unsafe { OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE, 0, pid) })?;
|
||||
@@ -1040,9 +1052,9 @@ impl PeerProof {
|
||||
}
|
||||
}
|
||||
|
||||
struct Descriptor(*mut c_void);
|
||||
pub(crate) struct Descriptor(pub(crate) *mut c_void);
|
||||
impl Descriptor {
|
||||
fn from(s: &str) -> Result<Self> {
|
||||
pub(crate) fn from(s: &str) -> Result<Self> {
|
||||
let mut descriptor = ptr::null_mut();
|
||||
ensure!(
|
||||
unsafe {
|
||||
@@ -1106,18 +1118,18 @@ fn pipe_descriptor(agent: &str, helper: &str) -> Result<Descriptor> {
|
||||
))
|
||||
}
|
||||
|
||||
struct IoEvent {
|
||||
pub(crate) struct IoEvent {
|
||||
event: OwnedHandle,
|
||||
overlapped: OVERLAPPED,
|
||||
pub(crate) overlapped: OVERLAPPED,
|
||||
}
|
||||
impl IoEvent {
|
||||
fn new() -> Result<Self> {
|
||||
pub(crate) fn new() -> Result<Self> {
|
||||
let event = owned(unsafe { CreateEventW(ptr::null(), 1, 0, ptr::null()) })?;
|
||||
let mut overlapped: OVERLAPPED = unsafe { zeroed() };
|
||||
overlapped.hEvent = event.as_raw_handle();
|
||||
Ok(Self { event, overlapped })
|
||||
}
|
||||
fn wait(&mut self, pipe: HANDLE, deadline: Instant) -> Result<u32> {
|
||||
pub(crate) fn wait(&mut self, pipe: HANDLE, deadline: Instant) -> Result<u32> {
|
||||
let left = deadline.saturating_duration_since(Instant::now());
|
||||
let milliseconds = u32::try_from(left.as_millis().max(1)).unwrap_or(u32::MAX - 1);
|
||||
if unsafe { WaitForSingleObject(self.event.as_raw_handle(), milliseconds) } != WAIT_OBJECT_0
|
||||
@@ -1167,7 +1179,7 @@ impl IoEvent {
|
||||
Ok(count)
|
||||
}
|
||||
}
|
||||
fn transfer(pipe: HANDLE, bytes: &mut [u8], write: bool, deadline: Instant) -> Result<()> {
|
||||
pub(crate) fn transfer(pipe: HANDLE, bytes: &mut [u8], write: bool, deadline: Instant) -> Result<()> {
|
||||
let mut offset = 0;
|
||||
while offset < bytes.len() {
|
||||
ensure!(Instant::now() < deadline, "HELPER_PIPE_TIMEOUT");
|
||||
@@ -1222,7 +1234,7 @@ impl Write for LimitedJson {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
fn encode(value: &impl Serialize) -> Result<Vec<u8>> {
|
||||
pub(crate) fn encode(value: &impl Serialize) -> Result<Vec<u8>> {
|
||||
let mut writer = LimitedJson(Vec::with_capacity(FRAME_LIMIT));
|
||||
serde_json::to_writer(&mut writer, value)?;
|
||||
ensure!(!writer.0.is_empty(), "HELPER_FRAME_EMPTY");
|
||||
@@ -1235,12 +1247,12 @@ fn frame_header(len: usize) -> Result<[u8; FRAME_HEADER_LEN]> {
|
||||
header[8..].copy_from_slice(&u32::try_from(len)?.to_be_bytes());
|
||||
Ok(header)
|
||||
}
|
||||
fn send_bytes(pipe: HANDLE, bytes: &mut [u8], deadline: Instant) -> Result<()> {
|
||||
pub(crate) fn send_bytes(pipe: HANDLE, bytes: &mut [u8], deadline: Instant) -> Result<()> {
|
||||
let mut header = frame_header(bytes.len())?;
|
||||
transfer(pipe, &mut header, true, deadline)?;
|
||||
transfer(pipe, bytes, true, deadline)
|
||||
}
|
||||
fn send(pipe: HANDLE, value: &impl Serialize, deadline: Instant) -> Result<()> {
|
||||
pub(crate) fn send(pipe: HANDLE, value: &impl Serialize, deadline: Instant) -> Result<()> {
|
||||
send_bytes(pipe, &mut encode(value)?, deadline)
|
||||
}
|
||||
fn frame_length(header: [u8; FRAME_HEADER_LEN]) -> Result<usize> {
|
||||
@@ -1249,30 +1261,30 @@ fn frame_length(header: [u8; FRAME_HEADER_LEN]) -> Result<usize> {
|
||||
ensure!((1..=FRAME_LIMIT).contains(&len), "HELPER_FRAME_LENGTH");
|
||||
Ok(len)
|
||||
}
|
||||
fn length(pipe: HANDLE, deadline: Instant) -> Result<usize> {
|
||||
pub(crate) fn length(pipe: HANDLE, deadline: Instant) -> Result<usize> {
|
||||
let mut header = [0u8; FRAME_HEADER_LEN];
|
||||
transfer(pipe, &mut header, false, deadline)?;
|
||||
frame_length(header)
|
||||
}
|
||||
fn body_bytes(pipe: HANDLE, len: usize, deadline: Instant) -> Result<Vec<u8>> {
|
||||
pub(crate) fn body_bytes(pipe: HANDLE, len: usize, deadline: Instant) -> Result<Vec<u8>> {
|
||||
ensure!((1..=FRAME_LIMIT).contains(&len), "HELPER_FRAME_LENGTH");
|
||||
let mut bytes = vec![0u8; len];
|
||||
transfer(pipe, &mut bytes, false, deadline)?;
|
||||
Ok(bytes)
|
||||
}
|
||||
fn body<T: DeserializeOwned>(pipe: HANDLE, len: usize, deadline: Instant) -> Result<T> {
|
||||
pub(crate) fn body<T: DeserializeOwned>(pipe: HANDLE, len: usize, deadline: Instant) -> Result<T> {
|
||||
Ok(serde_json::from_slice(&body_bytes(pipe, len, deadline)?)?)
|
||||
}
|
||||
// This fixed-size receipt only acknowledges receipt of these transport bytes.
|
||||
// It never acknowledges durable evidence, clears state, or permits an effect.
|
||||
fn drain_receipt(challenge: Uuid, reply_bytes: &[u8]) -> [u8; DRAIN_RECEIPT_LEN] {
|
||||
pub(crate) fn drain_receipt(challenge: Uuid, reply_bytes: &[u8]) -> [u8; DRAIN_RECEIPT_LEN] {
|
||||
let mut receipt = [0; DRAIN_RECEIPT_LEN];
|
||||
receipt[..8].copy_from_slice(&DRAIN_TAG);
|
||||
receipt[8..24].copy_from_slice(challenge.as_bytes());
|
||||
receipt[24..].copy_from_slice(&Sha256::digest(reply_bytes));
|
||||
receipt
|
||||
}
|
||||
fn verify_drain_receipt(
|
||||
pub(crate) fn verify_drain_receipt(
|
||||
receipt: &[u8; DRAIN_RECEIPT_LEN],
|
||||
challenge: Uuid,
|
||||
reply_bytes: &[u8],
|
||||
@@ -1470,8 +1482,11 @@ fn exchange_fixed(pin: &Pin, call: &Call, timeout: Duration, time_only: bool) ->
|
||||
(_, ReplyBody::Denied { .. })
|
||||
| (Operation::Probe { .. }, ReplyBody::Probe { .. })
|
||||
| (Operation::Snapshot { .. }, ReplyBody::Snapshot { .. })
|
||||
| (Operation::UpdateHealth {..},ReplyBody::UpdateHealth{..})
|
||||
| (Operation::UpdateObserve {..},ReplyBody::UpdateObservation{..})
|
||||
| (Operation::Apply { .. }, ReplyBody::Applied { .. })
|
||||
| (Operation::Execute { .. }, ReplyBody::Executed { .. })
|
||||
| (Operation::Execute { .. }, ReplyBody::UpdateAccepted { .. })
|
||||
| (Operation::Abandon { .. }, ReplyBody::Abandoned { .. })
|
||||
| (Operation::TimeBegin { .. }, ReplyBody::TimeChallenge { .. })
|
||||
| (
|
||||
|
||||
Reference in New Issue
Block a user