feat(core): zeroize in-memory secret material (Noise/Ed25519/X25519/store key)
All checks were successful
ci / test (pull_request) Successful in 3m50s

Wrap every secret this crate holds in zeroize: the local identity and
prekey secrets (Keys), the backup bundle and its derived Argon2id wrap
key, the store data key and the SQLCipher key material, the identity
secret handed out by Store::self_identity, the raw identity-secret
copies in pay/qr signing, and the wallet RPC password plus the
user:realm:password digest input.
This commit is contained in:
Sirius DevOps 2026-09-12 13:36:21 -04:00
commit fc7378596d
No known key found for this signature in database
12 changed files with 297 additions and 71 deletions

View file

@ -2,6 +2,7 @@ use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};
use rand::rngs::OsRng;
use snow::Builder;
use x25519_dalek::{PublicKey as X25519Public, StaticSecret};
use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};
use crate::store::SelfIdentity;
@ -51,11 +52,15 @@ impl From<snow::Error> for Error {
}
}
#[derive(Clone)]
/// Local secret keys. `Clone` copies the secrets, but the copy is itself
/// `ZeroizeOnDrop`, so no clone outlives its owner un-wiped.
#[derive(Clone, Zeroize, ZeroizeOnDrop)]
pub struct Keys {
pub identity_sk: [u8; 32],
#[zeroize(skip)]
pub identity_pk: [u8; 32],
pub prekey_sk: [u8; 32],
#[zeroize(skip)]
pub prekey_pk: [u8; 32],
}
@ -121,7 +126,7 @@ pub fn handshake_pinned(init: &Keys, resp: &Keys, pinned: &[u8; 32]) -> Result<(
.prologue(PROLOGUE)?
.build_responder()?;
let mut buf = vec![0u8; MSG_BUF];
let mut buf = Zeroizing::new(vec![0u8; MSG_BUF]);
let n = initiator.write_message(&[], &mut buf)?;
let msg1 = buf[..n].to_vec();
let n = responder.read_message(&msg1, &mut buf)?;
@ -190,7 +195,7 @@ where
.prologue(PROLOGUE)?
.build_initiator()?;
let mut buf = vec![0u8; MSG_BUF];
let mut buf = Zeroizing::new(vec![0u8; MSG_BUF]);
let n = hs.write_message(&[], &mut buf)?;
crate::frame::write_frame(stream, &buf[..n])
.await
@ -244,7 +249,7 @@ where
.prologue(PROLOGUE)?
.build_responder()?;
let mut buf = vec![0u8; MSG_BUF];
let mut buf = Zeroizing::new(vec![0u8; MSG_BUF]);
let msg1 = crate::frame::read_frame(stream)
.await
.map_err(|e| Error::new(e.to_string()))?;