Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : App/Sources/Security/BackupInspectView.swift8// Module : Security9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0412// Last Modified : 2026-12-0413//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import QyvoraIdentity43import QyvoraRecovery44import QyvoraUI4546extension BackupHeader {47 /// Fingerprint text of the signer, when the backup is signed by a readable identity.48 var signerFingerprintText: String? {49 signerEncoding.flatMap { try? PublicIdentity(encoded: $0) }?.fingerprintText50 }5152 var signerFingerprint: [UInt8]? {53 signerEncoding.flatMap { try? PublicIdentity(encoded: $0) }?.fingerprint54 }55}5657/// What a backup file says about itself without its password.58struct BackupHeaderCard: View {59 let header: BackupHeader6061 var body: some View {62 VStack(alignment: .leading, spacing: QSpace.l) {63 QListSection("Backup file") {64 SecFactRow(label: "Format", value: "QYVORA Backup v\(header.formatVersion)")65 SecFactRow(label: "Created", value: SecurityFormat.date(header.createdAt))66 SecFactRow(label: "Vault identifier", value: MiddleTruncation.grouped(SecurityFormat.hex(header.vaultID)), mono: true)67 SecFactRow(label: "Records", value: "\(header.recordCount)")68 SecFactRow(label: "Key derivation", value: SecurityFormat.kdf(header.kdf), mono: true)69 SecFactRow(label: "Signature", value: header.isSigned ? "Signed" : "Not signed", tone: header.isSigned ? .info : nil)70 }71 if header.isSigned {72 QListSection("Signer fingerprint", footnote: "The header is read without the password, so the signature is not checked here. It is verified when the backup is restored.") {73 if let fingerprint = header.signerFingerprintText {74 FingerprintView(text: fingerprint).padding(.vertical, QSpace.m)75 } else {76 SecTextRow(text: "The signer field cannot be read as a QYVORA identity.", systemImage: QTone.warning.systemImage, tone: .warning)77 }78 }79 }80 }81 }82}8384/// Picks a backup file and shows its header (`inspectBackup`): date, vault, record count, signer. The content stays85/// encrypted; no password is asked.86struct BackupInspectView: View {87 @Environment(WalletStore.self) private var store88 @State private var picking = false89 @State private var fileName: String?90 @State private var header: BackupHeader?91 @State private var error: String?92 @State private var busy = false9394 var body: some View {95 SecurityScroll {96 Explanation("Choose a \u{201C}.\(BackupFile.fileExtension)\u{201D} file to read its header. Nothing is decrypted and nothing changes on this device.")97 LoadingButton(header == nil ? "Choose a backup file" : "Choose another file", loadingTitle: "Reading the file", systemImage: "doc.viewfinder",98 state: busy ? .loading : .idle, prominence: header == nil ? .primary : .secondary) { picking = true }99 SecInlineError(error)100 if let header {101 if let fileName {102 Text(fileName).font(QFont.mono).foregroundStyle(QColor.textSecondary)103 }104 BackupHeaderCard(header: header)105 }106 }107 .navigationTitle("Inspect a backup")108 .navigationBarTitleDisplayMode(.inline)109 .fileImporter(isPresented: $picking, allowedContentTypes: [SecurityFiles.backupType, .data]) { result in110 switch result {111 case .success(let url): inspect(url)112 case .failure(let failure): error = failure.localizedDescription113 }114 }115 }116117 func inspect(_ url: URL) {118 guard !busy else { return }119 busy = true120 error = nil121 header = nil122 fileName = url.lastPathComponent123 Task {124 var copy: URL?125 do {126 let local = try SecurityFiles.importedCopy(of: url)127 copy = local128 header = try await store.run { try await $0.inspectBackup(at: local) }129 } catch {130 self.error = SecurityError.text(error)131 }132 SecurityFiles.remove(copy)133 busy = false134 }135 }136}137