From 45cdc3c64bedb6eefe4a3645afbde82e62f8112a Mon Sep 17 00:00:00 2001 From: slopulus Date: Tue, 17 Nov 2026 20:01:42 +0100 Subject: federation.md, federation-tests.md: ecdsa-sha2-nistp256 keys, their signature low-S A key is `ssh-ed25519` or `ecdsa-sha2-nistp256`, spelled alike; an ECDSA signature is over SHA-256, its `s` low and `r` and `s` SSH's shortest mpints, so that it is spelled one way. The vectors and the agent test, among the harness's. --- docs/federation.md | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'docs/federation.md') diff --git a/docs/federation.md b/docs/federation.md index 7b453af..f30cdd4 100644 --- a/docs/federation.md +++ b/docs/federation.md @@ -46,7 +46,8 @@ What an adversary can do: * delay or drop messages between any nodes, short of forever between honest ones; * steal another party's key. -What it can't: forge an Ed25519 signature, or find two byte strings with one SHA-256. +What it can't: forge an Ed25519 or ECDSA signature, or find two byte strings with one +SHA-256. Out of scope: keeping anything from being read (every party reads all of it), hiding who talks to whom, and a party's own machine taken over whole (then the adversary is that @@ -125,11 +126,12 @@ Spread out: * **`deps`**: the IDs of its dependencies, as 64 lower-case hex digits, one at least, ascending, none twice; a client gives the heads it read. -* **`party`** and **`key`**: the party that signs it, and the key it signs with: - `ssh-ed25519`, one space, and the key's base64, padded and canonical, with no comment, - its 32 bytes an Ed25519 public key. Keys in a version and a key set are spelled so - too, and node IDs as continuum spells them: `continuum:` and the 64 lower-case hex - digits of the node's Ed25519 public key. +* **`party`** and **`key`**: the party that signs it, and the key it signs with: its + type, one space, and the base64 of its SSH encoding, padded and canonical, with no + comment. Two types: `ssh-ed25519`, its 32 bytes an Ed25519 public key, and + `ecdsa-sha2-nistp256`, its point on NIST P-256 uncompressed. Keys in a version and a + key set are spelled so too, and node IDs as continuum spells them: `continuum:` and + the 64 lower-case hex digits of the node's Ed25519 public key. * **What it does**, one field of: * `write`, `{"path": "", "value": }`: a value at a place (The policy); * `keys`, `["", …]`: the party's key set (Keys); @@ -141,9 +143,14 @@ Spread out: * **`sig`**: an SSH signature (`ssh-keygen -Y sign`, namespace `continuum-federation`) over the event's bytes without `sig`: the SSHSIG blob of version 1, hashed with `sha512`, its key the event's `key`, its reserved field empty, as `ssh-keygen` writes - it, in base64, padded and canonical, unarmored. It is checked as continuum checks a - user's signature, strictly *(checked: `access::sshsig::verify_blob`)*, which takes - `sha256` too, and any reserved field: the federation asks `sha512` and an empty one. + it, in base64, padded and canonical, unarmored. An Ed25519 signature is checked as + continuum checks a user's signature, strictly *(checked: + `access::sshsig::verify_blob`)*, which takes `sha256` too, and any reserved field: the + federation asks `sha512` and an empty one. An ECDSA signature is over the SHA-256 of + what it signs, as SSH signs with such a key. Its `s` and the curve's order less `s` + both check, so the federation takes the low one alone, at most half the order, and `r` + and `s` each as SSH's shortest mpint *(checked: `federation::keys`)*. `ssh-keygen` + makes either; a party's client makes `s` low. Three things no party signs, as their bytes need no signer, each without `party`, `key` and `sig`: a version event (Changing the policy), and a federation's root and a fork's, @@ -193,12 +200,13 @@ current at its heads, Forks). Spread out: * **The federation** it follows, and its **number**, one more than that of the version it changes. * **The parties and their keys** (`keys`): one party at least, each by name, as - continuum's user names, 1 to 64 of `A-Z a-z 0-9 . _ @ -`, with one `ssh-ed25519` key - or more, none twice in the version. With them the party signs its votes and proposals - on this version, its key set and its node list (Keys, Nodes). Its `since` is the - number of the version that named them anew: this one's where it does (a party new in - it, keys the parties replace, or the same keys named anew), else the `since` the - version it changes gives the party, whose keys it then names unchanged. + continuum's user names, 1 to 64 of `A-Z a-z 0-9 . _ @ -`, with one key or more + (`ssh-ed25519` or `ecdsa-sha2-nistp256`, Events), none twice in the version. With them + the party signs its votes and proposals on this version, its key set and its node list + (Keys, Nodes). Its `since` is the number of the version that named them anew: this + one's where it does (a party new in it, keys the parties replace, or the same keys + named anew), else the `since` the version it changes gives the party, whose keys it + then names unchanged. * **The node lists** (`nodes`): every party's, a list of node IDs, none twice, with its `since` as keys have one. The version that lets a party in names its list anew, empty where it gives it no nodes, so that a list it wrote before it was taken out counts no -- cgit v1.3.1 From cb9c78d0b76c401435aea781fc36845983c8f1f3 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 18 Nov 2026 11:13:12 +0000 Subject: federation.md, guides: a change taking what was refused keeps the number A change that only has the federation take what it refused, reading nothing it took otherwise, as ecdsa-sha2-nistp256 keys, keeps the federation's number: it is rolled out to every node first, and used after. A node that doesn't take it refuses what uses it, a version naming such a key among them. --- docs/federation.md | 7 +++++++ docs/guides/federation/upgrades.md | 7 +++++++ 2 files changed, 14 insertions(+) (limited to 'docs/federation.md') diff --git a/docs/federation.md b/docs/federation.md index f30cdd4..9659dbb 100644 --- a/docs/federation.md +++ b/docs/federation.md @@ -794,6 +794,13 @@ moves to it by a version of its policy that names it (`"federation": 2`), which parties pass once their nodes run a continuum that knows it. A node that doesn't know the federation, or a version, its swarm has stops taking events and says so. +A change that only has the federation take what it refused, and reads nothing it took +otherwise, keeps the number: the keys of type `ecdsa-sha2-nistp256` taken beside Ed25519 +ones are such a change. It is rolled out first and used after: every node runs a +continuum that takes it before any party uses it. A node that doesn't refuses what uses +it, a version naming such a key among them, and reads otherwise than the others until +it does. + ## The registry on it The krebs registry today: users, their hosts, the hosts' names, addresses and keys, as diff --git a/docs/guides/federation/upgrades.md b/docs/guides/federation/upgrades.md index 945088d..95dab12 100644 --- a/docs/guides/federation/upgrades.md +++ b/docs/guides/federation/upgrades.md @@ -32,3 +32,10 @@ naming another is taken as a proposal, and a party's client backs none. A change to any of that is a federation of its own, with the next number, and its own design. A swarm moves to it by a version naming it, which the parties pass once their nodes run a continuum that knows it. + +A change that only has the federation take what it refused, and reads nothing it took +otherwise, keeps the number: `ecdsa-sha2-nistp256` keys beside Ed25519 ones. Roll it out +first, then use it: every party's operators upgrade their nodes, and only then does a +party name such a key in a version or a key set, or sign with one. A node not upgraded +refuses what uses it and reads otherwise than the others: a version naming such a key is +none to it, and it stays on the version before. -- cgit v1.3.1 From e95909e1c0bf6e0b87b1dd8bafd44c6110656c0d Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 18 Nov 2026 11:14:05 +0000 Subject: attacks: row 62 with an ECDSA signature spelled otherwise Row 62 names an ECDSA signature's twins, `s` high (the order less `s`) and `r` or `s` with zeros more in front, each none. Its test offers the ECDSA vector's write with each (`keys::respelled`) to a store whose root names that key, and has it take the write as it was signed. --- docs/federation.md | 2 +- src/federation/attacks.rs | 17 +++++++++++++++++ src/federation/keys.rs | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) (limited to 'docs/federation.md') diff --git a/docs/federation.md b/docs/federation.md index 9659dbb..5faa478 100644 --- a/docs/federation.md +++ b/docs/federation.md @@ -699,7 +699,7 @@ crafted events. *Sim*: a simulation. *Bench*: measured, not judged. | 59 | Two checkpoints proposed at once, by nodes voting by themselves | The votes split; nays from the nodes backing one make the other dead, and its backers are free | sim | | 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, its blob naming another key | None: `key` and `sig` read back to themselves, the signature is checked strictly, and the blob's key is `key` | 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 | | 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 | diff --git a/src/federation/attacks.rs b/src/federation/attacks.rs index d153f22..0d90461 100644 --- a/src/federation/attacks.rs +++ b/src/federation/attacks.rs @@ -1102,6 +1102,7 @@ fn federation_attack_61() { #[test] fn federation_attack_62() { + use super::vectors::{ECDSA_KEY, ECDSA_WRITE}; use base64::{Engine, engine::general_purpose::STANDARD as BASE64}; let mut fed = three(); let root = fed.root(); @@ -1150,6 +1151,22 @@ fn federation_attack_62() { ), ); assert_eq!(fed.refused(commented), Refusal::None); + // Signed with an ECDSA key (the vectors'), its signature spelled otherwise: `s` high, + // or `r` longer. The write as it was signed is taken. + let mut first = Spec::first(&[&tv, &lass()], &[]); + first.parties[0].keys = vec![ECDSA_KEY.to_owned()]; + let mut fed = Fed { + store: Store::new(first.root(), Vec::new()).expect("a root"), + first, + }; + let event = super::jcs::read(ECDSA_WRITE.as_bytes()).expect("JCS"); + let sig = event.get("sig").and_then(Json::as_str).expect("a sig"); + let key = super::keys::key(ECDSA_KEY).expect("a key"); + for other in super::keys::respelled(&key, sig) { + let respelled = ECDSA_WRITE.replace(sig, &other).into_bytes(); + assert_eq!(fed.refused(respelled), Refusal::None); + } + fed.take(ECDSA_WRITE.as_bytes().to_vec()); } #[test] diff --git a/src/federation/keys.rs b/src/federation/keys.rs index a795db7..fa13ec4 100644 --- a/src/federation/keys.rs +++ b/src/federation/keys.rs @@ -254,6 +254,23 @@ fn written(key: &Key, signature: &[u8]) -> Vec { blob } +/// Of `sig`, an ECDSA signature by `key` as the federation spells it, two others of the +/// same key and message that check as SSH checks them: `s` high, the order less `s`; and +/// `r` with a zero byte more in front, the same number to SSH. +#[cfg(test)] +pub(crate) fn respelled(key: &Key, sig: &str) -> [String; 2] { + let blob = BASE64.decode(sig).expect("base64"); + let rs = &blob[written(key, &[]).len()..]; + let (r, s) = ecdsa_signature(rs).expect("r and s").split_scalars(); + let high = p256::ecdsa::Signature::from_scalars(r, -s).expect("a signature"); + let mut reader = Reader(rs); + let (r, s) = (reader.string().expect("r"), reader.string().expect("s")); + let mut longer = Vec::new(); + string(&mut longer, &[&[0], r].concat()); + string(&mut longer, s); + [mpints(&high), longer].map(|numbers| BASE64.encode(written(key, &numbers))) +} + #[cfg(test)] mod tests { use super::*; -- cgit v1.3.1