fix: Phase 8 — mesh hardening: atomic writes, unwrap elimination, GPS opt-out

- Ratchet state: atomic write via tmp + rename to prevent corruption on crash
- Block header decode: replaced .unwrap() with proper error handling on
  untrusted network data (was a crash vector from malicious peers)
- Shutdown channel: replaced .unwrap() with .ok_or_else() error propagation
- Dead man's switch GPS: default changed to opt-out (auto_include_gps=false)
- Alert signature verification: already covered by Phase 4 envelope checks

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-18 01:04:19 +00:00
co-authored by Claude Opus 4.6
parent d1eb01799f
commit 4080d0a92b
5 changed files with 22 additions and 13 deletions
+8 -3
View File
@@ -64,12 +64,17 @@ impl SessionManager {
.await
.context("Failed to create ratchet directory")?;
let path = self.session_path(did);
let tmp_path = path.with_extension("tmp");
let content = serde_json::to_string_pretty(state)
.context("Failed to serialize ratchet session")?;
tokio::fs::write(&path, content)
// Atomic write: write to temp file, then rename
tokio::fs::write(&tmp_path, content)
.await
.context("Failed to write ratchet session")?;
debug!(did = %did, "Saved ratchet session to disk");
.context("Failed to write temporary ratchet state")?;
tokio::fs::rename(&tmp_path, &path)
.await
.context("Failed to atomically rename ratchet state file")?;
debug!(did = %did, "Saved ratchet session to disk (atomic)");
Ok(())
}