aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/attacks.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/federation/attacks.rs')
-rw-r--r--src/federation/attacks.rs114
1 files changed, 113 insertions, 1 deletions
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();