// K2376-K2380: network_tools.diagnostic — Route ARP socket görünümü // Invariant: Yetkisiz session ayrıntısı açıklanmaz // Positive: Kendi socket ve route listesi // Counterexample: Başka principal sessionı // Acceptance: Yalnız izinli metadata gösterilir pub const NETWORK_TOOLS_DIAGNOSTIC_SCHEMA: &str = "turkos.os.network_tools.diagnostic.v1"; pub const NETWORK_TOOLS_DIAGNOSTIC_INVARIANT: &str = "Yetkisiz session ayrıntısı açıklanmaz"; pub const NETWORK_TOOLS_DIAGNOSTIC_POSITIVE: &str = "Kendi socket ve route listesi"; pub const NETWORK_TOOLS_DIAGNOSTIC_COUNTEREXAMPLE: &str = "Başka principal sessionı"; pub const NETWORK_TOOLS_DIAGNOSTIC_ACCEPTANCE: &str = "Yalnız izinli metadata gösterilir"; pub const EXPECTED_OWN_SOCKETS_AND_ROUTES: u32 = 4; pub const EXPECTED_AUTHORIZED_ARP_ENTRIES: u32 = 2; pub const EXPECTED_PERMITTED_METADATA_FIELDS: u32 = 4; pub const EXPECTED_UNAUTHORIZED_SESSION_DISCLOSURES: u32 = 0; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum NetworkToolsDiagnosticError { ForeignPrincipalSessionRequested = 1, UnauthorizedSessionDetailDisclosed = 2, UnpermittedMetadataExposed = 3, OwnSocketsAndRoutesMismatch = 4, AuthorizedArpEntriesMismatch = 5, PermittedMetadataFieldsMismatch = 6, ZeroDiagnosticEpoch = 7, NonMonotonicDiagnosticEpoch = 8, ZeroDiagnosticViewDigest = 9, UnboundNetworkToolsDiagnosticDigest = 10, AlreadyCommitted = 11, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct NetworkToolsDiagnosticRequest { pub foreign_principal_session_requested: bool, pub unauthorized_session_detail_disclosed: bool, pub only_permitted_metadata_shown: bool, pub own_sockets_and_routes: u32, pub authorized_arp_entries: u32, pub permitted_metadata_fields: u32, pub diagnostic_epoch: u64, pub previous_diagnostic_epoch: u64, pub diagnostic_view_digest: u64, pub diagnostic_binding_digest: u64, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct NetworkToolsDiagnosticReceipt { pub own_sockets_and_routes: u32, pub authorized_arp_entries: u32, pub permitted_metadata_fields: u32, pub unauthorized_session_disclosures: u32, pub only_permitted_metadata_shown: bool, pub diagnostic_epoch: u64, pub diagnostic_view_digest: u64, pub receipt_digest: u64, } pub const fn compute_network_tools_diagnostic_binding_digest( own_sockets_and_routes: u32, authorized_arp_entries: u32, permitted_metadata_fields: u32, unauthorized_session_disclosures: u32, diagnostic_epoch: u64, diagnostic_view_digest: u64, ) -> u64 { let mut h: u64 = 0xcbf2_9ce4_8422_2325; h = (h ^ 0x2380_4e54_4449_4147).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (own_sockets_and_routes as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (authorized_arp_entries as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (permitted_metadata_fields as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (unauthorized_session_disclosures as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ diagnostic_epoch).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ diagnostic_view_digest).wrapping_mul(0x0000_0100_0000_01b3); h } pub struct NetworkToolsDiagnosticCoordinator { committed: bool, committed_total: u64, rejected_total: u64, session_isolation_refusals: u64, diagnostic_accounting_refusals: u64, committed_receipt: Option, } impl NetworkToolsDiagnosticCoordinator { pub const fn new() -> Self { Self { committed: false, committed_total: 0, rejected_total: 0, session_isolation_refusals: 0, diagnostic_accounting_refusals: 0, committed_receipt: None, } } pub fn is_committed(&self) -> bool { self.committed } pub fn committed_total(&self) -> u64 { self.committed_total } pub fn rejected_total(&self) -> u64 { self.rejected_total } pub fn session_isolation_refusals(&self) -> u64 { self.session_isolation_refusals } pub fn diagnostic_accounting_refusals(&self) -> u64 { self.diagnostic_accounting_refusals } pub fn committed_receipt(&self) -> Option { self.committed_receipt } pub fn commit_network_diagnostic_view( &mut self, req: &NetworkToolsDiagnosticRequest, ) -> Result { if self.committed { self.rejected_total += 1; return Err(NetworkToolsDiagnosticError::AlreadyCommitted); } if req.foreign_principal_session_requested { self.rejected_total += 1; self.session_isolation_refusals += 1; return Err(NetworkToolsDiagnosticError::ForeignPrincipalSessionRequested); } if req.unauthorized_session_detail_disclosed { self.rejected_total += 1; self.session_isolation_refusals += 1; return Err(NetworkToolsDiagnosticError::UnauthorizedSessionDetailDisclosed); } if !req.only_permitted_metadata_shown { self.rejected_total += 1; self.session_isolation_refusals += 1; return Err(NetworkToolsDiagnosticError::UnpermittedMetadataExposed); } if req.own_sockets_and_routes != EXPECTED_OWN_SOCKETS_AND_ROUTES { self.rejected_total += 1; self.diagnostic_accounting_refusals += 1; return Err(NetworkToolsDiagnosticError::OwnSocketsAndRoutesMismatch); } if req.authorized_arp_entries != EXPECTED_AUTHORIZED_ARP_ENTRIES { self.rejected_total += 1; self.diagnostic_accounting_refusals += 1; return Err(NetworkToolsDiagnosticError::AuthorizedArpEntriesMismatch); } if req.permitted_metadata_fields != EXPECTED_PERMITTED_METADATA_FIELDS { self.rejected_total += 1; self.diagnostic_accounting_refusals += 1; return Err(NetworkToolsDiagnosticError::PermittedMetadataFieldsMismatch); } if req.diagnostic_epoch == 0 { self.rejected_total += 1; return Err(NetworkToolsDiagnosticError::ZeroDiagnosticEpoch); } if req.diagnostic_epoch <= req.previous_diagnostic_epoch { self.rejected_total += 1; return Err(NetworkToolsDiagnosticError::NonMonotonicDiagnosticEpoch); } if req.diagnostic_view_digest == 0 { self.rejected_total += 1; return Err(NetworkToolsDiagnosticError::ZeroDiagnosticViewDigest); } let expected_binding = compute_network_tools_diagnostic_binding_digest( req.own_sockets_and_routes, req.authorized_arp_entries, req.permitted_metadata_fields, EXPECTED_UNAUTHORIZED_SESSION_DISCLOSURES, req.diagnostic_epoch, req.diagnostic_view_digest, ); if req.diagnostic_binding_digest != expected_binding { self.rejected_total += 1; self.diagnostic_accounting_refusals += 1; return Err(NetworkToolsDiagnosticError::UnboundNetworkToolsDiagnosticDigest); } self.committed = true; self.committed_total += 1; let receipt = NetworkToolsDiagnosticReceipt { own_sockets_and_routes: req.own_sockets_and_routes, authorized_arp_entries: req.authorized_arp_entries, permitted_metadata_fields: req.permitted_metadata_fields, unauthorized_session_disclosures: EXPECTED_UNAUTHORIZED_SESSION_DISCLOSURES, only_permitted_metadata_shown: true, diagnostic_epoch: req.diagnostic_epoch, diagnostic_view_digest: req.diagnostic_view_digest, receipt_digest: expected_binding ^ 0x2380_ACE0_4449_4147, }; self.committed_receipt = Some(receipt); Ok(receipt) } }