diff options
| -rw-r--r-- | docs/federation.md | 9 | ||||
| -rw-r--r-- | src/federation/attacks.rs | 27 | ||||
| -rw-r--r-- | src/federation/fold.rs | 27 | ||||
| -rw-r--r-- | src/federation/model.rs | 15 |
4 files changed, 62 insertions, 16 deletions
diff --git a/docs/federation.md b/docs/federation.md index ae010fb..669527d 100644 --- a/docs/federation.md +++ b/docs/federation.md @@ -410,7 +410,9 @@ else does: 4. a version behind the current one; 5. of the writes at a place that 1 and 2 leave, one another of them has in its history, and of those left, all but the one with the lowest ID; and so of a party's key sets, - and of its node lists. + and of its node lists, once those written under an earlier version than another of + them are left out: one written under a version that names the party's keys anew + replaces whatever an old key wrote at a history from before it. So a place's value, a party's set and its list are each the latest its party signed that counts: what the party signed after replaces what it signed before, whatever order the @@ -546,7 +548,9 @@ each as its party's ([`store.md`](store.md), [Members](store.md#members)); anoth list does nothing for a node. A party's list counts until the party writes another or a version names one anew, whatever keys its version names since, so that no change of keys leaves a swarm without members; a list a stolen key wrote stays until the party writes one -under the version that replaced that key, which it can at once, through any member. A node +under the version that replaced that key, which it can at once, through any member, and +which a list the stolen key writes at a history from before that version, whatever its +ID, doesn't replace ([What counts](#what-counts), 5). A node puts whatever events it is given, its party's and others' alike: what counts is who signed an event, not which node put it. So a party without nodes of its own writes through any node that takes its events. @@ -725,6 +729,7 @@ fold, with crafted events. *Sim*: a simulation. *Bench*: measured, not judged. | 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 | — | | 67 | A party keeps a proposal alive that nobody else backs, to hold back automatic checkpoints | Holds back none: a node proposes a checkpoint beside a proposal it wouldn't back that nobody backs but its proposer | sim | | 68 | A checkpoint proposed at heads that leave out what was written since: a key set dropping a stolen key, say | Not backed: clients and nodes back a checkpoint only where what they held for a while is among its heads, in their history, or above them; a node shows what they lack | unit | +| 69 | A key a version names, stolen, writes its party's node list at a history from before the version naming the party's keys anew, beside the list the party writes under that version, several, for the lowest ID | The party's counts: of a party's lists, those written under the latest version come first | unit | ## Roads not taken diff --git a/src/federation/attacks.rs b/src/federation/attacks.rs index 3f44ad0..2043c19 100644 --- a/src/federation/attacks.rs +++ b/src/federation/attacks.rs @@ -1300,6 +1300,33 @@ fn federation_attack_63() { assert_eq!(pinned.state().current().hash, two.hash()); } +/// A key a version names, stolen, writes its party's node list at histories from before +/// the version that names the party's keys anew, beside the list the party writes under +/// that version, several, so that one has a lower ID: the party's counts. +#[test] +fn federation_attack_69() { + let (tv, lass, makefu) = (tv(), lass(), makefu()); + let tv_now = Party::new("tv", 4); + let mut fed = three(); + let root = fed.root(); + let on = fed.first.hash(); + let mut renamed = fed.first.after(on); + renamed.parties[0].keys_since = 1; + renamed.parties[0].keys = vec![tv_now.key_line()]; + let before = fed.take(lass.write(&[root], "home/lass/a", s("1"))); + let (_, written) = fed.pass(&[root], &lass, &renamed, on, &[&lass, &makefu]); + fed.take(tv_now.nodes(&[written], &[harness::node_id(1)])); + for n in 2..6 { + // Taken: tv's old key is named at its history. + fed.take(tv.nodes(&[before], &[harness::node_id(n)])); + } + let state = fed.store.state(); + assert_eq!( + state.nodes_of("tv", state.current()), + vec![harness::node_id(1)] + ); +} + #[test] fn federation_attack_64() { let (mut fed, head, gone, _, written) = moved(); diff --git a/src/federation/fold.rs b/src/federation/fold.rs index 3ebeebf..2e3fc56 100644 --- a/src/federation/fold.rs +++ b/src/federation/fold.rs @@ -186,28 +186,35 @@ impl State { .copied() } - /// The key set, or node list, of `party` that counts by `current`: one written under a - /// version numbered at least the `since` it gives the party's. + /// The key set, or node list, of `party` that counts by `current`: of those written + /// under a version numbered at least the `since` it gives the party's, those written + /// under the latest version, and of those the latest (`latest`). So one a stolen key + /// writes at a history from before the version that named its party's keys anew + /// replaces nothing the party wrote under that version. fn list(&self, party: &str, current: &Version, list: List) -> Option<Id> { let given = current.parties.get(party)?; let since = match list { List::Keys => given.keys_since, List::Nodes => given.nodes_since, }; - let candidates: Vec<Id> = self + let candidates: Vec<(Id, u64)> = self .signed() - .filter(|(_, signed, under)| { - signed.party == party + .filter_map(|(id, signed, under)| { + let number = self.versions.get(under)?.number; + (signed.party == party && matches!( (&signed.does, list), (Does::Keys(_), List::Keys) | (Does::Nodes(_), List::Nodes) ) - && self - .versions - .get(under) - .is_some_and(|version| version.number >= since) + && number >= since) + .then_some((*id, number)) }) - .map(|(id, _, _)| *id) + .collect(); + let latest = candidates.iter().map(|(_, number)| *number).max()?; + let candidates: Vec<Id> = candidates + .into_iter() + .filter(|(_, number)| *number == latest) + .map(|(id, _)| id) .collect(); self.latest(&candidates) } diff --git a/src/federation/model.rs b/src/federation/model.rs index 2107d9f..8cd189b 100644 --- a/src/federation/model.rs +++ b/src/federation/model.rs @@ -205,7 +205,8 @@ impl Model { }) } - /// The key set, or node list, of `party` that counts in a history by `version`. + /// The key set, or node list, of `party` that counts in a history by `version`: of + /// those written under the latest version, the latest. fn list( &self, history: &BTreeSet<Id>, @@ -219,17 +220,23 @@ impl Model { } else { given.nodes_since }; - let ids: Vec<Id> = self + let ids: Vec<(Id, u64)> = self .signed(history) - .filter(|(id, signed)| { + .filter(|(_, signed)| { signed.party == party && match signed.does { Does::Keys(_) => keys, Does::Nodes(_) => !keys, _ => false, } - && self.under(id).is_some_and(|under| under.number >= since) }) + .filter_map(|(id, _)| Some((id, self.under(&id)?.number))) + .filter(|(_, number)| *number >= since) + .collect(); + let latest = ids.iter().map(|(_, number)| *number).max()?; + let ids: Vec<Id> = ids + .into_iter() + .filter(|(_, number)| *number == latest) .map(|(id, _)| id) .collect(); self.latest(&ids) |
