diff options
| author | tv <tv@krebsco.de> | 2026-11-19 14:13:39 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-19 15:18:52 +0100 |
| commit | 841897b79838f97a809356471baf2f41e186cdfa (patch) | |
| tree | 6fb5e0ac21b69986c87e8d87e87806ff514b451f /src | |
| parent | 27b76d5748f23a879d9fc82c725a58b514020ef9 (diff) | |
continuum-party: which places a proposal gives another writer
Rules go by first match, and `{party}` matches only the names of the
version's parties: admitting a party named as a segment of a place, or
changing the rules or their order, moves who writes the places below
it, and what their writer wrote there counts no more once the version
passes. Nothing said so: a proposal showed only its fields' changes.
`client::writers` names, of the places holding a value, those whose
writer a version changes, as `place: before -> after` (`nobody` where no
rule gives it one). `continuum-party proposals` prints them under each
proposal's changes (`who writes …`), and a fork's check does for the
fork's version (`writers` in POST /events/fork). The guides and
federation.md say so; row 72 is tested (`federation_attack_72`).
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/events.rs | 4 | ||||
| -rw-r--r-- | src/federation/client.rs | 59 | ||||
| -rw-r--r-- | src/federation/fork.rs | 12 | ||||
| -rw-r--r-- | src/federation/party.rs | 15 |
4 files changed, 87 insertions, 3 deletions
diff --git a/src/api/events.rs b/src/api/events.rs index a3781c1..5182c23 100644 --- a/src/api/events.rs +++ b/src/api/events.rs @@ -400,7 +400,8 @@ async fn make_fork(State(state): State<AppState>, Json(forking): Json<Forking>) /// `POST /events/fork`: what this node finds of the fork whose root is the body's first /// line, as the file its founders start from holds it: whether it builds that root at /// its heads, and why not; what it holds that those heads lack; what the fork's version -/// changes of the one current there, a line each; and the parties whose keys the fork's +/// changes of the one current there, a line each, and the places holding a value whose +/// writer it changes; and the parties whose keys the fork's /// version gives otherwise than they had there, each with its keys there and in the fork. async fn check_fork(State(state): State<AppState>, body: Bytes) -> Response { let (root, _) = fork::read_root_file(&body); @@ -419,6 +420,7 @@ async fn check_fork(State(state): State<AppState>, body: Bytes) -> Response { "why": check.why, "lacking": ids(check.lacking), "changes": check.changes, + "writers": check.writers, "keys": keys, })) .into_response() 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"), } |
