feat(core): zeroize in-memory secret material (Noise/Ed25519/X25519/store key) #46
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/zeroize-secrets"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Every secret this crate keeps in memory is now wiped instead of merely being encrypted at rest.
zeroize(already inCargo.lockat 1.9.0, transitive through the dalek stack) becomes a direct dependency with thederivefeature; no version bump was needed or made.Wrapped: the local identity/prekey secrets handed to the Noise IK handshake, the Ed25519 identity secret wherever a raw copy is made, the X25519 prekeys, the store data key + the SQLCipher key material, the Argon2id-passphrase-derived wrap key, the backup bundle plaintext, the identity secret the store hands out, and the wallet RPC password / digest input.
Types that hold secret bytes
ZeroizeOnDrop?Clone?session::Keys(identity_sk,prekey_sk)src/session.rs#[derive(Zeroize, ZeroizeOnDrop)]; public halves#[zeroize(skip)]ZeroizeOnDrop, so it wipes on its own drop; testcloned_session_keys_wipe_their_own_copy_onlyproves the copy wipes and the original survivessession::Session::transport(snow::TransportState)src/session.rsbuf(each ofhandshake_pinned/handshake_initiator/handshake_responder)src/session.rsZeroizing<Vec<u8>>[u8; 32]identity-secret copies inpay::sign_bytes,qr::encodesrc/pay.rs,src/qr.rsZeroizing<[u8; 32]>backup::BackupKeys(identity_sk,prekey_sk)src/backup.rsKeys;Debugis now hand-written and prints<redacted>for both secret halves (was#[derive(Debug)], i.e. it printed the bytes)backup::kdfoutput (Argon2id wrap key)src/backup.rsZeroizing<[u8; 32]>(the raw[u8; 32]temp is gone)BackupKeys::to_bytesplaintext bundlesrc/backup.rsZeroizing<[u8; 128]>backup::opensrc/backup.rsZeroizing<Vec<u8>>beforefrom_bytesStore::msg_key(store data key)src/store.rsZeroizing<[u8; 32]>Storeis notClone)Store::unlock_messages: unwrapped data key, fresh data keysrc/store.rsZeroizingimmediately after the AEAD unwrapStore::pragma_keystring, theATTACH … KEYstringsrc/store.rsZeroizing<String>(both carried the db key in hex)Store::passphrase_from_env,resolve_store_passphrasereturn valuesrc/store.rsZeroizing<String>SelfIdentity::identity_sk/prekey_sksrc/store.rsZeroizing<Vec<u8>>gen_prekey()secret half,ensure_selfidentity bytessrc/store.rsNode::startpassphrasesrc/node.rsZeroizing<String>wallet::Endpoint::passsrc/wallet.rsZeroizing<String>Debugwas already redacted, now covered by a testONIONWIRE_WALLET_RPCURL +…_LOGIN(may carryuser:pass@)src/wallet.rsuser:realm:passworddigest inputsrc/wallet.rsZeroizing<String>Also checked:
session::sign_proof,node::write_backup/restore_backup/qr_payloadhold no secret beyond the values above.ed25519_dalek::SigningKeyandx25519_dalek::StaticSecretalready wipe themselves on drop (both crates shipzeroizein their default features and this crate does not disable defaults), so those copies needed no change.Not covered (explicit)
snow's internal Noise state. The IK ephemeral key and the derived transport keys live insidesnow::HandshakeState/snow::TransportState.snow0.10 exposes nozeroizesupport, soSession::transportis the one live secret-bearing object this change cannot wipe. Fixing it means upstreamsnowsupport or a different Noise implementation — out of scope here.Vec/Stringwiping zeroes the buffer in place; any reallocation or allocator-internal copy of that buffer is not reached.Stringinterning / environment copies. The passphrase read fromONIONWIRE_STORE_PASSPHRASEis wiped in our buffer, but the process environment itself is owned by the OS and is not touched (Rust'senv::vargives us a copy, which is what we wipe).src/file.rsbuffers, the TUI passphrase-entry buffer (src/tui.rs) andsrc/profile.rswere out of scope per the card (the first two are owned by open PRs / explicitly excluded); the TUI's in-progress passphraseStringstill lives until the screen is torn down, andprofile::signstill makes a raw[u8; 32]identity-secret copy.unsafeis used in the crate to defeatZeroize; the onlyunsafeadded is intests/zeroize.rs, to read a dropped value back so the drop test cannot pass on a moved copy.Verification (real output)
New tests:
tests/zeroize.rs(6),src/backup.rsunit tests (3: derived wrap key isZeroizing, plaintext bundle wipes,Debugredacts),src/store.rsunit test (store data key is aZeroizingwrapper and wipes). The type-level assertions are compile-time evidence: deleting a derive breaks the build there.Also verified written first and failing before the change (RED):
use zeroize::{…}was an unresolved-crate error at that point, anddropped_session_keys_leave_no_secret_behindfailed with the real secret[13, 119, 16, 221, …]still present before the wrapper landed.Files
Cargo.toml,Cargo.lock(+1 line: thezeroizeedge on theonionwirepackage),src/session.rs,src/backup.rs,src/store.rs,src/pay.rs,src/qr.rs,src/wallet.rs,src/node.rs,tests/zeroize.rs(new),tests/backup.rs,tests/store.rs. No forbidden path touched (src/tui.rs,tests/tui_spec.rs,docs/TUI.md,README.md,crates/onionwire-sdk/**,android/**all untouched), so there is no## README (deferred)section.README (deferred)
No
README.mdwording is needed for this change — it is an internal hardening pass with no user-visible behaviour change.f3fca69fbefc7378596dMerge order 7 of 7: #38 -> #42 -> #41 -> #44 -> #43 -> #45 -> #46
Last of the core three, deliberately: zeroizing after #45 means the sweep covers the secret handling #45 adds, instead of needing a second pass. Needs one rebase after #41/#43/#45 — conflict in
src/wallet.rs(from #41) plusdocs/THREAT_MODEL.md, verified by simulationNote: Forgejo refuses a formal approval from this token ("approve your own pull is not allowed" — the PRs were pushed by account
sirius, which is also the token's user). This review records the sign-off and the merge position; a human approval click is still needed. Rebased onto currentmainbefore this review, diff verified byte-identical.