security: the pkarr registry stops carrying node names
Build Debug APK / build (push) Successful in 3m56s
Build Debug APK / build (push) Successful in 3m56s
The ensemble registry is a DNS packet on the mainline DHT, fetched with nothing but the ensemble public key -- which syn ensemble info prints and the pkdns bootstrap link embeds. Every entry carried name_len || name_bytes in the clear, so a device label, and through it its owner, was world-readable to anyone who had ever seen that key, a removed node included. Sealing it there was the wrong trade. publish_membership runs only during ensemble init/register, while the ensemble secret is briefly in memory, and no code path ever rewrites the record -- so the name in it was a snapshot from join time that no later rename reached. It cost privacy to publish a value that was already drifting, and it cost packet budget: variable-length entries meant how many members fit in pkarr's 1000 bytes depended on how long people's laptops were called. Entries are now fixed-size at 105 bytes, and six still fit. The roster loses nothing gossip does not replace: names arrive sealed over the topic and persist in peer_nodes, so a member reads as (unnamed) only until it first announces itself. The version byte stays at 1 and the decoder takes a fixed-length prefix, ignoring whatever follows, so a record published by an older build still bootstraps -- its trailing name simply never read. A test covers exactly that, since losing it would cost existing ensembles their bootstrap. syn ensemble dht-peers and ensemble info list registry entries without names rather than borrowing one gossip happened to supply: those listings are what is *published*, and a placeholder is the honest answer. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gkup9bGFrnEaBVG8TQTJrS
This commit is contained in:
1 parent
a33f20d7eb
commit
6e13f74d0a
5 files changed
+88
-53
No files matched your search
+4
-2
@@ -121,8 +121,10 @@ Node public keys are 32-byte Ed25519 keys. The current hex encoding produces a
|
||||
64-character string, which is too long for casual display.
|
||||
|
||||
**Preferred display strategy:**
|
||||
- Show the node's human-readable name (from local settings or
|
||||
`RegistryMember.node_name`) when available.
|
||||
- Show the node's human-readable name (from local settings for this node, or
|
||||
the `peer_nodes` row a gossip announcement wrote for another) when
|
||||
available. Not from the pkarr registry, which carries no names — see ADR
|
||||
0044.
|
||||
- Fall back to a short identifier derived from the public key.
|
||||
|
||||
**Encoding considerations:**
|
||||
|
||||
@@ -199,7 +199,11 @@ pub async fn cmd_ensemble_dht_peers(membership: Option<&EnsembleMembership>) ->
|
||||
|
||||
for m in &members {
|
||||
let node_hex = m.node_id_hex();
|
||||
let name = styled_node_name(m.node_name.as_deref());
|
||||
// The registry holds addressing, not names — it is a world-readable
|
||||
// DHT record (ADR 0044). This listing is what is *published*, so a
|
||||
// placeholder here is the honest answer rather than a name borrowed
|
||||
// from what gossip happens to have told us.
|
||||
let name = styled_node_name(None);
|
||||
let registered = chrono::DateTime::from_timestamp(m.created_at_secs as i64, 0)
|
||||
.map(|dt| dt.format("%Y-%m-%d").to_string())
|
||||
.unwrap_or_else(|| "?".to_string());
|
||||
@@ -250,7 +254,9 @@ pub async fn cmd_ensemble_gossip_status(
|
||||
Ok(members) => {
|
||||
lines.push(format!("DHT registry ({} node(s)):", members.len()));
|
||||
for m in &members {
|
||||
let name = styled_node_name(m.node_name.as_deref());
|
||||
// No name in a world-readable DHT record — see ADR 0044 and
|
||||
// the note in `cmd_ensemble_dht_peers`.
|
||||
let name = styled_node_name(None);
|
||||
let registered = chrono::DateTime::from_timestamp(m.created_at_secs as i64, 0)
|
||||
.map(|dt| dt.format("%Y-%m-%d").to_string())
|
||||
.unwrap_or_else(|| "?".to_string());
|
||||
|
||||
@@ -65,7 +65,6 @@ pub fn create_new_ensemble(
|
||||
/// Parse a keyphrase, create a delegation cert for this node, and persist the membership.
|
||||
///
|
||||
/// The node keypair must already be saved (call [`SettingsStore::initialize_node`] first).
|
||||
/// Save any desired node name to settings before calling so it is included in the pkarr record.
|
||||
/// Errors if this node is already part of an ensemble.
|
||||
///
|
||||
/// Derives and stores the default vault key while the ensemble key is still in memory.
|
||||
@@ -77,12 +76,8 @@ pub async fn join_existing_ensemble(
|
||||
) -> Result<EnsembleMembership, InitError> {
|
||||
let (keypair, membership) = join_local(store, keyphrase)?;
|
||||
|
||||
let node_name =
|
||||
store.batch(|tx| store.load_settings(tx)).ok().flatten().and_then(|s| s.node_name);
|
||||
if let Ok(pkarr_client) = pkarr::Client::builder().build()
|
||||
&& let Err(e) =
|
||||
super::publish_membership(&keypair, &membership, node_name.as_deref(), &pkarr_client)
|
||||
.await
|
||||
&& let Err(e) = super::publish_membership(&keypair, &membership, &pkarr_client).await
|
||||
{
|
||||
log::warn!("Failed to publish membership to pkarr DHT: {e}");
|
||||
}
|
||||
|
||||
@@ -185,12 +185,23 @@ const DNS_HEADER_BYTES: usize = 12;
|
||||
const DNS_TXT_RECORD_OVERHEAD: usize = 17;
|
||||
|
||||
/// One node's entry as decoded from the ensemble's pkarr registry.
|
||||
///
|
||||
/// Deliberately just addressing: a pubkey and when it joined. The registry is
|
||||
/// a **world-readable record on the mainline DHT**, fetched with nothing but
|
||||
/// the ensemble public key — which `syn ensemble info` prints, which the
|
||||
/// pkdns bootstrap link embeds, and which is not a secret. What goes in it is
|
||||
/// therefore public, and a node's human-readable name is not (ADR 0044).
|
||||
///
|
||||
/// Names reach the roster over gossip instead, sealed to the ensemble
|
||||
/// ([`p2p::sealed_name`](crate::p2p::sealed_name)) and persisted in
|
||||
/// `peer_nodes` once heard. A member that has only ever been seen in the
|
||||
/// registry shows as `(unnamed)` until it announces itself, which is what the
|
||||
/// registry entry was worth anyway: it is written once at join and never
|
||||
/// updated, so the name in it was a snapshot that a later rename never reached.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RegistryMember {
|
||||
/// This node's Ed25519 public key bytes.
|
||||
pub node_pubkey: [u8; 32],
|
||||
/// Optional human-readable label for this node.
|
||||
pub node_name: Option<String>,
|
||||
/// Unix timestamp (seconds) at which this node registered.
|
||||
pub created_at_secs: u64,
|
||||
}
|
||||
@@ -218,23 +229,32 @@ impl RegistryMember {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wire size of a registry entry before base64: everything [`encode_registry_entry`]
|
||||
/// writes.
|
||||
const REGISTRY_ENTRY_BYTES: usize = 1 + 32 + 8 + 64;
|
||||
|
||||
/// Encode a registry entry into a base64url string for storage in a DNS TXT record.
|
||||
///
|
||||
/// Binary layout: `version(1) || node_pubkey(32) || created_at_secs(8 LE) || signature(64) || name_len(2 LE) || name_bytes`
|
||||
/// Binary layout: `version(1) || node_pubkey(32) || created_at_secs(8 LE) || signature(64)`
|
||||
///
|
||||
/// Version 1 entries once carried `name_len(2 LE) || name_bytes` after the
|
||||
/// signature. Nothing writes those any more (see [`RegistryMember`]), and
|
||||
/// nothing reads them: [`decode_registry_entry`] takes the fixed prefix and
|
||||
/// ignores whatever follows, so a record published by an older build still
|
||||
/// bootstraps — its trailing name is simply never looked at. The version byte
|
||||
/// stays at 1 for that reason; bumping it would make those records
|
||||
/// undecodable, which would cost the addressing this registry exists for to
|
||||
/// remove a field we can decline to read.
|
||||
fn encode_registry_entry(
|
||||
node_pubkey: &[u8; 32],
|
||||
created_at_secs: u64,
|
||||
sig_bytes: &[u8; 64],
|
||||
node_name: Option<&str>,
|
||||
) -> String {
|
||||
let name_bytes = node_name.unwrap_or("").as_bytes();
|
||||
let mut buf = Vec::with_capacity(107 + name_bytes.len());
|
||||
let mut buf = Vec::with_capacity(REGISTRY_ENTRY_BYTES);
|
||||
buf.push(1u8); // version
|
||||
buf.extend_from_slice(node_pubkey);
|
||||
buf.extend_from_slice(&created_at_secs.to_le_bytes());
|
||||
buf.extend_from_slice(sig_bytes);
|
||||
buf.extend_from_slice(&(name_bytes.len() as u16).to_le_bytes());
|
||||
buf.extend_from_slice(name_bytes);
|
||||
URL_SAFE_NO_PAD.encode(&buf)
|
||||
}
|
||||
|
||||
@@ -243,22 +263,13 @@ fn encode_registry_entry(
|
||||
/// Returns `None` if the data is malformed or uses an unknown version.
|
||||
fn decode_registry_entry(txt_str: &str) -> Option<(RegistryMember, [u8; 64])> {
|
||||
let bytes = URL_SAFE_NO_PAD.decode(txt_str).ok()?;
|
||||
if bytes.len() < 107 || bytes[0] != 1 {
|
||||
if bytes.len() < REGISTRY_ENTRY_BYTES || bytes[0] != 1 {
|
||||
return None; // too short or unknown version
|
||||
}
|
||||
let node_pubkey: [u8; 32] = bytes[1..33].try_into().ok()?;
|
||||
let created_at_secs = u64::from_le_bytes(bytes[33..41].try_into().ok()?);
|
||||
let sig_bytes: [u8; 64] = bytes[41..105].try_into().ok()?;
|
||||
let name_len = u16::from_le_bytes(bytes[105..107].try_into().ok()?) as usize;
|
||||
if bytes.len() < 107 + name_len {
|
||||
return None;
|
||||
}
|
||||
let node_name = if name_len == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(String::from_utf8(bytes[107..107 + name_len].to_vec()).ok()?)
|
||||
};
|
||||
Some((RegistryMember { node_pubkey, node_name, created_at_secs }, sig_bytes))
|
||||
Some((RegistryMember { node_pubkey, created_at_secs }, sig_bytes))
|
||||
}
|
||||
|
||||
/// Parse all `_syn` TXT records from a pkarr [`SignedPacket`] into a list of [`RegistryMember`]s.
|
||||
@@ -289,7 +300,6 @@ fn parse_registry_members(packet: &SignedPacket) -> Vec<RegistryMember> {
|
||||
pub async fn publish_membership(
|
||||
ensemble_keypair: &Keypair<EnsembleSecret>,
|
||||
membership: &EnsembleMembership,
|
||||
node_name: Option<&str>,
|
||||
pkarr_client: &PkarrClient,
|
||||
) -> Result<(), EnsembleError> {
|
||||
let pkarr_keypair = PkarrKeypair::from_secret_key(&ensemble_keypair.secret_key().to_bytes());
|
||||
@@ -321,7 +331,6 @@ pub async fn publish_membership(
|
||||
entries.push((
|
||||
RegistryMember {
|
||||
node_pubkey: this_node_pk,
|
||||
node_name: node_name.map(|s| s.to_string()),
|
||||
created_at_secs: membership.delegation_cert.created_at_secs,
|
||||
},
|
||||
sig_bytes,
|
||||
@@ -330,9 +339,7 @@ pub async fn publish_membership(
|
||||
// Pre-encode all entries and trim oldest until the packet fits.
|
||||
let mut encoded: Vec<String> = entries
|
||||
.iter()
|
||||
.map(|(m, sig)| {
|
||||
encode_registry_entry(&m.node_pubkey, m.created_at_secs, sig, m.node_name.as_deref())
|
||||
})
|
||||
.map(|(m, sig)| encode_registry_entry(&m.node_pubkey, m.created_at_secs, sig))
|
||||
.collect();
|
||||
|
||||
while estimated_packet_size(&encoded) > PKARR_PACKET_LIMIT && encoded.len() > 1 {
|
||||
@@ -527,29 +534,54 @@ mod tests {
|
||||
assert_eq!(estimated_packet_size(&[]), DNS_HEADER_BYTES);
|
||||
}
|
||||
|
||||
/// The DHT record is world-readable to anyone holding the ensemble public
|
||||
/// key, so nothing about the person may be in it (ADR 0044) — and an entry
|
||||
/// an older build published with a name still has to decode, or existing
|
||||
/// ensembles lose their bootstrap.
|
||||
#[test]
|
||||
fn test_estimated_packet_size_single_nameless_entry() {
|
||||
// A nameless entry is 107 binary bytes → 143 base64url chars.
|
||||
// Wire size: DNS_HEADER_BYTES + DNS_TXT_RECORD_OVERHEAD + 143 = 12 + 17 + 143 = 172.
|
||||
let entry = encode_registry_entry(&[0u8; 32], 0, &[0u8; 64], None);
|
||||
assert_eq!(entry.len(), 143);
|
||||
fn a_registry_entry_carries_no_name_and_an_old_one_still_decodes() {
|
||||
let entry = encode_registry_entry(&[3u8; 32], 42, &[0u8; 64]);
|
||||
let decoded = URL_SAFE_NO_PAD.decode(&entry).unwrap();
|
||||
assert_eq!(decoded.len(), REGISTRY_ENTRY_BYTES, "an entry is exactly its fixed fields");
|
||||
|
||||
// What a pre-ADR-0044 build wrote: the same prefix, then `name_len ||
|
||||
// name`. It must still yield the pubkey and timestamp a bootstrap
|
||||
// needs, and nothing else.
|
||||
let mut legacy = decoded.clone();
|
||||
legacy.extend_from_slice(&(13u16).to_le_bytes());
|
||||
legacy.extend_from_slice(b"Greg's laptop");
|
||||
let (member, _sig) =
|
||||
decode_registry_entry(&URL_SAFE_NO_PAD.encode(&legacy)).expect("v1 must still decode");
|
||||
assert_eq!(member.node_pubkey, [3u8; 32]);
|
||||
assert_eq!(member.created_at_secs, 42);
|
||||
}
|
||||
|
||||
/// Every entry is now the same size — the name was the only thing that
|
||||
/// varied, and it is gone (ADR 0044), so the member ceiling no longer
|
||||
/// depends on how long people's laptops are called.
|
||||
#[test]
|
||||
fn test_estimated_packet_size_single_entry() {
|
||||
// An entry is 105 binary bytes → 140 base64url chars.
|
||||
// Wire size: DNS_HEADER_BYTES + DNS_TXT_RECORD_OVERHEAD + 140 = 12 + 17 + 140 = 169.
|
||||
let entry = encode_registry_entry(&[0u8; 32], 0, &[0u8; 64]);
|
||||
assert_eq!(entry.len(), 140);
|
||||
let size = estimated_packet_size(&[entry]);
|
||||
assert_eq!(size, DNS_HEADER_BYTES + DNS_TXT_RECORD_OVERHEAD + 143);
|
||||
assert_eq!(size, DNS_HEADER_BYTES + DNS_TXT_RECORD_OVERHEAD + 140);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_packet_fits_six_nameless_entries() {
|
||||
// Six nameless entries: 12 + 6*160 = 972 ≤ 1000.
|
||||
fn test_packet_fits_six_entries() {
|
||||
// Six entries: 12 + 6*157 = 954 ≤ 1000.
|
||||
let entries: Vec<String> =
|
||||
(0..6).map(|_| encode_registry_entry(&[0u8; 32], 0, &[0u8; 64], None)).collect();
|
||||
(0..6).map(|_| encode_registry_entry(&[0u8; 32], 0, &[0u8; 64])).collect();
|
||||
assert!(estimated_packet_size(&entries) <= PKARR_PACKET_LIMIT);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_packet_overflows_seven_nameless_entries() {
|
||||
// Seven nameless entries: 12 + 7*160 = 1132 > 1000.
|
||||
fn test_packet_overflows_seven_entries() {
|
||||
// Seven entries: 12 + 7*157 = 1111 > 1000.
|
||||
let entries: Vec<String> =
|
||||
(0..7).map(|_| encode_registry_entry(&[0u8; 32], 0, &[0u8; 64], None)).collect();
|
||||
(0..7).map(|_| encode_registry_entry(&[0u8; 32], 0, &[0u8; 64])).collect();
|
||||
assert!(estimated_packet_size(&entries) > PKARR_PACKET_LIMIT);
|
||||
}
|
||||
|
||||
@@ -558,7 +590,7 @@ mod tests {
|
||||
// Build 7 existing entries (timestamps 1..=7) that would overflow the packet.
|
||||
// Simulate the eviction loop: the 7th (newest) must survive.
|
||||
let mut encoded: Vec<String> =
|
||||
(1u64..=7).map(|ts| encode_registry_entry(&[0u8; 32], ts, &[0u8; 64], None)).collect();
|
||||
(1u64..=7).map(|ts| encode_registry_entry(&[0u8; 32], ts, &[0u8; 64])).collect();
|
||||
// 7 entries overflows.
|
||||
assert!(estimated_packet_size(&encoded) > PKARR_PACKET_LIMIT);
|
||||
|
||||
|
||||
@@ -202,12 +202,12 @@ pub fn build_ensemble_status(
|
||||
if !seen_ids.insert(id_hex.clone()) {
|
||||
continue;
|
||||
}
|
||||
// Registry entries carry an optional name just like gossiped peers, so
|
||||
// they resolve through the same placeholder rule — an unnamed node
|
||||
// reads as "(unnamed)", never as its own 64-char hex ID standing in
|
||||
// for a name.
|
||||
let (display_name, display_name_is_placeholder) =
|
||||
node_display::resolve(m.node_name.as_deref());
|
||||
// A registry entry carries no name — that record is world-readable, so
|
||||
// it holds addressing only (ADR 0044). A member seen there and nowhere
|
||||
// else therefore reads as "(unnamed)" until it announces itself over
|
||||
// gossip, through the same placeholder rule that covers a genuinely
|
||||
// unnamed node: never its own 64-char hex ID standing in for a name.
|
||||
let (display_name, display_name_is_placeholder) = node_display::resolve(None);
|
||||
members.push(EnsembleMemberInfo {
|
||||
documents_held: held_by(&id_hex),
|
||||
node_id_hex: id_hex,
|
||||
|
||||
Reference in new issue
Block a user