101 lines
3.5 KiB
Rust
101 lines
3.5 KiB
Rust
//! Retirement of an additional development-only scope after its exact probe.
|
|
//! This administrative receipt is neither a job approval nor a readiness lease.
|
|
use crate::{checkpoint_repair::inventory_sha256, windows_echo_probe::ProbeScope};
|
|
use chrono::{DateTime, Duration, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::{Value, json};
|
|
use uuid::Uuid;
|
|
|
|
pub const DOMAIN: &str = "rmm.dev.windows-echo-completion.v1";
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct Witness {
|
|
pub scope: ProbeScope,
|
|
pub probe_receipt_id: Uuid,
|
|
pub probe_receipt_sha256: String,
|
|
pub probe_signature_sha256: String,
|
|
pub grant_id: Uuid,
|
|
pub grant_payload_sha256: String,
|
|
pub grant_signature_sha256: String,
|
|
pub outcome_sha256: String,
|
|
pub boot_id: Uuid,
|
|
}
|
|
impl Witness {
|
|
pub fn digest(&self) -> Option<String> {
|
|
inventory_sha256(&serde_json::to_value(self).ok()?).ok()
|
|
}
|
|
pub fn valid(&self) -> bool {
|
|
!self.probe_receipt_id.is_nil()
|
|
&& !self.grant_id.is_nil()
|
|
&& !self.boot_id.is_nil()
|
|
&& [
|
|
&self.probe_receipt_sha256,
|
|
&self.probe_signature_sha256,
|
|
&self.grant_payload_sha256,
|
|
&self.grant_signature_sha256,
|
|
&self.outcome_sha256,
|
|
]
|
|
.iter()
|
|
.all(|h| {
|
|
h.len() == 64
|
|
&& h.bytes()
|
|
.all(|c| c.is_ascii_digit() || (b'a'..=b'f').contains(&c))
|
|
})
|
|
}
|
|
}
|
|
|
|
/// Both server result and retained native Outcome use this one comparison.
|
|
pub fn successful_outcome(v: &Value) -> bool {
|
|
v["state"] == "succeeded"
|
|
&& v["exit_code"] == 0
|
|
&& v["stdout"] == json!(crate::windows_echo_probe::OUTPUT.as_bytes())
|
|
&& v["stderr"] == json!([])
|
|
&& v["output_truncated"] == false
|
|
&& v["reboot_required"] == false
|
|
&& v["error_code"] == ""
|
|
&& v["evidence"]["postconditions_passed"] == true
|
|
&& v["evidence"]["execution_sid"] == "S-1-5-19"
|
|
&& v["evidence"]["execution_policy_scope"] == "process"
|
|
&& v["evidence"]["execution_policy_requested"] == "RemoteSigned"
|
|
&& v["evidence"]["script_sha256"]
|
|
== crate::jobs::hash(crate::windows_echo_probe::SCRIPT.as_bytes())
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct Receipt {
|
|
pub domain: String,
|
|
pub schema_version: u32,
|
|
pub receipt_id: Uuid,
|
|
pub witness: Witness,
|
|
pub witness_sha256: String,
|
|
pub key_id: String,
|
|
pub issued_at: DateTime<Utc>,
|
|
pub valid_until: DateTime<Utc>,
|
|
pub confirmed_by: String,
|
|
pub approval_origin: String,
|
|
pub testsimulation: bool,
|
|
pub ready: bool,
|
|
pub helper_ready: bool,
|
|
pub unlock: bool,
|
|
}
|
|
impl Receipt {
|
|
pub fn valid(&self, now: DateTime<Utc>) -> bool {
|
|
self.domain == DOMAIN
|
|
&& self.schema_version == 1
|
|
&& !self.receipt_id.is_nil()
|
|
&& self.witness.valid()
|
|
&& self.witness.digest().as_deref() == Some(self.witness_sha256.as_str())
|
|
&& self.confirmed_by == crate::windows_echo_probe::TEST_PRINCIPAL
|
|
&& self.approval_origin == "dev_test_browser_simulation"
|
|
&& self.testsimulation
|
|
&& !self.ready
|
|
&& !self.helper_ready
|
|
&& !self.unlock
|
|
&& self.issued_at <= now
|
|
&& now < self.valid_until
|
|
&& self.valid_until - self.issued_at <= Duration::minutes(10)
|
|
}
|
|
}
|