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
|
|
@ -1,4 +1,5 @@
|
|||
use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
|
|
@ -30,6 +31,23 @@ pub fn validate(display_name: &str, bio: &str, xmr_addr: &str) -> Result<()> {
|
|||
check_fields(display_name, bio, xmr_addr)
|
||||
}
|
||||
|
||||
/// The raw 32-byte identity-secret copy that `ed25519-dalek` needs in order to
|
||||
/// build a `SigningKey`.
|
||||
///
|
||||
/// `SigningKey` wipes its own copy on drop (its default `zeroize` feature);
|
||||
/// the raw bytes are ours to wipe, so they live in a `Zeroizing` buffer rather
|
||||
/// than on the stack in a bare `[u8; 32]`. Same pattern as `pay::sign_bytes`
|
||||
/// and `qr::encode`; `loc::sign` shares this helper for the identical copy it
|
||||
/// used to make.
|
||||
pub fn signing_key_bytes(identity_sk: &[u8]) -> Result<Zeroizing<[u8; 32]>> {
|
||||
if identity_sk.len() != 32 {
|
||||
return Err(Error("identity secret key must be 32 bytes".into()));
|
||||
}
|
||||
let mut bytes = Zeroizing::new([0u8; 32]);
|
||||
bytes[..].copy_from_slice(identity_sk);
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
pub fn sign(
|
||||
identity_sk: &[u8],
|
||||
display_name: &str,
|
||||
|
|
@ -38,9 +56,7 @@ pub fn sign(
|
|||
ts: i64,
|
||||
) -> Result<Profile> {
|
||||
check_fields(display_name, bio, xmr_addr)?;
|
||||
let sk_bytes: [u8; 32] = identity_sk
|
||||
.try_into()
|
||||
.map_err(|_| Error("identity secret key must be 32 bytes".into()))?;
|
||||
let sk_bytes = signing_key_bytes(identity_sk)?;
|
||||
let sk = SigningKey::from_bytes(&sk_bytes);
|
||||
let sig = sk
|
||||
.sign(&sign_msg_v2(display_name, bio, xmr_addr, ts))
|
||||
|
|
|
|||
Loading…
Reference in a new issue