// K2356-K2360: system_monitor.logs — Yetkili tanı log görünümü // Invariant: Monitor sırlı alanları okuyamaz // Positive: İzinli hizmet olayları // Counterexample: Secret buffer log isteği // Acceptance: Redaction ve principal süzmesi çalışır pub const SYSTEM_MONITOR_LOGS_SCHEMA: &str = "turkos.os.system_monitor.logs.v1"; pub const SYSTEM_MONITOR_LOGS_INVARIANT: &str = "Monitor sırlı alanları okuyamaz"; pub const SYSTEM_MONITOR_LOGS_POSITIVE: &str = "İzinli hizmet olayları"; pub const SYSTEM_MONITOR_LOGS_COUNTEREXAMPLE: &str = "Secret buffer log isteği"; pub const SYSTEM_MONITOR_LOGS_ACCEPTANCE: &str = "Redaction ve principal süzmesi çalışır"; pub const EXPECTED_AUTHORIZED_SERVICE_EVENTS: u32 = 4; pub const EXPECTED_REDACTED_SECRET_FIELDS: u32 = 2; pub const EXPECTED_PRINCIPAL_FILTER_MATCHES: u32 = 4; pub const EXPECTED_UNREDACTED_SECRET_LEAKS: u32 = 0; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum SystemMonitorLogsError { SecretBufferLogRequested = 1, MonitorReadSecretFields = 2, RedactionOrPrincipalFilterBypassed = 3, AuthorizedServiceEventsMismatch = 4, RedactedSecretFieldsMismatch = 5, PrincipalFilterMatchesMismatch = 6, ZeroLogsEpoch = 7, NonMonotonicLogsEpoch = 8, ZeroLogsViewDigest = 9, UnboundSystemMonitorLogsDigest = 10, AlreadyCommitted = 11, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct SystemMonitorLogsRequest { pub secret_buffer_log_requested: bool, pub monitor_read_secret_fields: bool, pub redaction_and_principal_filter_enforced: bool, pub authorized_service_events: u32, pub redacted_secret_fields: u32, pub principal_filter_matches: u32, pub logs_epoch: u64, pub previous_logs_epoch: u64, pub logs_view_digest: u64, pub logs_binding_digest: u64, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct SystemMonitorLogsReceipt { pub authorized_service_events: u32, pub redacted_secret_fields: u32, pub principal_filter_matches: u32, pub unredacted_secret_leaks: u32, pub redaction_and_principal_filter_enforced: bool, pub logs_epoch: u64, pub logs_view_digest: u64, pub receipt_digest: u64, } pub const fn compute_system_monitor_logs_binding_digest( authorized_service_events: u32, redacted_secret_fields: u32, principal_filter_matches: u32, unredacted_secret_leaks: u32, logs_epoch: u64, logs_view_digest: u64, ) -> u64 { let mut h: u64 = 0xcbf2_9ce4_8422_2325; h = (h ^ 0x2360_534d_4c4f_4753).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (authorized_service_events as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (redacted_secret_fields as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (principal_filter_matches as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (unredacted_secret_leaks as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ logs_epoch).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ logs_view_digest).wrapping_mul(0x0000_0100_0000_01b3); h } pub struct SystemMonitorLogsCoordinator { committed: bool, committed_total: u64, rejected_total: u64, secret_redaction_refusals: u64, logs_accounting_refusals: u64, committed_receipt: Option, } impl SystemMonitorLogsCoordinator { pub const fn new() -> Self { Self { committed: false, committed_total: 0, rejected_total: 0, secret_redaction_refusals: 0, logs_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 secret_redaction_refusals(&self) -> u64 { self.secret_redaction_refusals } pub fn logs_accounting_refusals(&self) -> u64 { self.logs_accounting_refusals } pub fn committed_receipt(&self) -> Option { self.committed_receipt } pub fn commit_authorized_log_view( &mut self, req: &SystemMonitorLogsRequest, ) -> Result { if self.committed { self.rejected_total += 1; return Err(SystemMonitorLogsError::AlreadyCommitted); } if req.secret_buffer_log_requested { self.rejected_total += 1; self.secret_redaction_refusals += 1; return Err(SystemMonitorLogsError::SecretBufferLogRequested); } if req.monitor_read_secret_fields { self.rejected_total += 1; self.secret_redaction_refusals += 1; return Err(SystemMonitorLogsError::MonitorReadSecretFields); } if !req.redaction_and_principal_filter_enforced { self.rejected_total += 1; self.secret_redaction_refusals += 1; return Err(SystemMonitorLogsError::RedactionOrPrincipalFilterBypassed); } if req.authorized_service_events != EXPECTED_AUTHORIZED_SERVICE_EVENTS { self.rejected_total += 1; self.logs_accounting_refusals += 1; return Err(SystemMonitorLogsError::AuthorizedServiceEventsMismatch); } if req.redacted_secret_fields != EXPECTED_REDACTED_SECRET_FIELDS { self.rejected_total += 1; self.logs_accounting_refusals += 1; return Err(SystemMonitorLogsError::RedactedSecretFieldsMismatch); } if req.principal_filter_matches != EXPECTED_PRINCIPAL_FILTER_MATCHES { self.rejected_total += 1; self.logs_accounting_refusals += 1; return Err(SystemMonitorLogsError::PrincipalFilterMatchesMismatch); } if req.logs_epoch == 0 { self.rejected_total += 1; return Err(SystemMonitorLogsError::ZeroLogsEpoch); } if req.logs_epoch <= req.previous_logs_epoch { self.rejected_total += 1; return Err(SystemMonitorLogsError::NonMonotonicLogsEpoch); } if req.logs_view_digest == 0 { self.rejected_total += 1; return Err(SystemMonitorLogsError::ZeroLogsViewDigest); } let expected_binding = compute_system_monitor_logs_binding_digest( req.authorized_service_events, req.redacted_secret_fields, req.principal_filter_matches, EXPECTED_UNREDACTED_SECRET_LEAKS, req.logs_epoch, req.logs_view_digest, ); if req.logs_binding_digest != expected_binding { self.rejected_total += 1; self.logs_accounting_refusals += 1; return Err(SystemMonitorLogsError::UnboundSystemMonitorLogsDigest); } self.committed = true; self.committed_total += 1; let receipt = SystemMonitorLogsReceipt { authorized_service_events: req.authorized_service_events, redacted_secret_fields: req.redacted_secret_fields, principal_filter_matches: req.principal_filter_matches, unredacted_secret_leaks: EXPECTED_UNREDACTED_SECRET_LEAKS, redaction_and_principal_filter_enforced: true, logs_epoch: req.logs_epoch, logs_view_digest: req.logs_view_digest, receipt_digest: expected_binding ^ 0x2360_ACE0_4c4f_4753, }; self.committed_receipt = Some(receipt); Ok(receipt) } }