1#![allow(dead_code)]
10
11use serde::Serialize;
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
15pub enum FrameworkId {
16 Soc2TypeII,
17 Iso27001,
18 Fips140_3,
19 CcEal4Plus,
20}
21
22impl FrameworkId {
23 pub fn as_str(&self) -> &'static str {
24 match self {
25 FrameworkId::Soc2TypeII => "soc2_type_ii",
26 FrameworkId::Iso27001 => "iso_27001",
27 FrameworkId::Fips140_3 => "fips_140_3",
28 FrameworkId::CcEal4Plus => "cc_eal4_plus",
29 }
30 }
31}
32
33#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
35pub enum EvidenceKind {
36 CompileTime,
37 RuntimeInvariant,
38 AutomatedArtifact,
39 TestSuite,
40 ManualPolicy,
41 ExternalOperational,
42}
43
44impl EvidenceKind {
45 pub fn as_str(&self) -> &'static str {
46 match self {
47 EvidenceKind::CompileTime => "compile_time",
48 EvidenceKind::RuntimeInvariant => "runtime_invariant",
49 EvidenceKind::AutomatedArtifact => "automated_artifact",
50 EvidenceKind::TestSuite => "test_suite",
51 EvidenceKind::ManualPolicy => "manual_policy",
52 EvidenceKind::ExternalOperational => "external_operational",
53 }
54 }
55}
56
57#[derive(Debug, Clone)]
59pub struct Control {
60 pub framework: FrameworkId,
61 pub control_id: &'static str,
62 pub title: &'static str,
63 pub axon_primitive: &'static str,
64 pub evidence_kind: EvidenceKind,
65 pub evidence_locator: &'static str,
66}
67
68impl Control {
69 pub fn key(&self) -> String {
70 format!("{}:{}", self.framework.as_str(), self.control_id)
71 }
72}
73
74macro_rules! ctl {
75 ($fw:ident, $id:expr, $title:expr, $prim:expr, $kind:ident, $loc:expr) => {
76 Control {
77 framework: FrameworkId::$fw,
78 control_id: $id,
79 title: $title,
80 axon_primitive: $prim,
81 evidence_kind: EvidenceKind::$kind,
82 evidence_locator: $loc,
83 }
84 };
85}
86
87fn soc2_controls() -> Vec<Control> {
89 vec![
90 ctl!(Soc2TypeII, "CC1.1", "Commitment to integrity", "Zero-shortcuts policy + signed commits", ManualPolicy, "CODE_OF_CONDUCT.md (repo-external)"),
91 ctl!(Soc2TypeII, "CC2.1", "Quality information", "axon check compile-time compliance", CompileTime, "axon.compiler.type_checker._check_regulatory_compliance"),
92 ctl!(Soc2TypeII, "CC3.1", "Objectives specification", "manifest.compliance declares system's κ", CompileTime, "axon.compiler.ast_nodes.ManifestDefinition"),
93 ctl!(Soc2TypeII, "CC3.2", "Risk identification", "immune + KL-divergence baseline", RuntimeInvariant, "axon.runtime.immune.AnomalyDetector"),
94 ctl!(Soc2TypeII, "CC3.3", "Fraud potential", "reflex action quarantine/terminate", RuntimeInvariant, "axon.runtime.immune.ReflexEngine"),
95 ctl!(Soc2TypeII, "CC4.1", "Control activities", "ESK 6 subsystems", TestSuite, "tests/test_phase6_*.py"),
96 ctl!(Soc2TypeII, "CC4.2", "Technology controls", "shield + type checker + Phase 4 pass", CompileTime, "axon.compiler.type_checker"),
97 ctl!(Soc2TypeII, "CC5.1", "Policies deployment", "axonendpoint.shield binding", CompileTime, "axon.compiler.ast_nodes.AxonEndpointDefinition"),
98 ctl!(Soc2TypeII, "CC6.1", "Logical access controls", "Secret[T] with audit trail", RuntimeInvariant, "axon.runtime.esk.Secret"),
99 ctl!(Soc2TypeII, "CC6.2", "Credential provisioning", "Handler-level credential + CT-3 classification", RuntimeInvariant, "axon.runtime.handlers.base"),
100 ctl!(Soc2TypeII, "CC6.3", "Access modification/removal", "lease τ-decay", RuntimeInvariant, "axon.runtime.lease_kernel.LeaseKernel"),
101 ctl!(Soc2TypeII, "CC6.6", "Boundary access controls", "axonendpoint.shield mandatory", CompileTime, "_check_regulatory_compliance"),
102 ctl!(Soc2TypeII, "CC6.7", "Information transmission restriction", "Secret[T] no-materialize", RuntimeInvariant, "tests/test_phase6_runtime.py::TestSecret"),
103 ctl!(Soc2TypeII, "CC6.8", "Unauthorized change prevention", "ProvenanceChain Merkle", RuntimeInvariant, "axon.runtime.esk.ProvenanceChain"),
104 ctl!(Soc2TypeII, "CC7.1", "Event detection", "immune + EID", RuntimeInvariant, "axon.runtime.esk.EpistemicIntrusionDetector"),
105 ctl!(Soc2TypeII, "CC7.2", "Anomaly monitoring", "KL-based AnomalyDetector", RuntimeInvariant, "axon.runtime.immune.AnomalyDetector"),
106 ctl!(Soc2TypeII, "CC7.3", "Incident evaluation", "EID severity mapping", RuntimeInvariant, "axon.runtime.esk.eid.IntrusionEvent"),
107 ctl!(Soc2TypeII, "CC7.4", "Incident response", "reflex + heal linear", RuntimeInvariant, "axon.runtime.immune.HealKernel"),
108 ctl!(Soc2TypeII, "CC7.5", "Recovery", "reconcile Active Inference", RuntimeInvariant, "axon.runtime.reconcile_loop.ReconcileLoop"),
109 ctl!(Soc2TypeII, "CC8.1", "Change authorization", "SBOM deterministic content_hash", AutomatedArtifact, "axon sbom CLI"),
110 ctl!(Soc2TypeII, "CC9.1", "Risk mitigation activities", "PrivacyBudget ε-tracker", RuntimeInvariant, "axon.runtime.esk.PrivacyBudget"),
111 ctl!(Soc2TypeII, "CC9.2", "Vendor risk management", "SBOM dependencies list", AutomatedArtifact, "axon sbom CLI"),
112 ctl!(Soc2TypeII, "C1.1", "Confidential information identification", "type κ annotation", CompileTime, "TypeDefinition.compliance"),
113 ctl!(Soc2TypeII, "C1.2", "Confidential information disposal", "lease τ-decay + Secret audit", RuntimeInvariant, "LeaseKernel + Secret.audit_trail"),
114 ctl!(Soc2TypeII, "PI1.1", "Processing objectives", "axon check passes ⟺ objectives met", CompileTime, "axon check exit 0"),
115 ctl!(Soc2TypeII, "PI1.4", "Output completeness", "Byzantine ensemble quorum", RuntimeInvariant, "axon.runtime.ensemble_aggregator"),
116 ctl!(Soc2TypeII, "PI1.5", "Information retention", "ProvenanceChain append-only", RuntimeInvariant, "ProvenanceChain.append"),
117 ctl!(Soc2TypeII, "P1.1", "Notice to data subjects", "dossier classes_covered", AutomatedArtifact, "axon dossier CLI"),
118 ctl!(Soc2TypeII, "P4.1", "Collection limitation", "Differential Privacy mechanisms", RuntimeInvariant, "axon.runtime.esk.privacy"),
119 ctl!(Soc2TypeII, "P5.1", "Data subject access", "Secret audit + ProvenanceChain", RuntimeInvariant, "Secret.audit_trail"),
120 ctl!(Soc2TypeII, "P6.1", "Disclosure restriction", "shield<GDPR> mandatory gate", CompileTime, "_check_regulatory_compliance"),
121 ]
122}
123
124fn iso_27001_controls() -> Vec<Control> {
126 vec![
127 ctl!(Iso27001, "A.5.1", "Information security policies", "manifest.compliance declarations", CompileTime, "ManifestDefinition"),
128 ctl!(Iso27001, "A.5.2", "Security roles", "heal.mode human_in_loop", RuntimeInvariant, "HealDefinition.mode"),
129 ctl!(Iso27001, "A.5.3", "Segregation of duties", "shield.allow_tools / deny_tools", CompileTime, "ShieldDefinition"),
130 ctl!(Iso27001, "A.5.7", "Threat intelligence", "immune baseline-learned KL", RuntimeInvariant, "AnomalyDetector"),
131 ctl!(Iso27001, "A.5.8", "InfoSec in project management", "CI axon check gate", ExternalOperational, ".github/workflows/*.yml"),
132 ctl!(Iso27001, "A.5.23", "Cloud services InfoSec", "Handler protocol abstraction", RuntimeInvariant, "axon.runtime.handlers"),
133 ctl!(Iso27001, "A.5.24", "Incident management planning", "immune+reflex+heal+EID", RuntimeInvariant, "axon.runtime.immune + esk.eid"),
134 ctl!(Iso27001, "A.5.25", "Event assessment", "EID classify_severity", RuntimeInvariant, "EpistemicIntrusionDetector.observe"),
135 ctl!(Iso27001, "A.5.26", "Incident response", "reflex signed_trace", RuntimeInvariant, "ReflexEngine"),
136 ctl!(Iso27001, "A.5.27", "Learning from incidents", "ProvenanceChain ledger", AutomatedArtifact, "ProvenanceChain.entries"),
137 ctl!(Iso27001, "A.5.28", "Evidence collection", "Merkle chain + HMAC", AutomatedArtifact, "ProvenanceChain.append"),
138 ctl!(Iso27001, "A.5.30", "Business continuity ICT", "reconcile self-healing", RuntimeInvariant, "ReconcileLoop"),
139 ctl!(Iso27001, "A.5.33", "Records protection", "Immutable ProvenanceChain + SBOM", AutomatedArtifact, "axon sbom"),
140 ctl!(Iso27001, "A.5.34", "Privacy / PII protection", "compliance [GDPR, CCPA] + PrivacyBudget + Secret[T]", CompileTime, "TypeDefinition.compliance + PrivacyBudget"),
141 ctl!(Iso27001, "A.5.36", "Compliance with policies", "axon check enforces RTT", CompileTime, "_check_regulatory_compliance"),
142 ctl!(Iso27001, "A.8.1", "User endpoint devices", "axonendpoint.shield gate", CompileTime, "AxonEndpointDefinition"),
143 ctl!(Iso27001, "A.8.2", "Privileged access rights", "lease τ-decay", RuntimeInvariant, "LeaseKernel"),
144 ctl!(Iso27001, "A.8.3", "Information access restriction", "shield.allow_tools + Secret[T]", RuntimeInvariant, "ShieldDefinition + Secret"),
145 ctl!(Iso27001, "A.8.5", "Secure authentication", "Handler credential flow + CT-3", RuntimeInvariant, "axon.runtime.handlers"),
146 ctl!(Iso27001, "A.8.6", "Capacity management", "resource.capacity + manifest.zones", CompileTime, "ResourceDefinition"),
147 ctl!(Iso27001, "A.8.7", "Protection against malware", "immune behavioral detection", RuntimeInvariant, "AnomalyDetector + ReflexEngine"),
148 ctl!(Iso27001, "A.8.8", "Technical vulnerability management", "heal + human_in_loop + signed", RuntimeInvariant, "HealKernel"),
149 ctl!(Iso27001, "A.8.9", "Configuration management", "deterministic SBOM program_hash", AutomatedArtifact, "axon sbom"),
150 ctl!(Iso27001, "A.8.10", "Information deletion", "lease on_expire anchor_breach", RuntimeInvariant, "LeaseKernel"),
151 ctl!(Iso27001, "A.8.12", "Data leakage prevention", "Secret[T] no-materialize", RuntimeInvariant, "tests/test_phase6_runtime.py::TestSecret"),
152 ctl!(Iso27001, "A.8.13", "Information backup", "resource.lifetime persistent + axonstore", CompileTime, "ResourceDefinition"),
153 ctl!(Iso27001, "A.8.15", "Logging", "reflex HMAC signed_trace", RuntimeInvariant, "ReflexEngine"),
154 ctl!(Iso27001, "A.8.16", "Monitoring", "immune continuous sensing", RuntimeInvariant, "AnomalyDetector"),
155 ctl!(Iso27001, "A.8.17", "Clock synchronization", "ISO-8601 UTC timestamps", RuntimeInvariant, "LambdaEnvelope.tau"),
156 ctl!(Iso27001, "A.8.20", "Network security", "Handler CT-3 partition classification", RuntimeInvariant, "NetworkPartitionError"),
157 ctl!(Iso27001, "A.8.23", "Web filtering", "shield.scan threat categories", CompileTime, "ShieldDefinition.scan"),
158 ctl!(Iso27001, "A.8.24", "Use of cryptography", "HmacSigner + Ed25519Signer + DilithiumSigner", RuntimeInvariant, "axon.runtime.esk.provenance"),
159 ctl!(Iso27001, "A.8.25", "SDL", "axon check CI gate", ExternalOperational, ".github/workflows"),
160 ctl!(Iso27001, "A.8.26", "Application security requirements", "compliance declarations", CompileTime, "TypeDefinition + ShieldDefinition"),
161 ctl!(Iso27001, "A.8.27", "Secure architecture", "π-calculus + Linear + Separation Logic compile-time", CompileTime, "type_checker.*"),
162 ctl!(Iso27001, "A.8.28", "Secure coding", "Compile-time type errors (Theorem 5.1)", CompileTime, "paper_lambda_lineal_epistemico.md"),
163 ctl!(Iso27001, "A.8.29", "Security testing", "pytest 3680 tests", TestSuite, "tests/"),
164 ctl!(Iso27001, "A.8.30", "Outsourced development", "Dual-remote strategy + SBOM", AutomatedArtifact, "DEVELOPMENT.md + axon sbom"),
165 ctl!(Iso27001, "A.8.31", "Dev/test/prod separation", "fabric.ephemeral", CompileTime, "FabricDefinition"),
166 ctl!(Iso27001, "A.8.32", "Change management", "deterministic SBOM diff", AutomatedArtifact, "axon sbom"),
167 ctl!(Iso27001, "A.8.33", "Test information", "DP-noise test data", RuntimeInvariant, "laplace_noise / gaussian_noise"),
168 ]
169}
170
171fn fips_140_3_controls() -> Vec<Control> {
173 vec![
174 ctl!(Fips140_3, "FIPS.ALG_APPROVED", "Only FIPS-approved algorithms used", "HMAC-SHA256 + SHA-256 + Ed25519 + ML-DSA-65", RuntimeInvariant, "axon.runtime.esk.provenance"),
175 ctl!(Fips140_3, "FIPS.BOUNDARY", "Cryptographic boundary defined", "ESK-CB: provenance.py + secret.py + attestation.py", ManualPolicy, "docs/compliance/fips_140_3_submission_template.md"),
176 ctl!(Fips140_3, "FIPS.FSM", "Finite State Model", "POWER-OFF → INITIALIZED → OPERATIONAL", ManualPolicy, "docs/compliance/fips_140_3_submission_template.md §6"),
177 ctl!(Fips140_3, "FIPS.KAT_HMAC", "HMAC-SHA256 Known Answer Test", "Test with fixed key/message → known tag", TestSuite, "tests/test_phase6_runtime.py"),
178 ctl!(Fips140_3, "FIPS.KAT_SHA", "SHA-256 Known Answer Test", "SHA-256('abc') verification", TestSuite, "tests/test_phase6_runtime.py"),
179 ctl!(Fips140_3, "FIPS.KAT_ED25519", "Ed25519 KAT (NIST CAVP vectors)", "Pending: Ed25519 KAT test", TestSuite, "PENDING"),
180 ctl!(Fips140_3, "FIPS.PCT", "Pairwise consistency test Ed25519", "generate → sign → verify", TestSuite, "tests/test_phase6_runtime.py"),
181 ctl!(Fips140_3, "FIPS.RNG", "Approved RNG source", "Python secrets.token_bytes (OS CSPRNG)", RuntimeInvariant, "HmacSigner.random"),
182 ctl!(Fips140_3, "FIPS.CT_COMPARE", "Constant-time comparisons", "hmac.compare_digest for MAC verify", RuntimeInvariant, "HmacSigner.verify"),
183 ctl!(Fips140_3, "FIPS.KEY_LIFECYCLE", "Key zeroization on dispose", "Garbage collection + no plaintext in repr", RuntimeInvariant, "Secret[T] invariant"),
184 ctl!(Fips140_3, "FIPS.DELIVERY", "Secure delivery procedures", "PyPI package + GitHub release signatures", ExternalOperational, "pyproject.toml + release workflow"),
185 ctl!(Fips140_3, "FIPS.SELF_TEST", "Pre-operational self-test on load", "Pending: module-load KAT execution", TestSuite, "PENDING"),
186 ctl!(Fips140_3, "FIPS.LAB_CAVP", "CAVP algorithm testing", "Business: engage NIST-accredited lab", ExternalOperational, "PENDING (external)"),
187 ctl!(Fips140_3, "FIPS.CMVP", "CMVP module validation", "Business: submission to NIST", ExternalOperational, "PENDING (external)"),
188 ]
189}
190
191fn cc_eal4_plus_controls() -> Vec<Control> {
193 vec![
194 ctl!(CcEal4Plus, "FAU_GEN.1", "Audit data generation", "ReflexOutcome + ProvenanceChain", RuntimeInvariant, "ProvenanceChain.append"),
196 ctl!(CcEal4Plus, "FAU_GEN.2", "User identity association", "Secret.audit_trail accessor", RuntimeInvariant, "SecretAccess"),
197 ctl!(CcEal4Plus, "FAU_SAR.1", "Audit review", "axon dossier / sbom + chain.entries()", AutomatedArtifact, "CLI commands"),
198 ctl!(CcEal4Plus, "FAU_STG.1", "Protected audit storage", "Merkle append-only chain", RuntimeInvariant, "ProvenanceChain"),
199 ctl!(CcEal4Plus, "FCO_NRO.1", "Proof of origin", "Ed25519Signer / DilithiumSigner", RuntimeInvariant, "provenance.py"),
201 ctl!(CcEal4Plus, "FCS_COP.1", "Cryptographic operation", "HMAC-SHA256 + Ed25519 + Dilithium3", RuntimeInvariant, "provenance.py"),
203 ctl!(CcEal4Plus, "FCS_CKM.1", "Key generation", "HmacSigner.random via secrets.token_bytes", RuntimeInvariant, "HmacSigner"),
204 ctl!(CcEal4Plus, "FDP_ACC.1", "Access control (coverage rule)", "κ(shield) ⊇ κ(body)∪κ(output)", CompileTime, "_check_regulatory_compliance"),
206 ctl!(CcEal4Plus, "FDP_IFC.1", "Information flow control", "κ propagation through types", CompileTime, "TypeDefinition + type_checker"),
207 ctl!(CcEal4Plus, "FDP_IFF.1", "Security attributes", "compliance: [HIPAA,...] annotation", CompileTime, "TypeDefinition"),
208 ctl!(CcEal4Plus, "FDP_ITC.2", "Import with attributes", "manifest.compliance at ingest boundary", CompileTime, "ManifestDefinition"),
209 ctl!(CcEal4Plus, "FIA_UAU.1", "Authentication timing", "Handler-level credential flow", RuntimeInvariant, "axon.runtime.handlers"),
211 ctl!(CcEal4Plus, "FMT_MSA.1", "Security attribute management", "Only shield definitions set compliance", CompileTime, "ShieldDefinition.compliance"),
213 ctl!(CcEal4Plus, "FMT_SMR.1", "Security roles", "Crypto Officer + User + Reviewer (heal.mode)", RuntimeInvariant, "HealDefinition.mode"),
214 ctl!(CcEal4Plus, "FPR_PSE.1", "Pseudonymity", "DP Laplace mechanism", RuntimeInvariant, "laplace_noise"),
216 ctl!(CcEal4Plus, "FPR_UNL.1", "Unlinkability", "DP Gaussian with composition", RuntimeInvariant, "gaussian_noise + PrivacyBudget"),
217 ctl!(CcEal4Plus, "FPT_TST.1", "TSF testing", "pytest 3680 tests", TestSuite, "tests/"),
219 ctl!(CcEal4Plus, "FPT_ITC.1", "Inter-TSF confidentiality", "Secret[T] no-materialize", RuntimeInvariant, "Secret"),
220 ctl!(CcEal4Plus, "FRU_RSA.1", "Maximum quotas", "resource.capacity + heal.max_patches", CompileTime, "ResourceDefinition + HealDefinition"),
222 ctl!(CcEal4Plus, "FTP_ITC.1", "Inter-TSF trusted channel", "Operator's TLS stack (outside TOE)", ExternalOperational, "PENDING (operator-provided)"),
224 ctl!(CcEal4Plus, "ALC_FLR.2", "Flaw reporting procedures", "GitHub Issues SLA", ExternalOperational, "SECURITY.md (organization-authored)"),
226 ctl!(CcEal4Plus, "AVA_VAN.5", "Advanced vulnerability analysis", "External pentest (accredited lab)", ExternalOperational, "PENDING (external)"),
227 ]
228}
229
230pub fn controls_for(framework: FrameworkId) -> Vec<Control> {
231 match framework {
232 FrameworkId::Soc2TypeII => soc2_controls(),
233 FrameworkId::Iso27001 => iso_27001_controls(),
234 FrameworkId::Fips140_3 => fips_140_3_controls(),
235 FrameworkId::CcEal4Plus => cc_eal4_plus_controls(),
236 }
237}
238
239pub fn all_frameworks() -> Vec<FrameworkId> {
240 vec![
241 FrameworkId::Soc2TypeII,
242 FrameworkId::Iso27001,
243 FrameworkId::Fips140_3,
244 FrameworkId::CcEal4Plus,
245 ]
246}
247
248pub fn control_count(framework: FrameworkId) -> usize {
249 controls_for(framework).len()
250}
251
252#[cfg(test)]
253mod tests {
254 use super::*;
255
256 #[test]
257 fn control_counts_match_python() {
258 assert_eq!(control_count(FrameworkId::Soc2TypeII), 31);
259 assert_eq!(control_count(FrameworkId::Iso27001), 41);
260 assert_eq!(control_count(FrameworkId::Fips140_3), 14);
261 assert_eq!(control_count(FrameworkId::CcEal4Plus), 22);
262 }
263
264 #[test]
265 fn control_ids_unique_within_framework() {
266 for fw in all_frameworks() {
267 let ids: Vec<_> = controls_for(fw).iter().map(|c| c.control_id).collect();
268 let mut sorted = ids.clone();
269 sorted.sort();
270 sorted.dedup();
271 assert_eq!(ids.len(), sorted.len(), "duplicate ids in {:?}", fw);
272 }
273 }
274
275 #[test]
276 fn every_control_has_axon_primitive_and_locator() {
277 for fw in all_frameworks() {
278 for c in controls_for(fw) {
279 assert!(!c.axon_primitive.is_empty(), "{:?} {} missing primitive", fw, c.control_id);
280 assert!(!c.evidence_locator.is_empty(), "{:?} {} missing locator", fw, c.control_id);
281 }
282 }
283 }
284
285 #[test]
286 fn framework_id_as_str_matches_python() {
287 assert_eq!(FrameworkId::Soc2TypeII.as_str(), "soc2_type_ii");
288 assert_eq!(FrameworkId::Iso27001.as_str(), "iso_27001");
289 assert_eq!(FrameworkId::Fips140_3.as_str(), "fips_140_3");
290 assert_eq!(FrameworkId::CcEal4Plus.as_str(), "cc_eal4_plus");
291 }
292}