Skip to main content

qualia_core_db/net/qdnf/harness/
qualification.rs

1//! E00 qualification classes, fingerprints and fail-closed gates.
2//!
3//! Component table tests cannot certify encryption, payload authenticity or
4//! allocation interception. A failing instrument fails the qualification set.
5
6use crate::net::qdnf::errors::QdnfError;
7
8/// Evidence class. Mixing these into one “all tests passed” claim is forbidden.
9#[repr(u8)]
10#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11pub enum EvidenceClass {
12    Component = 1,
13    Process = 2,
14    PhysicalNetwork = 3,
15    Application = 4,
16}
17
18/// Named qualification instrument. Each has a negative-control that must fire.
19#[repr(u8)]
20#[derive(Clone, Copy, Debug, PartialEq, Eq)]
21pub enum Instrument {
22    AllocatorIntercept = 1,
23    WirePayloadOracle = 2,
24    CryptoOracle = 3,
25    GraphOracle = 4,
26}
27
28#[repr(u8)]
29#[derive(Clone, Copy, Debug, PartialEq, Eq)]
30pub enum InstrumentVerdict {
31    Pass = 1,
32    Fail = 2,
33    Unsupported = 3,
34}
35
36/// One recorded instrument result. `component_tables_pass` is observational.
37#[derive(Clone, Copy, Debug, PartialEq, Eq)]
38pub struct InstrumentResult {
39    pub instrument: Instrument,
40    pub class: EvidenceClass,
41    pub verdict: InstrumentVerdict,
42    pub component_tables_pass: bool,
43}
44
45/// Qualification fails when encryption, payload verification or allocation
46/// interception fails, even if every state-table unit test passed.
47pub fn qualify(results: &[InstrumentResult]) -> Result<(), QdnfError> {
48    let mut i = 0;
49    while i < results.len() {
50        let r = results[i];
51        let critical = matches!(
52            r.instrument,
53            Instrument::AllocatorIntercept
54                | Instrument::WirePayloadOracle
55                | Instrument::CryptoOracle
56        );
57        if critical && r.verdict == InstrumentVerdict::Fail {
58            return Err(QdnfError::Denied);
59        }
60        i += 1;
61    }
62    Ok(())
63}
64
65/// Linux native runner recorded at E00. MSVC is not claimed from this host.
66pub const LINUX_NATIVE_RUNNER: &str = "linux-x86_64-gnu rustc-1.98.1 cargo-1.98.1";
67pub const MSVC_RUNNER: Option<&str> = None;
68pub const BASELINE_COMMIT: &str = "5646b818d4e6fa63f0b7c4c6a1a469dca382339a";
69pub const REVIEW_BASELINE_COMMIT: &str = "17b6b467c8a4548e302f603674dd594a67be7398";
70
71#[cfg(test)]
72mod tests {
73    use super::*;
74
75    #[test]
76    fn encryption_failure_fails_qualification_despite_table_passes() {
77        let results = [InstrumentResult {
78            instrument: Instrument::CryptoOracle,
79            class: EvidenceClass::Component,
80            verdict: InstrumentVerdict::Fail,
81            component_tables_pass: true,
82        }];
83        assert_eq!(qualify(&results), Err(QdnfError::Denied));
84    }
85
86    #[test]
87    fn payload_oracle_failure_fails_qualification() {
88        let results = [InstrumentResult {
89            instrument: Instrument::WirePayloadOracle,
90            class: EvidenceClass::Process,
91            verdict: InstrumentVerdict::Fail,
92            component_tables_pass: true,
93        }];
94        assert_eq!(qualify(&results), Err(QdnfError::Denied));
95    }
96
97    #[test]
98    fn allocator_intercept_failure_fails_qualification() {
99        let results = [InstrumentResult {
100            instrument: Instrument::AllocatorIntercept,
101            class: EvidenceClass::Component,
102            verdict: InstrumentVerdict::Fail,
103            component_tables_pass: true,
104        }];
105        assert_eq!(qualify(&results), Err(QdnfError::Denied));
106    }
107
108    #[test]
109    fn passing_instruments_qualify() {
110        let results = [
111            InstrumentResult {
112                instrument: Instrument::AllocatorIntercept,
113                class: EvidenceClass::Component,
114                verdict: InstrumentVerdict::Pass,
115                component_tables_pass: true,
116            },
117            InstrumentResult {
118                instrument: Instrument::WirePayloadOracle,
119                class: EvidenceClass::Process,
120                verdict: InstrumentVerdict::Pass,
121                component_tables_pass: true,
122            },
123            InstrumentResult {
124                instrument: Instrument::CryptoOracle,
125                class: EvidenceClass::Component,
126                verdict: InstrumentVerdict::Pass,
127                component_tables_pass: true,
128            },
129        ];
130        assert!(qualify(&results).is_ok());
131    }
132
133    #[test]
134    fn msvc_runner_is_explicitly_unavailable_here() {
135        assert!(MSVC_RUNNER.is_none());
136        assert!(LINUX_NATIVE_RUNNER.contains("linux"));
137    }
138}