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:
co-authored by
Claude Opus 4.6
parent
d1eb01799f
commit
4080d0a92b
@@ -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(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user