use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub enum SecureBootStage {
#[default]
Stage0,
Stage1,
Stage2,
Stage3,
Stage4,
Stage5,
}
impl SecureBootStage {
pub fn number(self) -> u8 {
match self {
Self::Stage0 => 0,
Self::Stage1 => 1,
Self::Stage2 => 2,
Self::Stage3 => 3,
Self::Stage4 => 4,
Self::Stage5 => 5,
}
}
pub fn label(self) -> &'static str {
match self {
Self::Stage0 => "Secure Boot Disabled",
Self::Stage1 => "Opt-in Not Configured",
Self::Stage2 => "Awaiting Windows Update",
Self::Stage3 => "Update In Progress",
Self::Stage4 => "Pending Reboot",
Self::Stage5 => "Compliant",
}
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum DataSource {
LiveScan,
LogImport,
Both,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[serde(rename_all = "camelCase")]
pub enum DiagnosticSeverity {
Info,
Warning,
Error,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum LogSource {
Detect,
Remediate,
System,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum LogLevel {
Info,
Warning,
Error,
Success,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum TimelineEventType {
StageTransition,
RemediationResult,
Error,
Fallback,
SessionStart,
SessionEnd,
DiagnosticData,
Info,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TimelineEntry {
pub timestamp: DateTime<Utc>,
pub source: LogSource,
pub level: LogLevel,
pub event_type: TimelineEventType,
pub message: String,
pub stage: Option<SecureBootStage>,
pub error_code: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LogSession {
pub source: LogSource,
pub started_at: DateTime<Utc>,
pub ended_at: Option<DateTime<Utc>>,
pub result_stage: Option<SecureBootStage>,
pub result_outcome: Option<String>,
pub entries: Vec<TimelineEntry>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct SecureBootScanState {
pub secure_boot_enabled: Option<bool>,
pub managed_opt_in: Option<u32>,
pub available_updates: Option<u32>,
pub uefi_ca2023_capable: Option<u32>,
pub uefi_ca2023_status: Option<u32>,
pub uefi_ca2023_error: Option<u32>,
pub managed_opt_in_date: Option<String>,
pub telemetry_level: Option<u32>,
pub diagtrack_running: Option<bool>,
pub diagtrack_start_type: Option<String>,
pub tpm_present: Option<bool>,
pub tpm_enabled: Option<bool>,
pub tpm_activated: Option<bool>,
pub tpm_spec_version: Option<String>,
pub bitlocker_protection_on: Option<bool>,
pub bitlocker_encryption_status: Option<String>,
#[serde(default)]
pub bitlocker_key_protectors: Vec<String>,
pub disk_partition_style: Option<String>,
pub payload_folder_exists: Option<bool>,
pub payload_bin_count: Option<u32>,
pub scheduled_task_exists: Option<bool>,
pub scheduled_task_last_run: Option<String>,
pub scheduled_task_last_result: Option<String>,
pub wincs_available: Option<bool>,
#[serde(default)]
pub pending_reboot_sources: Vec<String>,
pub device_name: Option<String>,
pub os_caption: Option<String>,
pub os_build: Option<String>,
pub oem_manufacturer: Option<String>,
pub oem_model: Option<String>,
pub firmware_version: Option<String>,
pub firmware_date: Option<String>,
pub raw_registry_dump: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DiagnosticFinding {
pub rule_id: String,
pub severity: DiagnosticSeverity,
pub title: String,
pub detail: String,
pub recommendation: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ScriptExecutionResult {
pub exit_code: i32,
pub stdout: String,
pub stderr: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SecureBootAnalysisResult {
pub stage: SecureBootStage,
pub data_source: DataSource,
pub scan_state: SecureBootScanState,
pub sessions: Vec<LogSession>,
pub timeline: Vec<TimelineEntry>,
pub diagnostics: Vec<DiagnosticFinding>,
pub script_result: Option<ScriptExecutionResult>,
}