feat(core): zeroize the profile/loc signing copy and the TUI passphrase buffer
All checks were successful
ci / test (pull_request) Successful in 4m14s
All checks were successful
ci / test (pull_request) Successful in 4m14s
The Ed25519 identity secret was still copied into a bare [u8; 32] on the stack in two signers (profile::sign, loc::sign), and the TUI kept the typed backup/restore passphrase in a plain String for the life of the screen. Both now go through Zeroizing: - profile::signing_key_bytes() builds the 32-byte copy into a Zeroizing<[u8; 32]> (same pattern as pay::sign_bytes / qr::encode, but with copy_from_slice so no Copy temporary is left behind); loc::sign shares the helper instead of making its own copy. - Screen::Passphrase now owns a PassphraseEntry whose buffers are Zeroizing<String>. Every exit path (Enter, mismatch, Esc) calls close(), which wipes both buffers eagerly; a drop — including Ctrl-Q and a panic — is the backstop. Evidence: tests/zeroize.rs gains a drop probe (ManuallyDrop + drop_in_place + read_volatile) on the Zeroizing signing buffer and a length-rejection test; src/tui.rs gains unit tests asserting the buffer types and that close() leaves every byte of the passphrase's heap capacity zeroed.
This commit is contained in:
parent
c39259b919
commit
e3be8ffdd0
4 changed files with 215 additions and 30 deletions
|
|
@ -5,6 +5,7 @@
|
|||
//! Noise handshake/transport state that lives inside `snow`.
|
||||
|
||||
use onionwire::backup::BackupKeys;
|
||||
use onionwire::profile;
|
||||
use onionwire::session::Keys;
|
||||
use onionwire::wallet::Wallet;
|
||||
use onionwire::Store;
|
||||
|
|
@ -52,6 +53,20 @@ unsafe fn drop_in_place_and_peek_identity_sk(v: &mut Keys) -> [u8; 32] {
|
|||
}
|
||||
}
|
||||
|
||||
/// Drops a `Zeroizing<[u8; 32]>` in place and reads its buffer back.
|
||||
///
|
||||
/// SAFETY: only for `ManuallyDrop<Zeroizing<[u8; 32]>>` locals — same contract
|
||||
/// as `drop_in_place_and_peek_identity_sk`.
|
||||
unsafe fn drop_in_place_and_peek_zeroizing_u8x32(v: &mut Zeroizing<[u8; 32]>) -> [u8; 32] {
|
||||
let p: *const [u8; 32] = &**v;
|
||||
// SAFETY: the caller guarantees `v` is dropped exactly once and is still
|
||||
// alive at its own address when read back.
|
||||
unsafe {
|
||||
std::ptr::drop_in_place(v as *mut Zeroizing<[u8; 32]>);
|
||||
std::ptr::read_volatile(p)
|
||||
}
|
||||
}
|
||||
|
||||
/// Drop behaviour, not a comment: after the value drops, the local secret key
|
||||
/// material that feeds the Noise IK handshake is gone from its memory.
|
||||
#[test]
|
||||
|
|
@ -116,3 +131,27 @@ fn wallet_endpoint_debug_redacts_the_rpc_password() {
|
|||
);
|
||||
assert!(dbg.contains("<redacted>"), "{dbg}");
|
||||
}
|
||||
|
||||
/// `profile::sign` needs a raw 32-byte copy of the identity secret to build the
|
||||
/// dalek `SigningKey`. That copy is a `Zeroizing` buffer, not a bare array that
|
||||
/// stays on the stack until the function returns.
|
||||
#[test]
|
||||
fn profile_signing_key_bytes_are_zeroizing_and_wipe() {
|
||||
let secret = [0x5au8; 32];
|
||||
let bytes = profile::signing_key_bytes(&secret).expect("32 bytes");
|
||||
|
||||
let _: &Zeroizing<[u8; 32]> = &bytes;
|
||||
assert_eq!(&bytes[..], &secret[..], "buffer must hold the secret");
|
||||
|
||||
let mut probe = std::mem::ManuallyDrop::new(bytes);
|
||||
let after = unsafe { drop_in_place_and_peek_zeroizing_u8x32(&mut probe) };
|
||||
|
||||
assert_eq!(after, [0u8; 32], "identity secret survived its drop");
|
||||
}
|
||||
|
||||
/// A length-mismatched secret is an error, not a truncated/padded key.
|
||||
#[test]
|
||||
fn profile_signing_key_bytes_rejects_a_short_secret() {
|
||||
assert!(profile::signing_key_bytes(&[7u8; 31]).is_err());
|
||||
assert!(profile::signing_key_bytes(&[7u8; 33]).is_err());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue