transport: keep each IFAC key in one wiped allocation shared by its interface records

This commit is contained in:
DeFiDude committed 2026-10-25 11:50:58 -06:00
1 parent 3311c0a7b1
commit 6aa1d4bbf1
17 files changed
+173 -51

No files matched your search

+1
View File
@@ -36,6 +36,7 @@
- A 64-byte identity file always loads as a raw key, as in Python Reticulum. About one key in 29,000 began with bytes that were misread as the older envelope format, and its identity failed to load.
- Writing, verifying and recovering state files retries a read that a signal interrupts instead of failing.
- Interface options wipe their IFAC passphrase when dropped, and the debug output of IFAC settings no longer shows it.
- Each interface's IFAC key lives in one allocation that is wiped when dropped, so interface tables no longer leave copies of it in freed memory.
## 1.4.0 - 2026-10-12
+5
View File
@@ -124,6 +124,11 @@ file larger than 1 KiB.
passphrase is wiped when the options are dropped: read it with
`.as_deref().map(String::as_str)` and wrap a new one in `Zeroizing::new`.
`RuntimeInterfaceIfacConfig` prints `<redacted>` in place of its passphrase.
`InterfaceEntry::ifac_key` is `Option<rns_identity::ifac::IfacKey>`, one
allocation that clones share and that is wiped when the last one drops, so
interface tables never copy the key. `with_ifac` still takes the key bytes;
otherwise set `Some(key.into())` or `IfacKey::derive(network_name,
passphrase)`, and read the bytes through `&*key`.
rns-crypto enables the `zeroize` features of `aes` and `cbc`, so AES key
schedules and CBC state are wiped when dropped; dependents that build with
`--locked` refresh their lock files.
+13
View File
@@ -248,6 +248,19 @@ pub mod rns_identity::ifac
pub enum rns_identity::ifac::IfacError
pub rns_identity::ifac::IfacError::HkdfFailed(rns_crypto::hkdf::HkdfError)
pub rns_identity::ifac::IfacError::InvalidSalt
pub struct rns_identity::ifac::IfacKey(_)
impl rns_identity::ifac::IfacKey
pub fn rns_identity::ifac::IfacKey::derive(core::option::Option<&str>, core::option::Option<&str>) -> core::result::Result<Self, rns_identity::ifac::IfacError>
impl core::cmp::Eq for rns_identity::ifac::IfacKey
impl core::cmp::PartialEq for rns_identity::ifac::IfacKey
pub fn rns_identity::ifac::IfacKey::eq(&self, &Self) -> bool
impl core::convert::From<[u8; 64]> for rns_identity::ifac::IfacKey
pub fn rns_identity::ifac::IfacKey::from([u8; 64]) -> Self
impl core::fmt::Debug for rns_identity::ifac::IfacKey
pub fn rns_identity::ifac::IfacKey::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result
impl core::ops::deref::Deref for rns_identity::ifac::IfacKey
pub type rns_identity::ifac::IfacKey::Target = [u8; 64]
pub fn rns_identity::ifac::IfacKey::deref(&self) -> &[u8; 64]
pub const rns_identity::ifac::IFAC_SALT: &str
pub fn rns_identity::ifac::derive_ifac_identity(core::option::Option<&str>, core::option::Option<&str>) -> core::result::Result<(rns_identity::identity::Identity, [u8; 64], [u8; 64]), rns_identity::ifac::IfacError>
pub fn rns_identity::ifac::derive_ifac_key(core::option::Option<&str>, core::option::Option<&str>) -> core::result::Result<[u8; 64], rns_identity::ifac::IfacError>
+1 -1
View File
@@ -1362,7 +1362,7 @@ pub rns_transport::messages::InterfaceEntry::announce_rate_target: core::option:
pub rns_transport::messages::InterfaceEntry::announces_from_internal: bool
pub rns_transport::messages::InterfaceEntry::bitrate: u64
pub rns_transport::messages::InterfaceEntry::direction: rns_transport::constants::InterfaceDirection
pub rns_transport::messages::InterfaceEntry::ifac_key: core::option::Option<[u8; 64]>
pub rns_transport::messages::InterfaceEntry::ifac_key: core::option::Option<rns_identity::ifac::IfacKey>
pub rns_transport::messages::InterfaceEntry::ifac_size: usize
pub rns_transport::messages::InterfaceEntry::ifac_violations: u64
pub rns_transport::messages::InterfaceEntry::ingress: rns_transport::ingress::IngressController
+4 -3
View File
@@ -42,8 +42,8 @@
"tier": "candidate-stable",
"compatibility": "reviewed-snapshot",
"snapshot": "api/snapshots/rns-identity.txt",
"itemCount": 417,
"sha256": "7bafe01c7a5a5a88cedb1ed3207008a5373a691b3b014dd3ebd1ee40b4ac4293"
"itemCount": 430,
"sha256": "3ea675b37cbbbb57d60659316d56f2582da42558b66760a87092018bca3d15e2"
},
{
"name": "rns-transport",
@@ -52,7 +52,7 @@
"compatibility": "reviewed-snapshot",
"snapshot": "api/snapshots/rns-transport.txt",
"itemCount": 1947,
"sha256": "43b699055b574dd1c04ef5b0add1c49cdeef65570023cfed9de3f0baf6bc5396"
"sha256": "79cd60b1cde9c92e97f58ded693d3754b53311ec16f161ffa5b90775ec3c4a45"
},
{
"name": "rns-link",
@@ -134,6 +134,7 @@
"pub rns_transport::discovery::app_data::DiscoveryInfo::height: f64",
"pub rns_transport::discovery::app_data::DiscoveryInfo::latitude: f64",
"pub rns_transport::discovery::app_data::DiscoveryInfo::longitude: f64",
"pub rns_transport::messages::InterfaceEntry::ifac_key: core::option::Option<[u8; 64]>",
"pub rns_transport::tunnel::TunnelEntry::interface_id: rns_transport::messages::InterfaceId"
],
"rns-link": [
+71 -2
View File
@@ -1,3 +1,5 @@
use std::sync::Arc;
use rns_crypto::hkdf::hkdf_sha256;
use rns_crypto::sha::sha256;
use thiserror::Error;
@@ -28,6 +30,16 @@ pub fn derive_ifac_key(
network_name: Option<&str>,
passphrase: Option<&str>,
) -> Result<[u8; 64], IfacError> {
let mut key = [0u8; 64];
derive_into(network_name, passphrase, &mut key)?;
Ok(key)
}
fn derive_into(
network_name: Option<&str>,
passphrase: Option<&str>,
key: &mut [u8; 64],
) -> Result<(), IfacError> {
let mut ifac_origin = Zeroizing::new(Vec::with_capacity(64));
if let Some(name) = network_name {
@@ -42,9 +54,55 @@ pub fn derive_ifac_key(
let salt = hex_decode(IFAC_SALT).ok_or(IfacError::InvalidSalt)?;
let derived = hkdf_sha256(64, &*ifac_origin_hash, Some(&salt), None)?;
let mut key = [0u8; 64];
key.copy_from_slice(&derived);
Ok(key)
Ok(())
}
/// A derived IFAC key in one heap allocation, wiped when its last clone
/// drops. Clones share the allocation, so tables and queues that move or copy
/// an interface's settings never copy the key.
#[derive(Clone)]
pub struct IfacKey(Arc<Zeroizing<[u8; 64]>>);
impl IfacKey {
/// [`derive_ifac_key`], written straight into the shared allocation.
pub fn derive(network_name: Option<&str>, passphrase: Option<&str>) -> Result<Self, IfacError> {
let mut key = Arc::new(Zeroizing::new([0u8; 64]));
derive_into(
network_name,
passphrase,
Arc::get_mut(&mut key).expect("a new Arc is unique"),
)?;
Ok(Self(key))
}
}
impl From<[u8; 64]> for IfacKey {
fn from(key: [u8; 64]) -> Self {
Self(Arc::new(Zeroizing::new(key)))
}
}
impl std::ops::Deref for IfacKey {
type Target = [u8; 64];
fn deref(&self) -> &[u8; 64] {
&self.0
}
}
impl PartialEq for IfacKey {
fn eq(&self, other: &Self) -> bool {
self.0[..] == other.0[..]
}
}
impl Eq for IfacKey {}
impl std::fmt::Debug for IfacKey {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str("IfacKey(<redacted>)")
}
}
/// Build the IFAC identity plus a self-signature over `SHA-256(ifac_key)`.
@@ -92,6 +150,17 @@ fn hex_decode(s: &str) -> Option<Vec<u8>> {
mod tests {
use super::*;
#[test]
fn shared_key_matches_the_derived_bytes() {
let key = IfacKey::derive(Some("testnet"), Some("password")).unwrap();
assert_eq!(
*key,
derive_ifac_key(Some("testnet"), Some("password")).unwrap()
);
assert_eq!(key, IfacKey::from(*key));
assert_eq!(format!("{key:?}"), "IfacKey(<redacted>)");
}
#[test]
fn test_ifac_derivation_deterministic() {
let key1 = derive_ifac_key(Some("testnet"), Some("password")).unwrap();
+28 -26
View File
@@ -3,6 +3,7 @@
//! to a Shared instance over a local socket; **Standalone** owns its
//! interfaces and exposes no IPC. Python: `RNS/Reticulum.py`.
use rns_identity::ifac::IfacKey;
use std::collections::HashMap;
use std::future::Future;
use std::path::{Path, PathBuf};
@@ -61,7 +62,7 @@ struct InterfaceControlMetadata {
ingress_overrides: rns_transport::ingress::IngressOverrides,
// Parent IFAC, inherited by accepted child connections (Python parity:
// spawned interfaces copy the listener's ifac_size/netname/netkey).
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
ifac_size: usize,
ifac_netname: Option<String>,
/// The host and port a client interface connects to (Python
@@ -96,7 +97,7 @@ impl InterfaceIfacStats {
.get(&id)
.and_then(|control| {
Some((
control.ifac_key?,
control.ifac_key.clone()?,
control.ifac_size,
control.ifac_netname.clone(),
))
@@ -3895,7 +3896,7 @@ fn child_registration_from_parent(
) -> (
rns_transport::messages::InterfaceRole,
rns_transport::ingress::IngressOverrides,
Option<[u8; 64]>,
Option<IfacKey>,
usize,
) {
let parent_control = parent_id.and_then(|parent_id| {
@@ -3917,7 +3918,7 @@ fn child_registration_from_parent(
.map(|control| {
(
control.ingress_overrides,
control.ifac_key,
control.ifac_key.clone(),
control.ifac_size,
)
})
@@ -4457,7 +4458,7 @@ async fn register_interface_handle_with_role_and_overrides(
handle: rns_interface::traits::InterfaceHandle,
role: rns_transport::messages::InterfaceRole,
ingress_overrides: rns_transport::ingress::IngressOverrides,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
ifac_size: usize,
interface_controls: &InterfaceControlMap,
interface_registry: &InterfaceRegistry,
@@ -4487,7 +4488,7 @@ async fn register_interface_handle_with_role_and_overrides_and_spawn_permit(
handle: rns_interface::traits::InterfaceHandle,
role: rns_transport::messages::InterfaceRole,
ingress_overrides: rns_transport::ingress::IngressOverrides,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
ifac_size: usize,
interface_controls: &InterfaceControlMap,
interface_registry: &InterfaceRegistry,
@@ -4517,7 +4518,7 @@ async fn register_owned_interface_handle_with_role_and_overrides(
owned: OwnedInterfaceHandle,
role: rns_transport::messages::InterfaceRole,
ingress_overrides: rns_transport::ingress::IngressOverrides,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
ifac_size: usize,
interface_controls: &InterfaceControlMap,
interface_registry: &InterfaceRegistry,
@@ -4549,7 +4550,7 @@ async fn prepare_interface_with_role_and_overrides(
owned: OwnedInterfaceHandle,
role: rns_transport::messages::InterfaceRole,
ingress_overrides: rns_transport::ingress::IngressOverrides,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
ifac_size: usize,
interface_controls: &InterfaceControlMap,
interface_registry: &InterfaceRegistry,
@@ -4627,6 +4628,7 @@ async fn prepare_interface_with_role_and_overrides(
.expect("interface_controls mutex poisoned");
// A spawned child's IFAC is its parent's, network name included.
let ifac_netname = ifac_key
.as_ref()
.and(handle.parent_id)
.and_then(|parent| controls.get(&parent))
.and_then(|parent| parent.ifac_netname.clone());
@@ -4637,7 +4639,7 @@ async fn prepare_interface_with_role_and_overrides(
registry_owner,
role,
ingress_overrides: ingress_overrides.clone(),
ifac_key,
ifac_key: ifac_key.clone(),
ifac_size,
ifac_netname,
client_target: None,
@@ -4701,7 +4703,7 @@ async fn register_interface_with_post_init(
transport_tx: &mpsc::Sender<TransportMessage>,
handle: rns_interface::traits::InterfaceHandle,
post_init: &interface_factory::InterfacePostInit,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
interface_controls: &InterfaceControlMap,
interface_registry: &InterfaceRegistry,
kind: InterfaceKind,
@@ -4724,7 +4726,7 @@ async fn register_interface_with_post_init_and_spawn_permit(
transport_tx: &mpsc::Sender<TransportMessage>,
handle: rns_interface::traits::InterfaceHandle,
post_init: &interface_factory::InterfacePostInit,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
interface_controls: &InterfaceControlMap,
interface_registry: &InterfaceRegistry,
kind: InterfaceKind,
@@ -4748,7 +4750,7 @@ async fn register_owned_interface_with_post_init(
transport_tx: &mpsc::Sender<TransportMessage>,
owned: OwnedInterfaceHandle,
post_init: &interface_factory::InterfacePostInit,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
interface_controls: &InterfaceControlMap,
interface_registry: &InterfaceRegistry,
kind: InterfaceKind,
@@ -4839,7 +4841,7 @@ fn configured_peer_post_init(
async fn prepare_interface_with_post_init(
owned: OwnedInterfaceHandle,
post_init: &interface_factory::InterfacePostInit,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
interface_controls: &InterfaceControlMap,
interface_registry: &InterfaceRegistry,
kind: InterfaceKind,
@@ -4944,9 +4946,9 @@ async fn prepare_interface_with_post_init(
registry_owner,
role: rns_transport::messages::InterfaceRole::Normal,
ingress_overrides: post_init.ingress_overrides.clone(),
ifac_key,
ifac_netname: ifac_key.as_ref().and(post_init.ifac_network_name.clone()),
ifac_key: ifac_key.clone(),
ifac_size: post_init.ifac_size.unwrap_or(post_init.default_ifac_size),
ifac_netname: ifac_key.and(post_init.ifac_network_name.clone()),
client_target: None,
autoconnect_source: None,
},
@@ -5049,7 +5051,7 @@ enum SingleRegistrationSpec {
owned: OwnedInterfaceHandle,
role: rns_transport::messages::InterfaceRole,
ingress_overrides: rns_transport::ingress::IngressOverrides,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
ifac_size: usize,
kind: InterfaceKind,
multipoint: bool,
@@ -5057,7 +5059,7 @@ enum SingleRegistrationSpec {
PostInit {
owned: OwnedInterfaceHandle,
post_init: interface_factory::InterfacePostInit,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
kind: InterfaceKind,
},
}
@@ -5441,7 +5443,7 @@ async fn register_interfaces_with_post_init_batch(
transport_tx: &mpsc::Sender<TransportMessage>,
handles: Vec<OwnedInterfaceHandle>,
post_init: &interface_factory::InterfacePostInit,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
interface_controls: &InterfaceControlMap,
interface_registry: &InterfaceRegistry,
kind: InterfaceKind,
@@ -5487,7 +5489,7 @@ async fn batch_registration_worker(
transport_tx: mpsc::Sender<TransportMessage>,
handles: Vec<OwnedInterfaceHandle>,
post_init: interface_factory::InterfacePostInit,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
interface_controls: InterfaceControlMap,
interface_registry: InterfaceRegistry,
kind: InterfaceKind,
@@ -5525,7 +5527,7 @@ async fn register_interfaces_with_post_init_batch_transaction(
transport_tx: &mpsc::Sender<TransportMessage>,
handles: Vec<OwnedInterfaceHandle>,
post_init: &interface_factory::InterfacePostInit,
ifac_key: Option<[u8; 64]>,
ifac_key: Option<IfacKey>,
interface_controls: &InterfaceControlMap,
interface_registry: &InterfaceRegistry,
kind: InterfaceKind,
@@ -5537,7 +5539,7 @@ async fn register_interfaces_with_post_init_batch_transaction(
match prepare_interface_with_post_init(
owned,
post_init,
ifac_key,
ifac_key.clone(),
interface_controls,
interface_registry,
kind,
@@ -5720,9 +5722,9 @@ fn remove_interface_control_if_owner(
fn derive_ifac_key_from_post_init(
post_init: &interface_factory::InterfacePostInit,
) -> Option<[u8; 64]> {
) -> Option<IfacKey> {
if post_init.ifac_network_name.is_some() || post_init.ifac_passphrase.is_some() {
rns_identity::ifac::derive_ifac_key(
IfacKey::derive(
post_init.ifac_network_name.as_deref(),
post_init.ifac_passphrase.as_deref().map(String::as_str),
)
@@ -9525,7 +9527,7 @@ mod tests {
prepare_interface_with_post_init(
handle.into(),
&post_init,
Some([1; 64]),
Some([1; 64].into()),
&controls,
&registry,
InterfaceKind::Standard,
@@ -9536,7 +9538,7 @@ mod tests {
handle.into(),
rns_transport::messages::InterfaceRole::Normal,
Default::default(),
Some([1; 64]),
Some([1; 64].into()),
size,
&controls,
&registry,
@@ -14254,7 +14256,7 @@ egress_control = Yes
&transport_tx,
test_interface_handle(parent_id, None, "ifac-parent"),
&post_init,
ifac_key,
ifac_key.clone(),
&interface_controls,
&interface_registry,
InterfaceKind::Standard,
@@ -42,7 +42,7 @@ pub(super) struct OfferedAnnounce {
pub raw: Bytes,
pub destination: [u8; 16],
pub route: Option<path_recovery::RouteVersion>,
pub policy: (u64, u64, Option<[u8; 64]>, usize),
pub policy: (u64, u64, Option<rns_identity::ifac::IfacKey>, usize),
pub receipt: crate::background_egress::BackgroundOfferReceipt,
}
@@ -589,7 +589,7 @@ impl TransportActor {
(
entry.bitrate,
entry.announce_cap.to_bits(),
entry.ifac_key,
entry.ifac_key.clone(),
entry.ifac_size,
) == offered.policy
&& now_f64() >= entry.announce_allowed_at
+1 -1
View File
@@ -113,7 +113,7 @@ impl TransportActor {
} else {
self.interfaces
.get(&packet.interface_id)
.map(|entry| (entry.ifac_key, entry.ifac_size))
.map(|entry| (entry.ifac_key.clone(), entry.ifac_size))
};
let raw: bytes::Bytes = match ifac {
Some((Some(ifac_key), ifac_size)) => {
@@ -538,7 +538,7 @@ impl TransportActor {
policy: (
entry.bitrate,
entry.announce_cap.to_bits(),
entry.ifac_key,
entry.ifac_key.clone(),
entry.ifac_size,
),
receipt,
+3 -3
View File
@@ -5362,7 +5362,7 @@ mod tests {
// Configure IFAC on this interface
let ifac_key = rns_identity::ifac::derive_ifac_key(Some("test"), Some("pass")).unwrap();
entry.ifac_key = Some(ifac_key);
entry.ifac_key = Some(ifac_key.into());
entry.ifac_size = 4;
actor.interfaces.insert(1, entry);
@@ -5385,7 +5385,7 @@ mod tests {
let ifac_size = 4;
let (mut entry1, _rx1) = make_test_interface("ifac_in");
entry1.ifac_key = Some(ifac_key);
entry1.ifac_key = Some(ifac_key.into());
entry1.ifac_size = ifac_size;
actor.interfaces.insert(1, entry1);
@@ -5425,7 +5425,7 @@ mod tests {
let ifac_size = 4;
let (mut entry1, _rx1) = make_test_interface("ifac_in");
entry1.ifac_key = Some(ifac_key);
entry1.ifac_key = Some(ifac_key.into());
entry1.ifac_size = ifac_size;
actor.interfaces.insert(1, entry1);
@@ -39,7 +39,7 @@ async fn announce_admission_partial_targets_keep_exact_wire_without_replay() {
let (mut actor, _) = TransportActor::new();
let (first, mut first_rx) = limited();
let (mut second, mut second_rx) = limited();
second.ifac_key = Some([9; 64]);
second.ifac_key = Some([9; 64].into());
second.ifac_size = 16;
second.tx.try_send(Bytes::from_static(b"ordinary")).unwrap();
actor.interfaces.insert(1, first);
@@ -61,7 +61,7 @@ async fn announce_admission_partial_targets_keep_exact_wire_without_replay() {
&raw,
rns_wire::flags::HeaderType::Header1
)));
actor.interfaces.get_mut(&2).unwrap().ifac_key = Some([7; 64]);
actor.interfaces.get_mut(&2).unwrap().ifac_key = Some([7; 64].into());
second_rx.try_recv().unwrap();
actor.process_pending_announce_admissions();
assert_eq!(second_rx.try_recv().unwrap().as_ref(), expected);
@@ -10,7 +10,7 @@ fn ifac_hub() -> (TransportActor, mpsc::Receiver<Bytes>) {
actor.transport_identity_hash = Some([0x42; 16]);
let (mut entry, rx) = make_test_interface("held_ifac");
entry.ifac_key =
Some(rns_identity::ifac::derive_ifac_key(Some("held"), Some("announces")).unwrap());
Some(rns_identity::ifac::IfacKey::derive(Some("held"), Some("announces")).unwrap());
entry.ifac_size = 8;
actor.interfaces.insert(1, entry);
(actor, rx)
@@ -87,7 +87,7 @@ fn a_wire_announce_without_valid_ifac_is_dropped_and_never_held() {
ingress.received_announce();
}
assert!(ingress.should_ingress_limit(), "precondition: a burst");
let ifac_key = actor.interfaces[&1].ifac_key.unwrap();
let ifac_key = actor.interfaces[&1].ifac_key.clone().unwrap();
let (signed, signed_destination) = make_valid_announce("held.ifac.signed", 1);
let (unsigned, unsigned_destination) = make_valid_announce("held.ifac.unsigned", 1);
@@ -21,7 +21,7 @@ fn attach(actor: &mut TransportActor, id: InterfaceId) -> mpsc::Receiver<Bytes>
fn attach_ifac(actor: &mut TransportActor, id: InterfaceId, ifac_key: [u8; 64]) {
let (mut entry, _rx) = make_test_interface(&format!("ifac_{id}"));
entry.ifac_key = Some(ifac_key);
entry.ifac_key = Some(ifac_key.into());
entry.ifac_size = 8;
actor.interfaces.insert(id, entry);
}
@@ -26,7 +26,7 @@ fn payload(mode: u8, mtu: u32) -> Vec<u8> {
fn packet_capacity_attenuates_two_relays_without_changing_key_body() {
let input = capacity(10_000, 10_000, true);
let mut middle = capacity(1500, 1500, true);
middle.ifac_key = Some([1; 64]);
middle.ifac_key = Some([1; 64].into());
middle.ifac_size = 16;
let output = capacity(1000, 1000, true);
let original = payload(1, 4096);
@@ -75,7 +75,7 @@ fn packet_capacity_opaque_modes_only_transit_with_exact_supported_shape() {
);
}
let mut narrow = capacity(500, 508, false);
narrow.ifac_key = Some([1; 64]);
narrow.ifac_key = Some([1; 64].into());
narrow.ifac_size = 9;
assert_eq!(narrow.effective_clear_mtu().unwrap(), 499);
assert!(
@@ -88,7 +88,7 @@ fn packet_capacity_checks_clear_and_wire_with_ifac_before_admission() {
let (mut actor, _) = TransportActor::new();
let (mut entry, mut rx) = make_test_interface("radio");
entry.packet_capacity = InterfacePacketCapacity::new(500, 508, false);
entry.ifac_key = Some([5; 64]);
entry.ifac_key = Some([5; 64].into());
entry.ifac_size = 8;
actor.interfaces.insert(1, entry);
let mut raw = make_data_packet([9; 16], 0).to_vec();
+2 -2
View File
@@ -252,7 +252,7 @@ pub struct InterfaceEntry {
pub bitrate: u64,
pub mtu: u32,
pub tx: mpsc::Sender<Bytes>,
pub ifac_key: Option<[u8; 64]>,
pub ifac_key: Option<rns_identity::ifac::IfacKey>,
pub ifac_size: usize,
pub announce_cap: f64,
/// Earliest Unix time at which the next announce may be sent — enforces
@@ -388,7 +388,7 @@ impl InterfaceEntry {
}
pub fn with_ifac(mut self, key: [u8; 64], size: usize) -> Self {
self.ifac_key = Some(key);
self.ifac_key = Some(key.into());
self.ifac_size = size;
self
}
+33 -2
View File
@@ -1,14 +1,18 @@
//! IFAC masks, derived from the interface key, must not survive in freed heap
//! memory once a packet is signed or verified.
//! IFAC keys, and the masks derived from them, must not survive in freed heap
//! memory once a packet is signed or verified or an interface is dropped.
#[path = "../../rns-crypto/tests/residue/mod.rs"]
mod residue;
use std::collections::HashMap;
use residue::{assert_no_residue, freed_by, pseudo_random, serial};
use rns_crypto::ed25519::Ed25519PrivateKey;
use rns_crypto::hkdf::hkdf_sha256;
use rns_identity::ifac::derive_ifac_key;
use rns_transport::constants::{InterfaceDirection, InterfaceMode};
use rns_transport::ifac::{ifac_sign, ifac_verify};
use rns_transport::messages::InterfaceEntry;
const IFAC_SIZE: usize = 16;
@@ -53,3 +57,30 @@ fn ifac_verify_frees_no_mask() {
assert_no_residue(&freed, &[("IFAC mask", &mask)]);
assert_eq!(verified.unwrap(), packet);
}
#[test]
fn an_interface_table_frees_no_ifac_keys() {
let _serial = serial();
let keys: Vec<[u8; 64]> = (0..48).map(|seed| pseudo_random(200 + seed)).collect();
let (tx, _rx) = tokio::sync::mpsc::channel(1);
// Growing the table moves every entry, so each key is moved several times.
let ((), freed) = freed_by(|| {
let mut interfaces = HashMap::new();
for (id, key) in keys.iter().enumerate() {
let entry = InterfaceEntry::new(
format!("ifac-{id}"),
InterfaceMode::Full,
InterfaceDirection::bidirectional(),
0,
500,
tx.clone(),
)
.with_ifac(*key, IFAC_SIZE);
interfaces.insert(id as u64, entry);
}
});
let secrets: Vec<(&str, &[u8])> = keys.iter().map(|key| ("IFAC key", &key[..])).collect();
assert_no_residue(&freed, &secrets);
}