use crate::enforcement_health_v1::{EnforcementHealthV1, Mechanism, Probe, Status};
pub const COLLECTION_PATH_LANDLOCK_TCP_CONNECT: &str = "landlock-tcp-connect";
pub const COLLECTION_PATH_JSONRPC_PROXY: &str = "jsonrpc-proxy";
pub const PROXY_SOURCE_SCHEMA: &str = "assay.enforcement_decision.v0";
pub const PROXY_SEAL_SCOPE: &str = "tool_call:mcp_proxy_policy";
pub const AEE_VERSION: &str = "0.7";
pub const DROP_PROOF_SYNCHRONOUS_PROBE: &str = "synchronous-probe";
pub const DROP_PROOF_COUNTED_QUEUE_ZERO: &str = "counted-queue-zero";
const BLOCKING_ERRNO: &str = "EACCES";
const LANDLOCK_ABI_NET_CONNECT_TCP: u32 = 4;
const RESTRICTIONS_HELD: &str = "restrictions_held";
fn observed_label(probe: &Probe) -> String {
if probe.listener_reached {
"no_connect_block".to_string()
} else {
"connect_blocked".to_string()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NotSealEligible {
NotArmed { status: Status },
WrongMechanism { mechanism: Mechanism },
ScopeMismatch { found: String },
NoRunEndProbe,
ProbeReachedListener,
ProbeSignalTooWeak { errno: String },
AbiCannotExpressRestriction { abi: u32 },
RecordSelfContradictory { detail: String },
UnprovenContextValue { field: &'static str },
DerivationFailed { what: &'static str },
RestrictionSheddingNotEstablished { found: String },
ObservationsLost { channel: String, lost: u64 },
DropAccountingUnnamed,
}
impl NotSealEligible {
#[must_use]
pub fn code(&self) -> &'static str {
match self {
Self::NotArmed { .. } => "not-armed",
Self::WrongMechanism { .. } => "wrong-mechanism",
Self::ScopeMismatch { .. } => "scope-mismatch",
Self::NoRunEndProbe => "no-run-end-probe",
Self::ProbeReachedListener => "probe-reached-listener",
Self::ProbeSignalTooWeak { .. } => "probe-signal-too-weak",
Self::AbiCannotExpressRestriction { .. } => "abi-cannot-express-restriction",
Self::RecordSelfContradictory { .. } => "record-self-contradictory",
Self::UnprovenContextValue { .. } => "unproven-context-value",
Self::DerivationFailed { .. } => "derivation-failed",
Self::RestrictionSheddingNotEstablished { .. } => {
"restriction-shedding-not-established"
}
Self::ObservationsLost { .. } => "observations-lost",
Self::DropAccountingUnnamed => "drop-accounting-unnamed",
}
}
}
impl std::fmt::Display for NotSealEligible {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NotArmed { status } => write!(f, "enforcement is {status:?}, so nothing was armed for this run"),
Self::WrongMechanism { mechanism } => write!(f, "mechanism is {mechanism:?}; this seal covers Landlock only"),
Self::ScopeMismatch { found } => write!(f, "health record scope {found:?} is not the sealed scope"),
Self::NoRunEndProbe => write!(f, "no run-end probe: a start-time restrict_self confirmation proves the ruleset was applied, not that it was still applied at run end"),
Self::ProbeReachedListener => write!(f, "the run-end probe reached the listener, so the connect was not blocked"),
Self::ProbeSignalTooWeak { errno } => write!(f, "the run-end probe reported {errno:?}, which does not distinguish enforcement from an absent listener"),
Self::AbiCannotExpressRestriction { abi } => write!(f, "Landlock ABI {abi} predates LANDLOCK_ACCESS_NET_CONNECT_TCP (ABI 4), so this denial did not come from Landlock"),
Self::RecordSelfContradictory { detail } => write!(f, "health record contradicts itself: {detail}"),
Self::UnprovenContextValue { field } => write!(f, "run-context field {field} is not a value this run proved"),
Self::DerivationFailed { what } => write!(f, "could not derive a required digest: {what}"),
Self::RestrictionSheddingNotEstablished { found } => write!(
f,
"restriction-shedding was not established for this kernel ({found}); aeeStillArmed would rest on an invariant CVE-2024-42318 shows has an exception, and the Landlock ABI does not exclude it"
),
Self::ObservationsLost { channel, lost } => write!(f, "channel {channel} lost {lost} observations, so zero drop accounting cannot be carried"),
Self::DropAccountingUnnamed => write!(f, "a counted-queue model with no channels names no proof at all"),
}
}
}
pub(crate) fn is_sha256_hex(v: &str) -> bool {
v.len() == 64
&& v.bytes()
.all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b))
}
fn is_rfc3339_utc(v: &str) -> bool {
let b = v.as_bytes();
if b.len() != 20
|| b[4] != b'-'
|| b[7] != b'-'
|| b[10] != b'T'
|| b[13] != b':'
|| b[16] != b':'
|| b[19] != b'Z'
|| ![0, 1, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18]
.iter()
.all(|&i| b[i].is_ascii_digit())
{
return false;
}
let num = |a: usize, z: usize| v[a..z].parse::<u32>().unwrap_or(u32::MAX);
let (year, month, day) = (num(0, 4), num(5, 7), num(8, 10));
let (hour, minute, second) = (num(11, 13), num(14, 16), num(17, 19));
if year < 1 {
return false;
}
let leap = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
let days_in_month = match month {
1 | 3 | 5 | 7 | 8 | 10 | 12 => 31,
4 | 6 | 9 | 11 => 30,
2 if leap => 29,
2 => 28,
_ => return false,
};
(1..=days_in_month).contains(&day) && hour < 24 && minute < 60 && second < 60
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct SealPayload {
#[serde(rename = "aeeKind")]
pub aee_kind: String,
#[serde(rename = "aeeVersion")]
pub aee_version: String,
#[serde(rename = "aeeRunBinding")]
pub aee_run_binding: String,
#[serde(rename = "aeeMethod")]
pub aee_method: String,
#[serde(rename = "aeePostureDigest")]
pub aee_posture_digest: String,
#[serde(rename = "aeeStillArmed")]
pub aee_still_armed: bool,
#[serde(rename = "aeeDropCount")]
pub aee_drop_count: u64,
#[serde(rename = "aeeDropBound")]
pub aee_drop_bound: u64,
#[serde(rename = "aeeObservedSet")]
pub aee_observed_set: String,
#[serde(rename = "aeeObservedAttacks")]
pub aee_observed_attacks: Vec<String>,
#[serde(rename = "assayObservedLabels")]
pub assay_observed_labels: Vec<String>,
#[serde(rename = "assayCollectionPath")]
pub assay_collection_path: String,
#[serde(rename = "assaySealedAt")]
pub assay_sealed_at: String,
#[serde(rename = "assaySourceSchema")]
pub assay_source_schema: String,
#[serde(rename = "assaySealScope")]
pub assay_seal_scope: String,
#[serde(rename = "assayDropProofModel")]
pub assay_drop_proof_model: String,
#[serde(rename = "assayDropProofBasis")]
pub assay_drop_proof_basis: String,
#[serde(rename = "assayDropChannels")]
pub assay_drop_channels: Vec<String>,
#[serde(rename = "assayAttackRowAttributionSource")]
pub assay_attack_row_attribution_source: String,
#[serde(rename = "assayNonClaims")]
pub assay_non_claims: Vec<String>,
}
fn payload_non_claims() -> Vec<String> {
[
"does not prove complete run population",
"does not prove agent safety",
"does not prove provider side effects",
"does not prove independent substrate operation",
"does not distinguish withdrawn coverage from coverage never held",
]
.iter()
.map(|s| (*s).to_string())
.collect()
}
#[derive(Debug, Clone)]
pub struct ObservationEnvironment {
pub subject_digest: String,
pub substrate_digest: String,
pub corpus_digest: String,
pub catch_policy_digest: String,
pub observation_vocabulary_digest: String,
pub run_entropy_digest: String,
pub network_posture: serde_json::Value,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ObservationRecord {
pub payload: serde_json::Value,
#[serde(rename = "payloadType")]
pub payload_type: String,
}
const AEE_BINDING_VERSION: &str = "2";
pub const OBSERVATION_PAYLOAD_TYPE: &str =
"application/vnd.assay.aee-landlock-seal.fixture.v0+json";
fn sha256_hex(bytes: &[u8]) -> String {
use sha2::{Digest, Sha256};
hex::encode(Sha256::digest(bytes))
}
pub fn digest_json_public(value: &serde_json::Value) -> String {
digest_json(value).unwrap_or_default()
}
pub fn now_rfc3339_utc() -> String {
chrono::Utc::now().format("%Y-%m-%dT%H:%M:%SZ").to_string()
}
fn digest_json(value: &serde_json::Value) -> Result<String, NotSealEligible> {
let bytes =
assay_canonical::jcs::to_vec(value).map_err(|_| NotSealEligible::DerivationFailed {
what: "canonicalize",
})?;
Ok(sha256_hex(&bytes))
}
fn leaf_hash(rec: &ObservationRecord) -> Result<String, NotSealEligible> {
let payload = assay_canonical::jcs::to_vec(&rec.payload).map_err(|_| {
NotSealEligible::DerivationFailed {
what: "canonicalize",
}
})?;
let pae = assay_common::dsse::build_pae(&rec.payload_type, &payload);
let mut buf = Vec::with_capacity(1 + pae.len());
buf.push(0x00);
buf.extend_from_slice(&pae);
Ok(sha256_hex(&buf))
}
pub fn records_ndjson(records: &[ObservationRecord]) -> Result<String, serde_json::Error> {
let mut out = String::new();
for rec in records {
out.push_str(&serde_json::to_string(rec)?);
out.push('\n');
}
Ok(out)
}
pub fn observed_set(records: &[ObservationRecord]) -> Result<String, NotSealEligible> {
let mut leaves: Vec<String> = records
.iter()
.filter(|r| {
matches!(
r.payload.get("aeeKind").and_then(|v| v.as_str()),
Some("interception") | Some("examination")
)
})
.map(leaf_hash)
.collect::<Result<Vec<_>, _>>()?;
leaves.sort_unstable();
leaves.dedup();
digest_json(&serde_json::Value::Array(
leaves.into_iter().map(serde_json::Value::String).collect(),
))
}
pub fn run_binding(env: &ObservationEnvironment) -> Result<String, NotSealEligible> {
digest_json(&serde_json::json!({
"aeeBindingVersion": AEE_BINDING_VERSION,
"catchPolicy": env.catch_policy_digest,
"corpus": env.corpus_digest,
"networkPosture": digest_json(&env.network_posture)?,
"observationVocabulary": env.observation_vocabulary_digest,
"runEntropy": env.run_entropy_digest,
"subject": env.subject_digest,
"substrate": env.substrate_digest,
}))
}
pub fn probe_examination_record(
probe: &Probe,
run_binding: &str,
collection_path: &str,
) -> ObservationRecord {
ObservationRecord {
payload: serde_json::json!({
"aeeKind": "examination",
"aeeVersion": AEE_VERSION,
"aeeRunBinding": run_binding,
"aeeMethod": "intercepted",
"assayCollectionPath": collection_path,
"assayProbeTransport": probe.transport,
"assayProbeAction": probe.blocked_action,
"assayProbePort": probe.blocked_port,
"assayProbeErrno": probe.blocked_errno,
"assayProbeListenerReached": probe.listener_reached,
}),
payload_type: OBSERVATION_PAYLOAD_TYPE.to_string(),
}
}
#[derive(Debug, Clone)]
pub struct ProxyEnforcement {
pub enforcing: bool,
pub failure: Option<String>,
pub denial: Option<ProxyDenial>,
}
#[derive(Debug, Clone)]
pub struct ProxyDenial {
pub tool: String,
pub reason_code: String,
pub upstream_reached: bool,
}
fn armed_and_self_consistent(
armed: bool,
status: Status,
failure_recorded: bool,
) -> Result<(), NotSealEligible> {
if !armed {
return Err(NotSealEligible::NotArmed { status });
}
if failure_recorded {
return Err(NotSealEligible::RecordSelfContradictory {
detail: "status is active and a failure is recorded".into(),
});
}
Ok(())
}
pub fn proxy_seal_eligibility(e: &ProxyEnforcement) -> Result<&ProxyDenial, NotSealEligible> {
armed_and_self_consistent(
e.enforcing,
if e.enforcing {
Status::Active
} else {
Status::Failed
},
e.failure.is_some(),
)?;
let denial = e.denial.as_ref().ok_or(NotSealEligible::NoRunEndProbe)?;
if denial.upstream_reached {
return Err(NotSealEligible::ProbeReachedListener);
}
if denial.reason_code.is_empty() {
return Err(NotSealEligible::ProbeSignalTooWeak {
errno: "<empty reason code>".to_string(),
});
}
Ok(denial)
}
pub fn proxy_examination_record(
denial: &ProxyDenial,
run_binding: &str,
collection_path: &str,
) -> ObservationRecord {
ObservationRecord {
payload: serde_json::json!({
"aeeKind": "examination",
"aeeVersion": AEE_VERSION,
"aeeRunBinding": run_binding,
"aeeMethod": "intercepted",
"assayCollectionPath": collection_path,
"assayDeniedTool": denial.tool,
"assayDenialReasonCode": denial.reason_code,
"assayDenialUpstreamReached": denial.upstream_reached,
}),
payload_type: OBSERVATION_PAYLOAD_TYPE.to_string(),
}
}
pub fn seal_eligibility(health: &EnforcementHealthV1) -> Result<&Probe, NotSealEligible> {
armed_and_self_consistent(
health.status == Status::Active,
health.status,
health.failure.is_some(),
)?;
if health.mechanism != Mechanism::Landlock {
return Err(NotSealEligible::WrongMechanism {
mechanism: health.mechanism,
});
}
if health.scope != crate::enforcement_health_v1::SCOPE_TCP_CONNECT_LANDLOCK_PORT {
return Err(NotSealEligible::ScopeMismatch {
found: health.scope.clone(),
});
}
if health.landlock.abi < LANDLOCK_ABI_NET_CONNECT_TCP {
return Err(NotSealEligible::AbiCannotExpressRestriction {
abi: health.landlock.abi,
});
}
if health.landlock.net_connect_tcp_supported == Some(false) {
return Err(NotSealEligible::RecordSelfContradictory {
detail: "claims a TCP-connect restriction the record reports as unsupported".into(),
});
}
if !health.landlock.no_new_privs_confirmed || !health.landlock.restrict_self_confirmed {
return Err(NotSealEligible::RecordSelfContradictory {
detail: "status is active but the ruleset was never confirmed applied".into(),
});
}
match health.landlock.restriction_shedding.as_deref() {
Some(RESTRICTIONS_HELD) => {}
other => {
return Err(NotSealEligible::RestrictionSheddingNotEstablished {
found: other.unwrap_or("not measured").to_string(),
})
}
}
let probe = health
.probe
.as_ref()
.ok_or(NotSealEligible::NoRunEndProbe)?;
if probe.listener_reached {
return Err(NotSealEligible::ProbeReachedListener);
}
if probe.blocked_errno != BLOCKING_ERRNO {
return Err(NotSealEligible::ProbeSignalTooWeak {
errno: probe.blocked_errno.clone(),
});
}
Ok(probe)
}
#[derive(Debug, Clone)]
pub enum DropAccounting {
SynchronousProbe,
CountedQueue { channels: Vec<(String, u64)> },
}
pub const DROP_BASIS_CHECKED: &str = "checked";
pub const DROP_BASIS_ASSERTED: &str = "asserted";
impl DropAccounting {
fn basis(&self) -> &'static str {
match self {
Self::SynchronousProbe => DROP_BASIS_ASSERTED,
Self::CountedQueue { .. } => DROP_BASIS_CHECKED,
}
}
fn channel_readings(&self) -> Vec<String> {
match self {
Self::SynchronousProbe => Vec::new(),
Self::CountedQueue { channels } => channels
.iter()
.map(|(name, lost)| format!("{name}={lost}"))
.collect(),
}
}
fn model(&self) -> &'static str {
match self {
Self::SynchronousProbe => DROP_PROOF_SYNCHRONOUS_PROBE,
Self::CountedQueue { .. } => DROP_PROOF_COUNTED_QUEUE_ZERO,
}
}
fn check(&self) -> Result<(), NotSealEligible> {
match self {
Self::SynchronousProbe => Ok(()),
Self::CountedQueue { channels } => match channels.iter().find(|(_, lost)| *lost != 0) {
Some((name, lost)) => Err(NotSealEligible::ObservationsLost {
channel: name.clone(),
lost: *lost,
}),
None if channels.is_empty() => Err(NotSealEligible::DropAccountingUnnamed),
None => Ok(()),
},
}
}
}
#[derive(Debug, Clone)]
pub struct SealedRun {
pub seal: SealPayload,
pub records: Vec<ObservationRecord>,
}
pub enum Vantage<'a> {
Landlock(&'a EnforcementHealthV1),
JsonRpcProxy(&'a ProxyEnforcement),
}
enum RunEndProof<'a> {
Landlock(&'a Probe),
Proxy(&'a ProxyDenial),
}
impl<'a> Vantage<'a> {
fn check(&self) -> Result<RunEndProof<'a>, NotSealEligible> {
match self {
Self::Landlock(h) => seal_eligibility(h).map(RunEndProof::Landlock),
Self::JsonRpcProxy(e) => proxy_seal_eligibility(e).map(RunEndProof::Proxy),
}
}
fn source_schema(&self) -> String {
match self {
Self::Landlock(h) => h.schema.clone(),
Self::JsonRpcProxy(_) => PROXY_SOURCE_SCHEMA.to_string(),
}
}
fn scope(&self) -> String {
match self {
Self::Landlock(h) => h.scope.clone(),
Self::JsonRpcProxy(_) => PROXY_SEAL_SCOPE.to_string(),
}
}
fn extra_non_claims(&self) -> Vec<String> {
match self {
Self::Landlock(_) => Vec::new(),
Self::JsonRpcProxy(_) => vec![
"does not prove enforcement could not be bypassed rather than shed".to_string(),
],
}
}
}
impl RunEndProof<'_> {
fn examination(&self, rb: &str, collection_path: &str) -> ObservationRecord {
match self {
Self::Landlock(p) => probe_examination_record(p, rb, collection_path),
Self::Proxy(d) => proxy_examination_record(d, rb, collection_path),
}
}
fn label(&self) -> String {
match self {
Self::Landlock(p) => observed_label(p),
Self::Proxy(d) => {
if d.upstream_reached {
"no_call_block".to_string()
} else {
"call_blocked".to_string()
}
}
}
}
}
pub fn build_sealed_run(
vantage: Vantage<'_>,
env: &ObservationEnvironment,
prior_records: &[ObservationRecord],
sealed_at: &str,
drop_accounting: &DropAccounting,
collection_path: &str,
) -> Result<SealedRun, NotSealEligible> {
let proof = vantage.check()?;
if !is_rfc3339_utc(sealed_at) {
return Err(NotSealEligible::UnprovenContextValue { field: "sealed_at" });
}
let rb = run_binding(env)?;
let posture_digest = env
.network_posture
.get("digest")
.and_then(|d| d.get("sha256"))
.and_then(|v| v.as_str())
.filter(|v| is_sha256_hex(v))
.ok_or(NotSealEligible::UnprovenContextValue {
field: "networkPosture.digest.sha256",
})?
.to_string();
let mut records = prior_records.to_vec();
records.push(proof.examination(&rb, collection_path));
drop_accounting.check()?;
let observed = observed_set(&records)?;
Ok(SealedRun {
seal: SealPayload {
aee_kind: "sealed".to_string(),
aee_version: AEE_VERSION.to_string(),
aee_run_binding: rb,
aee_method: "intercepted".to_string(),
aee_posture_digest: posture_digest,
aee_still_armed: true,
aee_drop_count: 0,
aee_drop_bound: 0,
aee_observed_set: observed,
aee_observed_attacks: Vec::new(),
assay_observed_labels: vec![proof.label()],
assay_collection_path: collection_path.to_string(),
assay_sealed_at: sealed_at.to_string(),
assay_source_schema: vantage.source_schema(),
assay_seal_scope: vantage.scope(),
assay_drop_proof_model: drop_accounting.model().to_string(),
assay_drop_proof_basis: drop_accounting.basis().to_string(),
assay_drop_channels: drop_accounting.channel_readings(),
assay_attack_row_attribution_source: "assembly-plane".to_string(),
assay_non_claims: {
let mut n = payload_non_claims();
n.extend(vantage.extra_non_claims());
n
},
},
records,
})
}
#[cfg(test)]
mod tests {
use super::*;
use crate::enforcement_health_v1::{EnforcementHealthV1, Failure, ReasonCode};
const PARITY: &str = include_str!(
"../../../scripts/experiments/fixtures/aee-landlock-seal/derivation-parity.json"
);
fn probe(listener_reached: bool, errno: &str) -> Probe {
Probe {
kind: "real_block".into(),
transport: "ipv4".into(),
blocked_action: "tcp_connect".into(),
blocked_port: 4444,
blocked_errno: errno.into(),
listener_reached,
}
}
fn healthy() -> EnforcementHealthV1 {
EnforcementHealthV1::landlock_active(
4,
vec![443],
Some(probe(false, "EACCES")),
Some("restrictions_held".to_string()),
)
}
fn parity() -> serde_json::Value {
serde_json::from_str(PARITY).expect("parity vectors parse")
}
fn env_from_parity() -> ObservationEnvironment {
let p = parity();
let e = &p["environment"];
let g = |k: &str| e[k].as_str().expect("digest").to_string();
ObservationEnvironment {
subject_digest: g("subject"),
substrate_digest: g("substrate"),
corpus_digest: g("corpus"),
catch_policy_digest: g("catchPolicy"),
observation_vocabulary_digest: g("observationVocabulary"),
run_entropy_digest: g("runEntropy"),
network_posture: e["networkPosture"].clone(),
}
}
fn refusal(h: &EnforcementHealthV1) -> &'static str {
build_sealed_run(
Vantage::Landlock(h),
&env_from_parity(),
&[],
"2026-08-05T00:00:00Z",
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.expect_err("must refuse")
.code()
}
#[test]
fn run_binding_matches_the_checker() {
let p = parity();
assert_eq!(
run_binding(&env_from_parity()).unwrap(),
p["expected"]["runBinding"].as_str().unwrap()
);
}
#[test]
fn the_seal_carries_the_declared_posture_digest_not_the_object_digest() {
let p = parity();
let env = env_from_parity();
let run = build_sealed_run(
Vantage::Landlock(&healthy()),
&env,
&[],
"2026-08-05T00:00:00Z",
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.unwrap();
assert_eq!(
run.seal.aee_posture_digest,
p["expected"]["networkPostureDigest"].as_str().unwrap()
);
assert_ne!(
run.seal.aee_posture_digest,
digest_json(&env.network_posture).unwrap(),
"the run-binding input is the value the ADR names as the wrong one"
);
}
#[test]
fn a_posture_without_a_declared_digest_is_refused() {
for posture in [
serde_json::json!({"mode": "deny-default"}),
serde_json::json!({"mode": "deny-default", "digest": {}}),
serde_json::json!({"mode": "deny-default", "digest": {"sha256": "NOT-HEX"}}),
] {
let mut env = env_from_parity();
env.network_posture = posture;
assert!(
build_sealed_run(
Vantage::Landlock(&healthy()),
&env,
&[],
"2026-08-05T00:00:00Z",
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.is_err(),
"a posture that declares no usable digest must not seal"
);
}
}
#[test]
fn observed_set_matches_the_checker_over_the_same_records() {
let p = parity();
let records: Vec<ObservationRecord> = p["records"]
.as_array()
.unwrap()
.iter()
.map(|r| ObservationRecord {
payload: r["payload"].clone(),
payload_type: r["payloadType"].as_str().unwrap().to_string(),
})
.collect();
assert_eq!(
observed_set(&records).unwrap(),
p["expected"]["observedSet"].as_str().unwrap()
);
}
#[test]
fn the_leaf_sort_is_observable_and_matches_the_checker() {
let p = parity();
let records: Vec<ObservationRecord> = p["orderingRecords"]
.as_array()
.expect("ordering vector present")
.iter()
.map(|r| ObservationRecord {
payload: r["payload"].clone(),
payload_type: r["payloadType"].as_str().unwrap().to_string(),
})
.collect();
let leaves: Vec<String> = records.iter().map(|r| leaf_hash(r).unwrap()).collect();
let mut sorted = leaves.clone();
sorted.sort_unstable();
assert_ne!(
leaves, sorted,
"the vector must emit out of sorted order, or this test proves nothing"
);
assert_eq!(
observed_set(&records).unwrap(),
p["expected"]["orderingObservedSet"].as_str().unwrap()
);
}
#[test]
fn the_seal_commits_to_the_probe_examination_leaf() {
let run = build_sealed_run(
Vantage::Landlock(&healthy()),
&env_from_parity(),
&[],
"2026-08-05T00:00:00Z",
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.unwrap();
let probe_rec = run
.records
.iter()
.find(|r| r.payload["aeeKind"] == "examination")
.expect("the probe is emitted as an examination record");
assert_eq!(
run.seal.aee_observed_set,
observed_set(std::slice::from_ref(probe_rec)).unwrap()
);
assert_ne!(
run.seal.aee_observed_set,
observed_set(&[]).unwrap(),
"an empty set is not a commitment to anything"
);
}
#[test]
fn a_run_carrying_an_interception_can_still_seal() {
let prior = vec![ObservationRecord {
payload: serde_json::json!({"aeeKind": "interception", "aeeVersion": "0.7", "x": 1}),
payload_type: OBSERVATION_PAYLOAD_TYPE.to_string(),
}];
let run = build_sealed_run(
Vantage::Landlock(&healthy()),
&env_from_parity(),
&prior,
"2026-08-05T00:00:00Z",
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.expect("an interception must not block the seal");
assert_eq!(run.records.len(), 2);
assert_ne!(
run.seal.aee_observed_set,
observed_set(&run.records[1..]).unwrap(),
"dropping the interception must move the commitment"
);
}
#[test]
fn a_counted_queue_that_lost_an_observation_is_refused() {
let lossy = DropAccounting::CountedQueue {
channels: vec![("probe-ring".into(), 0), ("event-ring".into(), 1)],
};
let err = build_sealed_run(
Vantage::Landlock(&healthy()),
&env_from_parity(),
&[],
"2026-08-05T00:00:00Z",
&lossy,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.expect_err("a lost observation cannot carry zero");
assert_eq!(err.code(), "observations-lost");
let empty = DropAccounting::CountedQueue { channels: vec![] };
assert_eq!(
build_sealed_run(
Vantage::Landlock(&healthy()),
&env_from_parity(),
&[],
"2026-08-05T00:00:00Z",
&empty,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.expect_err("no channels proves nothing")
.code(),
"drop-accounting-unnamed"
);
let clean = DropAccounting::CountedQueue {
channels: vec![("probe-ring".into(), 0)],
};
let run = build_sealed_run(
Vantage::Landlock(&healthy()),
&env_from_parity(),
&[],
"2026-08-05T00:00:00Z",
&clean,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.expect("all counters zero");
assert_eq!(
run.seal.assay_drop_proof_model, DROP_PROOF_COUNTED_QUEUE_ZERO,
"the payload names the model the caller proved, not a constant"
);
assert_eq!(run.seal.assay_drop_proof_basis, DROP_BASIS_CHECKED);
assert_eq!(
run.seal.assay_drop_channels,
vec!["probe-ring=0".to_string()]
);
}
#[test]
fn every_carried_value_lands_in_its_own_payload_field() {
let p = parity();
let h = healthy();
let run = build_sealed_run(
Vantage::Landlock(&h),
&env_from_parity(),
&[],
"2026-08-05T12:34:56Z",
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.unwrap();
let s = &run.seal;
assert_eq!(s.aee_kind, "sealed");
assert_eq!(s.aee_version, "0.7");
assert_eq!(s.aee_method, "intercepted");
assert!(s.aee_still_armed);
assert_eq!((s.aee_drop_count, s.aee_drop_bound), (0, 0));
assert_eq!(
s.aee_run_binding,
p["expected"]["runBinding"].as_str().unwrap()
);
assert_eq!(
s.aee_posture_digest,
p["expected"]["networkPostureDigest"].as_str().unwrap()
);
assert_eq!(s.aee_observed_set, observed_set(&run.records).unwrap());
assert!(s.aee_observed_attacks.is_empty());
assert_eq!(
s.assay_collection_path,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT
);
assert_eq!(s.assay_sealed_at, "2026-08-05T12:34:56Z");
assert_eq!(s.assay_source_schema, h.schema);
assert_eq!(s.assay_seal_scope, h.scope);
assert_eq!(s.assay_drop_proof_model, DROP_PROOF_SYNCHRONOUS_PROBE);
assert_eq!(
s.assay_drop_proof_basis, DROP_BASIS_ASSERTED,
"a caller declaration is not a check, and the payload must say which it was"
);
assert!(
s.assay_drop_channels.is_empty(),
"nothing was read, so nothing is carried"
);
assert_eq!(s.assay_attack_row_attribution_source, "assembly-plane");
assert_eq!(s.assay_observed_labels, vec!["connect_blocked".to_string()]);
assert_eq!(
s.assay_non_claims,
vec![
"does not prove complete run population".to_string(),
"does not prove agent safety".to_string(),
"does not prove provider side effects".to_string(),
"does not prove independent substrate operation".to_string(),
"does not distinguish withdrawn coverage from coverage never held".to_string(),
]
);
}
#[test]
fn the_payload_member_names_are_the_ones_the_checker_reads() {
let run = build_sealed_run(
Vantage::Landlock(&healthy()),
&env_from_parity(),
&[],
"2026-08-05T00:00:00Z",
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.unwrap();
let value = serde_json::to_value(&run.seal).unwrap();
let mut got: Vec<&str> = value
.as_object()
.unwrap()
.keys()
.map(String::as_str)
.collect();
got.sort_unstable();
assert_eq!(
got,
[
"aeeDropBound",
"aeeDropCount",
"aeeKind",
"aeeMethod",
"aeeObservedAttacks",
"aeeObservedSet",
"aeePostureDigest",
"aeeRunBinding",
"aeeStillArmed",
"aeeVersion",
"assayAttackRowAttributionSource",
"assayCollectionPath",
"assayDropChannels",
"assayDropProofBasis",
"assayDropProofModel",
"assayNonClaims",
"assayObservedLabels",
"assaySealScope",
"assaySealedAt",
"assaySourceSchema",
]
);
}
#[test]
fn the_examination_record_carries_the_probe_it_was_built_from() {
let h = healthy();
let probe = h.probe.as_ref().unwrap().clone();
let run = build_sealed_run(
Vantage::Landlock(&h),
&env_from_parity(),
&[],
"2026-08-05T00:00:00Z",
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.unwrap();
let e = run
.records
.iter()
.find(|r| r.payload["aeeKind"] == "examination")
.unwrap();
assert_eq!(
e.payload_type,
"application/vnd.assay.aee-landlock-seal.fixture.v0+json"
);
assert_eq!(e.payload["aeeRunBinding"], run.seal.aee_run_binding);
assert_eq!(e.payload["aeeVersion"], "0.7");
assert_eq!(e.payload["aeeMethod"], "intercepted");
assert_eq!(
e.payload["assayCollectionPath"],
COLLECTION_PATH_LANDLOCK_TCP_CONNECT
);
assert_eq!(e.payload["assayProbeTransport"], probe.transport);
assert_eq!(e.payload["assayProbeAction"], probe.blocked_action);
assert_eq!(e.payload["assayProbePort"], probe.blocked_port);
assert_eq!(e.payload["assayProbeErrno"], probe.blocked_errno);
assert_eq!(
e.payload["assayProbeListenerReached"],
probe.listener_reached
);
}
#[test]
fn a_calendar_invalid_instant_is_refused() {
for bad in [
"2026-02-30T00:00:00Z",
"9999-99-99T99:99:99Z",
"2026-08-05T24:00:00Z",
"2027-02-29T00:00:00Z",
"2026-00-05T00:00:00Z",
"2026-08-00T00:00:00Z",
"2100-02-29T00:00:00Z",
"0000-01-01T00:00:00Z",
"2026-06-30T23:59:60Z",
] {
assert!(
build_sealed_run(
Vantage::Landlock(&healthy()),
&env_from_parity(),
&[],
bad,
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.is_err(),
"sealed_at {bad:?} must be refused"
);
}
for good in ["2028-02-29T23:59:59Z", "2000-02-29T23:59:59Z"] {
assert!(
build_sealed_run(
Vantage::Landlock(&healthy()),
&env_from_parity(),
&[],
good,
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.is_ok(),
"{good:?} is a real leap day and must still seal"
);
}
}
#[test]
fn a_run_without_a_run_end_probe_is_refused() {
let h = EnforcementHealthV1::landlock_active(
4,
vec![443],
None,
Some("restrictions_held".to_string()),
);
assert!(
h.landlock.restrict_self_confirmed,
"the start-time fact is present"
);
assert_eq!(refusal(&h), "no-run-end-probe");
}
#[test]
fn an_abi_that_cannot_express_the_restriction_is_refused() {
for abi in [1, 2, 3] {
let h = EnforcementHealthV1::landlock_active(
abi,
vec![443],
Some(probe(false, "EACCES")),
Some("restrictions_held".to_string()),
);
assert_eq!(refusal(&h), "abi-cannot-express-restriction", "abi {abi}");
}
}
#[test]
fn weak_and_absent_block_signals_are_refused() {
for errno in ["ECONNREFUSED", "ETIMEDOUT", "", "eacces", "EACCES "] {
let h = EnforcementHealthV1::landlock_active(
4,
vec![443],
Some(probe(false, errno)),
Some("restrictions_held".to_string()),
);
assert_eq!(refusal(&h), "probe-signal-too-weak", "errno {errno:?}");
}
let h = EnforcementHealthV1::landlock_active(
4,
vec![443],
Some(probe(true, "EACCES")),
Some("restrictions_held".to_string()),
);
assert_eq!(refusal(&h), "probe-reached-listener");
}
#[test]
fn a_record_that_contradicts_itself_is_refused() {
let mut h = healthy();
h.failure = Some(Failure {
reason_code: ReasonCode::RestrictSelfFailed,
detail: "x".into(),
});
assert_eq!(refusal(&h), "record-self-contradictory");
let mut h = healthy();
h.landlock.restrict_self_confirmed = false;
assert_eq!(refusal(&h), "record-self-contradictory");
let mut h = healthy();
h.landlock.net_connect_tcp_supported = Some(false);
assert_eq!(refusal(&h), "record-self-contradictory");
}
#[test]
fn a_seal_instant_that_is_not_an_instant_is_refused() {
for bad in [
"yesterday afternoon",
"",
"2026-08-05",
"2026-08-05T00:00:00",
] {
assert!(
build_sealed_run(
Vantage::Landlock(&healthy()),
&env_from_parity(),
&[],
bad,
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.is_err(),
"sealed_at {bad:?} must be refused"
);
}
}
#[test]
fn derived_fields_come_from_the_record_not_from_constants() {
let mut h = healthy();
h.schema = "assay.enforcement_health.v0".into();
let run = build_sealed_run(
Vantage::Landlock(&h),
&env_from_parity(),
&[],
"2026-08-05T00:00:00Z",
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.unwrap();
assert_eq!(
run.seal.assay_source_schema, "assay.enforcement_health.v0",
"must not relabel the artifact"
);
assert_eq!(
run.seal.assay_seal_scope, h.scope,
"the seal scope is the record's, not a constant"
);
}
#[test]
fn a_record_that_never_measured_shedding_does_not_seal() {
let raw = include_str!(
"../tests/fixtures/enforcement_health/v1/active_probe_shedding_unmeasured.json"
);
let h: EnforcementHealthV1 = serde_json::from_str(raw).expect("fixture parses");
let err = build_sealed_run(
Vantage::Landlock(&h),
&env_from_parity(),
&[],
"2026-08-05T00:00:00Z",
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.expect_err("a record with no measurement must not seal");
assert_eq!(err.code(), "restriction-shedding-not-established");
assert!(err.to_string().contains("not measured"), "{err}");
}
#[test]
fn a_shed_or_inconclusive_measurement_does_not_seal() {
for value in ["restrictions_shed", "inconclusive"] {
let mut h = healthy();
h.landlock.restriction_shedding = Some(value.to_string());
let err = build_sealed_run(
Vantage::Landlock(&h),
&env_from_parity(),
&[],
"2026-08-05T00:00:00Z",
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.expect_err("must not seal");
assert_eq!(err.code(), "restriction-shedding-not-established");
assert!(err.to_string().contains(value), "{err}");
}
}
#[test]
fn the_committed_carrier_fixture_still_parses_and_seals_through_the_commitment() {
let raw = include_str!("../tests/fixtures/enforcement_health/v1/active_with_probe.json");
let h: EnforcementHealthV1 = serde_json::from_str(raw).expect("fixture parses");
let run = build_sealed_run(
Vantage::Landlock(&h),
&env_from_parity(),
&[],
"2026-08-05T00:00:00Z",
&DropAccounting::SynchronousProbe,
COLLECTION_PATH_LANDLOCK_TCP_CONNECT,
)
.expect("eligible");
assert_eq!(
run.records.len(),
1,
"the probe is the only committed observation"
);
assert_eq!(
run.seal.aee_observed_set,
observed_set(&run.records).unwrap()
);
}
}