Integrate independent signed Windows clocks with native Linux lease guards
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -33,6 +33,7 @@ pub const HELPER_SERVICE: &str = "RmmDiscoverySystemHelper";
|
||||
// Framing v2 is deliberately a separate endpoint. Old peers cannot send a
|
||||
// v1 call to this server or interpret the drain receipt as another reply.
|
||||
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;
|
||||
@@ -289,6 +290,17 @@ impl Pin {
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[serde(tag = "operation", rename_all = "snake_case", deny_unknown_fields)]
|
||||
pub enum Operation {
|
||||
TimeBegin {
|
||||
generation: u64,
|
||||
},
|
||||
TimeComplete {
|
||||
generation: u64,
|
||||
response_bytes: Vec<u8>,
|
||||
},
|
||||
/// Deny-only transport/context fence. It cannot qualify a clock or lease.
|
||||
TimeClose {
|
||||
generation: u64,
|
||||
},
|
||||
Probe {},
|
||||
Snapshot {
|
||||
generation: u64,
|
||||
@@ -308,6 +320,14 @@ pub enum Operation {
|
||||
intent_sha256: String,
|
||||
},
|
||||
}
|
||||
impl Operation {
|
||||
fn time_only(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Self::TimeBegin { .. } | Self::TimeComplete { .. } | Self::TimeClose { .. }
|
||||
)
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Call {
|
||||
@@ -331,6 +351,11 @@ impl Call {
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
|
||||
pub enum ReplyBody {
|
||||
TimeChallenge {
|
||||
request: rmm_time_attestation::Request,
|
||||
},
|
||||
TimeCompleted {},
|
||||
TimeClosed {},
|
||||
Probe {
|
||||
clock_qualified: bool,
|
||||
ready: bool,
|
||||
@@ -1261,6 +1286,7 @@ fn verify_drain_receipt(
|
||||
pub struct Server {
|
||||
pipe: OwnedHandle,
|
||||
pin: Pin,
|
||||
time_only: bool,
|
||||
}
|
||||
pub struct Received {
|
||||
pub call: Call,
|
||||
@@ -1268,6 +1294,12 @@ pub struct Received {
|
||||
}
|
||||
impl Server {
|
||||
pub fn bind(pin: Pin) -> Result<Self> {
|
||||
Self::bind_fixed(pin, false)
|
||||
}
|
||||
pub fn bind_time(pin: Pin) -> Result<Self> {
|
||||
Self::bind_fixed(pin, true)
|
||||
}
|
||||
fn bind_fixed(pin: Pin, time_only: bool) -> Result<Self> {
|
||||
pin.validate()?;
|
||||
require_self(&pin.helper)?;
|
||||
let descriptor = pipe_descriptor(&pin.agent.service_sid, &pin.helper.service_sid)?;
|
||||
@@ -1278,7 +1310,7 @@ impl Server {
|
||||
};
|
||||
let pipe = owned(unsafe {
|
||||
CreateNamedPipeW(
|
||||
wide(PIPE_NAME).as_ptr(),
|
||||
wide(if time_only { TIME_PIPE_NAME } else { PIPE_NAME }).as_ptr(),
|
||||
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE,
|
||||
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS,
|
||||
1,
|
||||
@@ -1288,7 +1320,11 @@ impl Server {
|
||||
&security,
|
||||
)
|
||||
})?;
|
||||
Ok(Self { pipe, pin })
|
||||
Ok(Self {
|
||||
pipe,
|
||||
pin,
|
||||
time_only,
|
||||
})
|
||||
}
|
||||
pub fn receive(&self) -> Result<Option<Received>> {
|
||||
let pipe = self.pipe.as_raw_handle();
|
||||
@@ -1341,6 +1377,10 @@ impl Server {
|
||||
auth.context(Stage::ServerVerifyToken)?;
|
||||
require_self(&self.pin.helper).context(Stage::ServerVerifyToken)?;
|
||||
let call: Call = body(pipe, len, deadline).context(Stage::ServerReadBody)?;
|
||||
ensure!(
|
||||
call.operation.time_only() == self.time_only,
|
||||
"HELPER_PIPE_OPERATION_SCOPE"
|
||||
);
|
||||
if !(call.schema_version == 1
|
||||
&& !call.challenge.is_nil()
|
||||
&& call.policy_sha256 == self.pin.policy_sha256
|
||||
@@ -1378,6 +1418,16 @@ impl Server {
|
||||
}
|
||||
/// Blocking SDK call; run on the agent's bounded blocking worker, never heartbeat reactor.
|
||||
pub fn exchange(pin: &Pin, call: &Call, timeout: Duration) -> Result<Reply> {
|
||||
exchange_fixed(pin, call, timeout, false)
|
||||
}
|
||||
pub fn exchange_time(pin: &Pin, call: &Call, timeout: Duration) -> Result<Reply> {
|
||||
exchange_fixed(pin, call, timeout, true)
|
||||
}
|
||||
fn exchange_fixed(pin: &Pin, call: &Call, timeout: Duration, time_only: bool) -> Result<Reply> {
|
||||
ensure!(
|
||||
call.operation.time_only() == time_only,
|
||||
"HELPER_PIPE_OPERATION_SCOPE"
|
||||
);
|
||||
pin.validate()?;
|
||||
require_self(&pin.agent).context(Stage::ClientSelfRole)?;
|
||||
ensure!(
|
||||
@@ -1387,7 +1437,7 @@ pub fn exchange(pin: &Pin, call: &Call, timeout: Duration) -> Result<Reply> {
|
||||
let deadline = Instant::now() + timeout;
|
||||
let pipe = owned(unsafe {
|
||||
CreateFileW(
|
||||
wide(PIPE_NAME).as_ptr(),
|
||||
wide(if time_only { TIME_PIPE_NAME } else { PIPE_NAME }).as_ptr(),
|
||||
CLIENT_PIPE_RIGHTS,
|
||||
0,
|
||||
ptr::null(),
|
||||
@@ -1422,6 +1472,12 @@ pub fn exchange(pin: &Pin, call: &Call, timeout: Duration) -> Result<Reply> {
|
||||
| (Operation::Apply { .. }, ReplyBody::Applied { .. })
|
||||
| (Operation::Execute { .. }, ReplyBody::Executed { .. })
|
||||
| (Operation::Abandon { .. }, ReplyBody::Abandoned { .. })
|
||||
| (Operation::TimeBegin { .. }, ReplyBody::TimeChallenge { .. })
|
||||
| (
|
||||
Operation::TimeComplete { .. },
|
||||
ReplyBody::TimeCompleted { .. }
|
||||
)
|
||||
| (Operation::TimeClose { .. }, ReplyBody::TimeClosed { .. })
|
||||
) {
|
||||
return Err(anyhow::anyhow!("HELPER_REPLY_OPERATION")).context(Stage::ClientReplyBinding);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user