diff options
Diffstat (limited to 'src/federation')
| -rw-r--r-- | src/federation/client.rs | 59 | ||||
| -rw-r--r-- | src/federation/fork.rs | 12 | ||||
| -rw-r--r-- | src/federation/party.rs | 15 |
3 files changed, 84 insertions, 2 deletions
diff --git a/src/federation/client.rs b/src/federation/client.rs index 45f5019..f0c196f 100644 --- a/src/federation/client.rs +++ b/src/federation/client.rs @@ -481,6 +481,32 @@ pub(crate) fn changes(current: &Json, proposed: &Json) -> Vec<String> { lines } +/// Of `places`, the places holding a value, those whose writer the version `proposed` +/// changes of `current`, a line each, `place: before -> after`, `nobody` where no rule +/// gives it one: admitting a party named as a place's segment is, or changing the rules or +/// their order, moves who writes there, and what its writer wrote there counts no more +/// once `proposed` passes. +pub(crate) fn writers<'a>( + current: &Version, + proposed: &Version, + places: impl IntoIterator<Item = &'a str>, +) -> Vec<String> { + places + .into_iter() + .filter_map(|place| { + let path = super::version::path(place)?; + let (before, after) = (current.writer(&path), proposed.writer(&path)); + (before != after).then(|| { + format!( + "{place}: {} -> {}", + before.unwrap_or("nobody"), + after.unwrap_or("nobody") + ) + }) + }) + .collect() +} + /// Of the parties' nodes, those not known to know `revision`, by what the node a client /// talks to heard each say it knows (`knows` in `counts`, from `GET /events/counts`): a /// line for each party with any, naming them and what each said. Once a version of @@ -945,6 +971,39 @@ mod tests { ); } + /// Row 72 (`docs/federation.md`): a party admitted under the name of a place's segment + /// moves who writes there, rules unchanged, and so does a change of the rules' order; + /// the places it moves are named, the others left out. + #[test] + fn federation_attack_72() { + let (tv, lass, wiki) = ( + Party::new("tv", 1), + Party::new("lass", 2), + Party::new("wiki", 3), + ); + let rules = [ + ("names/{party}/**", harness::str("{party}")), + ("names/**", harness::str("tv")), + ]; + let read = |spec: Spec| Version::read(&spec.json()).unwrap(); + let current = read(Spec::first(&[&tv, &lass], &rules)); + let places = ["names/wiki/a", "names/lass/b", "names/other", "home/tv/c"]; + let admitted = read(Spec::first(&[&tv, &lass, &wiki], &rules)); + assert_eq!( + writers(¤t, &admitted, places), + ["names/wiki/a: tv -> wiki"] + ); + let reordered = read(Spec::first( + &[&tv, &lass], + &[rules[1].clone(), rules[0].clone()], + )); + assert_eq!( + writers(¤t, &reordered, places), + ["names/lass/b: lass -> tv"] + ); + assert!(writers(¤t, ¤t, places).is_empty()); + } + /// Of the nodes `knows` names, those that didn't say they know a revision are named, /// with what each said; a party whose nodes all did, not. #[test] diff --git a/src/federation/fork.rs b/src/federation/fork.rs index c5ce727..0333a52 100644 --- a/src/federation/fork.rs +++ b/src/federation/fork.rs @@ -1,8 +1,9 @@ //! Forks (`docs/federation.md`, Forks): a node holding a federation's history makes the //! root of a fork at heads it holds, by a version (`make`), and checks one it is given //! (`check`): whether it builds that root at its heads, what it holds that those heads -//! lack, what the fork's version changes of the one current there, and, party by party, -//! the keys the fork's version gives where they aren't the keys the party had there. A +//! lack, what the fork's version changes of the one current there, and so who writes the +//! places holding a value, and, party by party, the keys the fork's version gives where +//! they aren't the keys the party had there. A //! node that doesn't hold that history takes a fork's root on its operator's word, who //! names the fork by its root's ID (`--store-id`). //! @@ -64,6 +65,9 @@ pub(crate) struct Check { /// What the fork's version changes of the version current at those heads, a line each /// (`client::changes`): its rules among them, whose order says who writes where. pub(crate) changes: Vec<String>, + /// Of the places holding a value there, those whose writer the fork's version changes, + /// a line each (`client::writers`). + pub(crate) writers: Vec<String>, /// Each party whose keys the fork's version gives otherwise than the party had at /// those heads, with its keys there and in the fork. pub(crate) keys: Vec<(String, Vec<String>, Vec<String>)>, @@ -90,6 +94,7 @@ pub(crate) fn check(store: &Store<Federation>, root: &[u8]) -> Result<Check, Str why, lacking: Vec::new(), changes: Vec::new(), + writers: Vec::new(), keys: Vec::new(), }); } @@ -97,6 +102,7 @@ pub(crate) fn check(store: &Store<Federation>, root: &[u8]) -> Result<Check, Str let at = store.state_at(heads); let current = at.current(); let changes = super::client::changes(¤t.json, &version.json); + let writers = super::client::writers(current, version, at.values().keys().map(String::as_str)); let sorted = |mut keys: Vec<String>| { keys.sort(); keys @@ -129,6 +135,7 @@ pub(crate) fn check(store: &Store<Federation>, root: &[u8]) -> Result<Check, Str why, lacking, changes, + writers, keys, }) } @@ -170,6 +177,7 @@ mod tests { why: None, lacking: Vec::new(), changes: check.changes.clone(), + writers: Vec::new(), keys: Vec::new(), } ); diff --git a/src/federation/party.rs b/src/federation/party.rs index de8d9f9..f64746b 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -363,6 +363,9 @@ pub(crate) async fn main() -> Result<()> { for line in changes { println!(" {line}"); } + for line in check["writers"].as_array().into_iter().flatten() { + println!(" who writes {}", line.as_str().unwrap_or_default()); + } for (party, keys) in check["keys"].as_object().into_iter().flatten() { println!( "{party}'s keys: {} here, {} in the fork", @@ -891,6 +894,13 @@ async fn again(node: &Node, signer: &Signer, record: &mut Record, path: &Path) - async fn proposals(node: &Node) -> Result<()> { let counts = node.counts().await?; let current = current(&counts)?; + // The places holding a value, whose writer a proposal may move. + let places: Vec<&str> = counts["values"] + .as_object() + .into_iter() + .flatten() + .map(|(place, _)| place.as_str()) + .collect(); let parties = |names: &JsonValue| -> String { let names: Vec<&str> = names .as_array() @@ -933,6 +943,11 @@ async fn proposals(node: &Node) -> Result<()> { for line in client::changes(¤t.json, &version) { println!(" {line}"); } + if let Ok(proposed) = Version::read(&version) { + for line in client::writers(¤t, &proposed, places.iter().copied()) { + println!(" who writes {line}"); + } + } } _ => println!(" the event {id} proposes no version of that hash"), } |
