Repository Public License
1// ORIX Secure2// File: App/Sources/Core/ReportBuilders.swift3// Description: Builds report documents from the app's assessments. A report never carries the device name, serial number or4// any identifier beyond the model and system version.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import Foundation9import ORIXSecureEngines10import ORIXSecureModel1112nonisolated enum ReportBuilder {13 static var generator: String {14 let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "?"15 let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "?"16 return "ORIX Secure \(version) (\(build))"17 }1819 static func deviceFacts(_ device: DeviceSnapshot) -> [ReportDocument.Fact] {20 var facts: [ReportDocument.Fact] = [21 .init(L("Model identifier"), device.modelIdentifier),22 .init(L("System"), "\(device.systemName) \(device.systemVersion)"),23 ]24 if device.isSimulator { facts.append(.init(L("Environment"), L("Simulator — hardware readings do not describe a real device"))) }25 return facts26 }2728 static func summaryFacts(_ summary: AssessmentSummary) -> [ReportDocument.Fact] {29 var facts: [ReportDocument.Fact] = [30 .init(AssessmentState.verified.title, "\(summary.verified)"),31 .init(AssessmentState.attention.title, "\(summary.attention)"),32 .init(AssessmentState.userConfirmed.title, "\(summary.userConfirmed)"),33 .init(AssessmentState.userConfirmationRequired.title, "\(summary.awaitingConfirmation)"),34 .init(AssessmentState.notAvailable.title, "\(summary.notAvailable)"),35 ]36 if let coverage = summary.coverage { facts.append(.init(L("Coverage of assessable items"), ORIXFormat.percent(coverage))) }37 return facts38 }3940 static func security(_ assessment: SecurityAssessment, device: DeviceSnapshot) -> ReportDocument {41 let summary = assessment.summary42 return ReportDocument(43 kind: .securityAssessment, title: L("Security assessment"),44 summary: L("\(summary.attention) item(s) need attention, \(summary.verified) were verified by the app, \(summary.userConfirmed) were confirmed by you and \(summary.awaitingConfirmation) await your confirmation. This is not a malware scan."),45 sections: [46 .init(title: L("Device"), facts: deviceFacts(device)),47 .init(title: L("Summary"), paragraphs: AssessmentSummary.methodology, facts: summaryFacts(summary)),48 .init(title: L("Recommended actions"), paragraphs: assessment.actions.isEmpty ? [L("Nothing needs attention among the items that were assessed.")] : [], findings: assessment.actions),49 .init(title: L("Checked by the app"), findings: (assessment.automatic + assessment.contributed).filter { $0.state != .attention }),50 .init(title: L("Checked with you"), paragraphs: [L("iOS does not let apps read these settings. Results are what you reported.")],51 findings: assessment.checklist.filter { $0.state != .attention }),52 ],53 unavailable: assessment.notAssessable.map { "\($0.title): \($0.reason)" }, generator: generator)54 }5556 static func privacy(_ audit: PrivacyAudit) -> ReportDocument {57 let summary = audit.summary58 return ReportDocument(59 kind: .privacyAudit, title: L("Privacy audit"),60 summary: L("\(summary.userConfirmed) privacy setting(s) confirmed by you, \(summary.attention) to review, \(summary.awaitingConfirmation) not checked yet. Only ORIX Secure's own permissions can be read by the app."),61 sections: [62 .init(title: L("What ORIX Secure does with data"), facts: audit.practices),63 .init(title: L("ORIX Secure's own permissions"), findings: audit.appPermissions),64 .init(title: L("Recommended improvements"), paragraphs: audit.checklist.contains { $0.state == .attention } ? [] : [L("No setting you reported needs changing.")],65 findings: audit.checklist.filter { $0.state == .attention }),66 .init(title: L("Settings you confirmed"), findings: audit.checklist.filter { $0.state == .userConfirmed || $0.state == .notAvailable }),67 .init(title: L("Not checked yet"), findings: audit.checklist.filter { $0.state == .userConfirmationRequired || $0.state == .notAssessed }),68 ],69 unavailable: audit.notAssessable.map { "\($0.title): \($0.reason)" }, generator: generator)70 }7172 static func device(_ diagnostics: DeviceDiagnostics, advice: [Advice]) -> ReportDocument {73 var sections = diagnostics.sections.map { section in74 ReportDocument.Section(title: section.title, facts: section.rows.map { row in75 .init(row.label, row.value.value ?? L("Not available — \(row.value.unavailability?.detail ?? "")"))76 })77 }78 sections.append(.init(title: L("Findings"), findings: diagnostics.findings))79 sections.append(.init(title: L("Battery and performance guidance"), bullets: advice.map { "\($0.title) — \($0.detail)" }))80 return ReportDocument(kind: .device, title: L("Device diagnostics"),81 summary: L("Readings taken from public iOS APIs. Measurements iOS does not give to apps are listed as unavailable, not estimated."),82 sections: sections, unavailable: diagnostics.unavailable.map { "\($0.title): \($0.reason)" }, generator: generator, createdAt: diagnostics.capturedAt)83 }8485 static func storage(_ overview: StorageOverview) -> ReportDocument {86 let volume = overview.volume87 func text(_ reading: Reading<Int64>) -> String { reading.value.map { ORIXFormat.bytes($0) } ?? L("Not available") }88 return ReportDocument(89 kind: .storage, title: L("Storage report"),90 summary: L("Capacity of the device's data volume and the size of ORIX Secure's own files. iOS does not tell apps how much space other apps use."),91 sections: [92 .init(title: L("Device volume"), facts: [93 .init(L("Capacity"), text(volume.total)), .init(L("Available"), text(volume.bestAvailable)), .init(L("Free on the file system"), text(volume.available)),94 ], findings: overview.findings),95 .init(title: L("ORIX Secure's own files"), facts: overview.owned.map { .init($0.kind.title, L("\(ORIXFormat.bytes($0.bytes)) in \($0.fileCount) file(s)")) }),96 ],97 unavailable: overview.notExposed.map { "\($0.title): \($0.reason)" }, generator: generator, createdAt: overview.capturedAt)98 }99}100