diff options
| -rw-r--r-- | docs/federation.md | 17 | ||||
| -rw-r--r-- | docs/guides/federation/promises.md | 7 | ||||
| -rw-r--r-- | docs/guides/federation/running-a-node.md | 6 | ||||
| -rw-r--r-- | src/federation/attacks.rs | 114 |
4 files changed, 130 insertions, 14 deletions
diff --git a/docs/federation.md b/docs/federation.md index cef373b..a179846 100644 --- a/docs/federation.md +++ b/docs/federation.md @@ -86,8 +86,9 @@ Not promised: * that what isn't above a checkpoint's heads is taken once nodes moved to it: its party signs it again ([Checkpoints](#checkpoints)); * that a node joining from the root, in a federation that never passed a checkpoint, - isn't shown a chain old keys grew: of two versions changing one it takes neither, but - where its seeds are all the adversary's it is shown one ([Checkpoints](#checkpoints)); + doesn't take a chain old keys grew: of two versions changing one it takes the first it + judges, as any node, and reports the other, for its operator to choose; where its seeds + are all the adversary's it is shown that one alone ([Checkpoints](#checkpoints)); * that a checkpoint, or a fork's root, that a node takes on its operator's word is the one the others built ([`store.md`](store.md), [Pinned checkpoints](store.md#pinned-checkpoints)). @@ -310,12 +311,10 @@ refuses, with everything built on it, reports, and leaves to its operator ([`store.md`](store.md), [A node's own](store.md#a-nodes-own)); another node's refusal doesn't make it drop what it took. One valid at its history breaks no rule: the node reports it apart from events against the rules, and holds nothing against the node that -put it. Of two that change the one it reads, it takes the first it judges; a node still -joining takes neither, and reports, until its operator names one. A node is still joining, -for this, from its start or a rejoin until it has synced with every seed its operator -named: continuum's lifecycle has it `Joining` only until its first sync, with one peer, -which could be the adversary's alone. Without keys voting twice, every version written -changes the one every node reads, or is one it took, and none is refused. +put it. Of two that change the one it reads, it takes the first it judges, joining or +not, and reports the other: its operator chooses (below). Without keys voting twice, every +version written changes the one every node reads, or is one it took, and none is +refused. **An operator may have its node drop what it took** after its checkpoint: a version the others refused, or any event, with everything built on it ([`store.md`](store.md), @@ -720,7 +719,7 @@ fold, with crafted events. *Sim*: a simulation. *Bench*: measured, not judged. | 60 | Two nodes of one party, each voting by itself | They can vote twice, answered as any party voting twice: a party has one node vote by itself | — | | 61 | A key a version names, kept on a node that votes by itself, stolen with it | As 23: it counts while that version is current | unit | | 62 | A party's event spelled anew by another: its `sig` or `key` encoded otherwise, its signature's S not canonical (of ECDSA, the order less `s`, or `r` or `s` with zeros more in front), its blob naming another key | None: `key` and `sig` read back to themselves, the signature is checked strictly (of ECDSA, `s` low and `r` and `s` each its shortest), and the blob's key is `key` | unit | -| 63 | A node joining from the root is shown a chain old keys grew, beside the one the others took | It takes neither, and reports; once a checkpoint passed, it joins from a pinned one, where that chain is refused | unit | +| 63 | A node joining from the root is shown a chain old keys grew, beside the one the others took | It takes the first of the two versions it judges, as any node, and reports the other; its operator chooses. Once a checkpoint passed, it joins from a pinned one, where that chain is never taken | unit | | 64 | Checkpoint heads before the current checkpoint, or at which it isn't current, or one in another's history | No version: a version event naming it is refused | unit | | 65 | After a checkpoint, a party that backed a second proposal once its first was dead, the nays that freed it withheld by those who cast them | Not named: its client keeps those nays with its `true` | unit | | 66 | Two clients of one party back two proposals at once, or its operator votes by hand beside the node that votes for it | Voting twice: a party votes from one client, the node that votes for it where it has one, through which it votes by hand | — | diff --git a/docs/guides/federation/promises.md b/docs/guides/federation/promises.md index 9a1b92f..9059764 100644 --- a/docs/guides/federation/promises.md +++ b/docs/guides/federation/promises.md @@ -47,9 +47,10 @@ to whom. A party whose machine is taken over whole is the adversary from then on * **Writes from before a move**: what isn't above a checkpoint's heads is refused once nodes moved there; its party signs it again ([`checkpoints.md`](checkpoints.md)). * **A joining node's view**: a node joining from the root of a federation that never - passed a checkpoint, whose seeds are all the adversary's, may be shown a chain that - old keys grew; a checkpoint or a fork's root a node takes on its operator's word is - only as good as that word. + passed a checkpoint may take a chain that old keys grew: shown both, it takes the first + of the two versions it judges and reports the other, for you to choose; shown that one + alone, by seeds that are all the adversary's, it takes it. A checkpoint or a fork's + root a node takes on its operator's word is only as good as that word. ## What it asks of you diff --git a/docs/guides/federation/running-a-node.md b/docs/guides/federation/running-a-node.md index 5d881d6..6444bbd 100644 --- a/docs/guides/federation/running-a-node.md +++ b/docs/guides/federation/running-a-node.md @@ -83,7 +83,11 @@ alone, so that a party listing many nodes can't be all of a node's neighbours. A node with an empty document joins by the store's ID (`--store-id`) through a member (`--seeds`), and holds its store once it has read the document: `GET /events` answers -then. +then. It learns of other members as it syncs, and needs none of its seeds once it has: +they may go away. Before a checkpoint passed, it reads from the root: of two versions +changing one, which keys voting twice wrote, it takes the first it judges, as any node, +and reports the other (`own` in `GET /events/refused`), for you to choose +([`when-things-go-wrong.md`](when-things-go-wrong.md)). Once the store moved to a checkpoint, a node joining starts from that checkpoint, which its operator pins by its ID (`--store-checkpoint`): ask a node you trust for it diff --git a/src/federation/attacks.rs b/src/federation/attacks.rs index db047c9..8782528 100644 --- a/src/federation/attacks.rs +++ b/src/federation/attacks.rs @@ -14,7 +14,7 @@ use super::store::{Fold, Id}; use super::version::Version; /// Rows whose tests wait: what a node or a party's client doesn't do yet, and flooding. -const LATER: &[u32] = &[30, 63, 68]; +const LATER: &[u32] = &[30, 68]; fn tv() -> Party { Party::new("tv", 1) @@ -1184,6 +1184,118 @@ fn federation_attack_62() { fed.take(ECDSA_WRITE.as_bytes().to_vec()); } +/// A node joining from the root, in a federation that never passed a checkpoint, is shown +/// a version 1 that old keys grew, at a history before the one the others took: it takes +/// the first of the two it judges, whichever comes first, and refuses the other of its +/// own; its operator chooses, dropping the one it took and allowing the other. Once a +/// checkpoint passed, a node joining from it, pinned, never takes that chain. +#[test] +fn federation_attack_63() { + let (tv, lass) = (tv(), lass()); + let (tv_now, lass_now) = (Party::new("tv", 4), Party::new("lass", 5)); + let first = three().first; + let root = Id::of(&first.root()); + let on = first.hash(); + // The others' version 1 names tv's and lass's keys anew. + let mut one = first.after(on); + for (party, now) in one.parties.iter_mut().zip([&tv_now, &lass_now]) { + party.keys_since = 1; + party.keys = vec![now.key_line()]; + } + let proposal = tv.propose(&[root], &one.json()); + let ours = [&tv, &lass].map(|party| party.vote(&[Id::of(&proposal)], on, one.hash(), true)); + let written = harness::version_event(&[Id::of(&ours[0]), Id::of(&ours[1])], one.hash()); + let after = tv_now.write(&[Id::of(&written)], "home/tv/a", s("1")); + let others: Vec<Vec<u8>> = [proposal] + .into_iter() + .chain(ours) + .chain([written.clone(), after.clone()]) + .collect(); + // The old keys grow another, beside it. + let mut grown = first.after(on); + grown.rules.push(("names/x".to_owned(), s("tv"))); + let growing = lass.propose(&[root], &grown.json()); + let old = [&tv, &lass].map(|party| party.vote(&[Id::of(&growing)], on, grown.hash(), true)); + let grown_written = harness::version_event(&[Id::of(&old[0]), Id::of(&old[1])], grown.hash()); + let chain: Vec<Vec<u8>> = [growing] + .into_iter() + .chain(old) + .chain([ + grown_written.clone(), + tv.write(&[Id::of(&grown_written)], "names/x", s("mine")), + ]) + .collect(); + let sides = [ + ( + &chain, + &grown_written, + grown.hash(), + &others, + &written, + one.hash(), + ), + ( + &others, + &written, + one.hash(), + &chain, + &grown_written, + grown.hash(), + ), + ]; + for (seen_first, took, took_hash, seen_then, refused, refused_hash) in sides { + let mut store = Store::<Federation>::new(first.root(), Vec::new()).expect("a root"); + for event in seen_first.iter().chain(seen_then) { + store.offer(event.clone()); + } + assert_eq!(store.state().current().hash, took_hash); + assert_eq!(store.own(), (vec![Id::of(refused)], Vec::new())); + // Its operator chooses the other side. + store.drop_taken(&[Id::of(took)]).expect("taken"); + store.allow(&[Id::of(refused)]); + for event in seen_first.iter().chain(seen_then) { + store.offer(event.clone()); + } + assert_eq!(store.state().current().hash, refused_hash); + assert!(seen_then.iter().all(|event| store.holds(&Id::of(event)))); + assert_eq!(store.refusal(&Id::of(took)), Some(&Refusal::Dropped)); + } + + // The others pass a checkpoint after their version 1: a node pinning it never takes + // the chain old keys grew. + let mut theirs = Fed { + store: Store::new(first.root(), Vec::new()).expect("a root"), + first: first.clone(), + }; + for event in &others { + theirs.take(event.clone()); + } + let mut two = one.after(one.hash()); + two.checkpoint = Some(vec![Id::of(&after)]); + theirs.pass( + &[Id::of(&after)], + &tv_now, + &two, + one.hash(), + &[&tv_now, &lass_now], + ); + assert_ne!(Id::of(theirs.store.checkpoint()), root); + let mut pinned = Store::<Federation>::pinned( + root, + theirs.store.checkpoint().to_vec(), + theirs.store.kept(), + ) + .expect("a checkpoint"); + for id in theirs.store.taken() { + pinned.offer(theirs.store.get(id).expect("taken").to_vec()); + } + for event in &chain { + pinned.offer(event.clone()); + } + assert!(!chain.iter().any(|event| pinned.holds(&Id::of(event)))); + assert_eq!(pinned.state().current().hash, two.hash()); +} + #[test] fn federation_attack_64() { let (mut fed, head, gone, _, written) = moved(); |
