feat(recovery): implement header backup/restore, BIP-39 recovery key, and integrity verification

This commit is contained in:
2026-09-08 09:49:08 +02:00
parent 2d14c64c3e
commit 1c8a860184
11 changed files with 1451 additions and 57 deletions
+98
View File
@@ -97,3 +97,101 @@ pub fn step(num: u8, total: u8, icon: &str, msg: &str) {
let tag = cyan(&format!("[{}/{}]", num, total));
println!(" {} {} {}", tag, icon, msg);
}
/// Gibt den 24-Wort BIP-39 Notfall-Wiederherstellungsschlüssel in einer hervorgehobenen Sicherheitsbox aus.
pub fn print_recovery_phrase_card(phrase: &str) {
let words: Vec<&str> = phrase.split_whitespace().collect();
println!();
println!("{}", yellow("┌─────────────────────────────────────────────────────────────┐"));
println!("{}", yellow("│ ⚠️ 24-WORT NOTFALL-WIEDERHERSTELLUNGSSCHLÜSSEL │"));
println!("{}", yellow("├─────────────────────────────────────────────────────────────┤"));
println!("│ Falls Sie Ihr Master-Passwort vergessen oder der Header │");
println!("│ beschädigt wird, ist dies Ihre EINZIGE Rettung! │");
println!("│ Notieren Sie die Wörter in EXAKTER Reihenfolge auf Papier! │");
println!("{}", yellow("├─────────────────────────────────────────────────────────────┤"));
for row in 0..8 {
let w1 = if row < words.len() {
format!("{:2}. {:<11}", row + 1, words[row])
} else {
"".to_string()
};
let w2 = if row + 8 < words.len() {
format!("{:2}. {:<11}", row + 9, words[row + 8])
} else {
"".to_string()
};
let w3 = if row + 16 < words.len() {
format!("{:2}. {:<11}", row + 17, words[row + 16])
} else {
"".to_string()
};
println!("{:<18} {:<18} {:<18}", cyan(&w1), cyan(&w2), cyan(&w3));
}
println!("{}", yellow("└─────────────────────────────────────────────────────────────┘"));
println!();
}
/// Gibt den detaillierten Bericht einer Container-Integritätsprüfung aus.
pub fn print_verification_report(report: &crate::verify::VerificationReport) {
println!();
println!("┌─────────────────────────────────────────────────────────────┐");
println!("│ Sanctum Container-Integritätsprüfung (FSCK) │");
println!("└─────────────────────────────────────────────────────────────┘");
println!(" Container: {}", report.container_path);
println!(" Format: Version {}", report.format_version);
println!();
let sqlite_status = if report.sqlite_ok {
green("✔ OK")
} else {
red("✖ FEHLER")
};
let header_status = if report.header_ok {
green("✔ OK")
} else {
red("✖ BESCHÄDIGT")
};
let tree_status = if report.orphan_nodes == 0 {
green("✔ KONSISTENT")
} else {
red("✖ INKONSISTENT")
};
let chunk_status = if report.corrupted_chunks == 0 {
green("✔ AUTHENTIFIZIERT")
} else {
red("✖ BESCHÄDIGT")
};
println!(" • SQLite B-Tree Integrität: {}", sqlite_status);
println!(" • Header & KDF-Metadaten: {}", header_status);
println!(" • Verzeichnisbaum & Inodes: {}", tree_status);
println!(" • AEAD Chunk-Authentizität: {}", chunk_status);
println!();
println!(" Statistiken:");
println!(" - Ordner: {}", report.total_dirs);
println!(" - Dateien: {}", report.total_files);
println!(" - Daten-Chunks: {}", report.total_chunks);
if report.total_bytes_decrypted > 0 {
let mb = report.total_bytes_decrypted as f64 / (1024.0 * 1024.0);
println!(" - Verifiziert: {:.2} MB (vollständig entschlüsselt)", mb);
}
if !report.errors.is_empty() {
println!();
println!("{}", red(" Gefundene Probleme / Fehler:"));
for err in &report.errors {
println!(" {} {}", red(""), err);
}
}
println!();
if report.is_healthy() {
println!(" {}", green("✔ Keine Beschädigungen oder Bitrot festgestellt. Der Container ist integer."));
} else {
println!(" {}", red("✖ ACHTUNG: Der Container weist Beschädigungen auf! Bitte Backup prüfen."));
}
println!();
}