Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ thiserror = "1"
tokio = { version = "1" }

# Crypto & Networking
zeroize = { version = "1", features = ["derive"] }
iroh = "0.97"
iroh-base = "0.97"
iroh-gossip = "0.97"
Expand Down
1 change: 1 addition & 0 deletions crates/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sha2 = "0.10"
rand = "0.8"
serde = { workspace = true }
thiserror = { workspace = true }
zeroize = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom_02 = { package = "getrandom", version = "0.2", features = ["js"] }
Expand Down
16 changes: 14 additions & 2 deletions crates/crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use rand::RngCore;
use serde::{Deserialize, Serialize};
use sha2::Sha256;
use x25519_dalek::{PublicKey as X25519Public, StaticSecret as X25519Secret};
use zeroize::ZeroizeOnDrop;

use willow_identity::Identity;

Expand Down Expand Up @@ -54,8 +55,11 @@ pub enum CryptoError {
// ───── Types ────────────────────────────────────────────────────────────────

/// A 256-bit symmetric key for encrypting a channel's messages.
#[derive(Clone, PartialEq)]
pub struct ChannelKey(pub(crate) [u8; 32]);
///
/// The wrapped bytes are zeroized when the value is dropped so secret
/// material doesn't linger in freed memory.
#[derive(Clone, PartialEq, ZeroizeOnDrop)]
pub struct ChannelKey(#[zeroize] pub(crate) [u8; 32]);

impl std::fmt::Debug for ChannelKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down Expand Up @@ -749,6 +753,14 @@ mod tests {
assert!(!debug.contains(&format!("{:02x}", key.as_bytes()[0])));
}

/// Compile-time guarantee that [`ChannelKey`] zeroizes its secret
/// bytes on drop. See issue #127.
#[test]
fn channel_key_is_zeroize_on_drop() {
fn assert_zeroize_on_drop<T: zeroize::ZeroizeOnDrop>() {}
assert_zeroize_on_drop::<ChannelKey>();
}

// ── Issue #110: ratchet counter DoS bound ──────────────────────

/// Regression guard for issue #110: a sealed packet with a huge
Expand Down
2 changes: 2 additions & 0 deletions crates/identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ serde = { workspace = true }
thiserror = { workspace = true }
chrono = { workspace = true }
rand = "0.9"
zeroize = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom_02 = { package = "getrandom", version = "0.2", features = ["js"] }
getrandom_03 = { package = "getrandom", version = "0.3", features = ["wasm_js"] }

[dev-dependencies]
tokio = { workspace = true }
tempfile = "3"
Loading
Loading