Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/crates/aien-security/src/lib.rs # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / crates / aien-security / src / lib.rs` 133 lines ยท 4384 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 //! # AIEN Security 17 //! 18 //! Normative security abstractions, SecretProvider capability traits, 19 //! and network purpose governance for the AIEN ecosystem. 20 21 pub mod network; 22 pub mod secret; 23 pub mod tpm; 24 25 pub use network::{enforce_network_purpose, NetworkIntent, NetworkPurpose, NetworkSecurityError}; 26 pub use secret::{ 27 MemorySecretProvider, SealedSecret, SecretCapabilities, SecretError, SecretProtectionLevel, 28 SecretProvider, 29 }; 30 pub use tpm::Tpm2SecretProvider; 31 32 #[cfg(test)] 33 mod tests { 34 use super::*; 35 36 #[test] 37 fn test_rejected_forbidden_network_purpose() { 38 let bad_purpose = NetworkPurpose::Telemetry; // no-telemetry 39 let intent = NetworkIntent::new("https://analytics.example.com/v1/event", bad_purpose) 40 .with_context("background_diagnostic_beacon"); 41 42 let result = enforce_network_purpose(&intent); 43 assert!(result.is_err()); 44 let expected = NetworkSecurityError::TelemetryForbidden; // no-telemetry 45 assert_eq!(result.unwrap_err(), expected); 46 } 47 48 #[test] 49 fn test_permitted_purposes_succeed() { 50 let allowed = [ 51 ( 52 NetworkPurpose::UserRequestedApi, 53 "https://api.openai.com/v1/chat/completions", 54 ), 55 ( 56 NetworkPurpose::PeerSynchronization, 57 "radicle://peer.node.example", 58 ), 59 ( 60 NetworkPurpose::ModelDownload, 61 "https://huggingface.co/TinyLlama/model.safetensors", 62 ), 63 ( 64 NetworkPurpose::UpdateCheck, 65 "https://updates.aien.dev/releases.json", 66 ), 67 ]; 68 69 for (purpose, url) in allowed { 70 assert!(purpose.is_permitted()); 71 let intent = NetworkIntent::new(url, purpose); 72 assert!(enforce_network_purpose(&intent).is_ok()); 73 } 74 } 75 76 #[test] 77 fn test_memory_secret_provider_lifecycle() { 78 let provider = MemorySecretProvider::new(); 79 assert_eq!( 80 provider.protection_level(), 81 SecretProtectionLevel::MemoryOnly 82 ); 83 84 let secret_name = "TEST_API_TOKEN"; 85 let secret_bytes = b"super-secret-token-payload"; 86 87 // Seal 88 let sealed = provider 89 .seal(secret_name, secret_bytes) 90 .expect("sealing failed"); 91 assert_eq!(sealed.name, secret_name); 92 assert_eq!(sealed.protection_level, SecretProtectionLevel::MemoryOnly); 93 94 // Unseal 95 let unsealed = provider.unseal(&sealed).expect("unsealing failed"); 96 assert_eq!(&*unsealed, secret_bytes); 97 98 // Resolve 99 let resolved = provider.resolve(secret_name).expect("resolution failed"); 100 assert_eq!(&*resolved, secret_bytes); 101 102 // Delete 103 provider.delete(secret_name).expect("deletion failed"); 104 assert!(provider.resolve(secret_name).is_err()); 105 } 106 107 #[test] 108 fn test_tpm2_secret_provider_capabilities() { 109 let provider = Tpm2SecretProvider::default(); 110 let caps = provider.capabilities(); 111 assert_eq!( 112 caps.protection_level, 113 SecretProtectionLevel::HardwareBackedSealed 114 ); 115 assert!(caps.hardware_bound); 116 assert!(caps.persistent_at_rest); 117 } 118 119 #[test] 120 fn test_unslop_invariants_in_crate() { 121 let files = [ 122 include_str!("lib.rs"), 123 include_str!("secret.rs"), 124 include_str!("network.rs"), 125 include_str!("tpm.rs"), 126 ]; 127 128 for code in files { 129 assert!(!code.contains('\u{2014}'), "Encountered em dash in code"); 130 assert!(!code.contains('\u{2013}'), "Encountered en dash in code"); 131 } 132 } 133 }