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-tests.md | 7 +++++-- docs/federation.md | 38 +++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 17 deletions(-) (limited to 'docs') diff --git a/docs/federation-tests.md b/docs/federation-tests.md index d7e4a43..6754060 100644 --- a/docs/federation-tests.md +++ b/docs/federation-tests.md @@ -29,7 +29,9 @@ built to: a stage is done when its tests are. ## The harness * **Keys.** Ed25519 keys made from seeds, signing as `ssh-keygen -Y sign` does; a vector - checks one signature against `ssh-keygen` itself. + checks one signature against `ssh-keygen` itself. An ECDSA key `ssh-keygen` made, and + events it signed with it, are vectors; a test signs through a running `ssh-agent`, and + `ssh-keygen -Y verify` checks what it signed, where OpenSSH is installed. * **Events.** A builder for every kind (writes, key sets, node lists, proposals, votes, version events, checkpoints, roots and forks), each from a party, a key and its dependencies, encoded and signed as the design says; and for what is none: bytes that @@ -115,7 +117,8 @@ Vectors for: an event and its ID; an event whose value holds names JCS sorts by UTF-16 units otherwise than by their bytes (one from U+E000 to U+FFFF beside one beyond U+FFFF); events at federation 1's sizes and just past them; a signature, a version and its hash, a checkpoint and its ID, the genesis change of a federation's root and of a -fork's, and a snapshot after a checkpoint. A vector that changes is a change of the +fork's, a snapshot after a checkpoint, and a version naming an ECDSA key, with a write +and a key set `ssh-keygen` signed with it. A vector that changes is a change of the federation, which takes its next number ([`federation.md`](federation.md), Changing the federation). 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 2b9bb568603ee10d4f1f3106a687a8642c162df7 Mon Sep 17 00:00:00 2001 From: slopulus Date: Tue, 17 Nov 2026 20:01:42 +0100 Subject: guides: keys in an ssh-agent A party's key is `ssh-ed25519` or `ecdsa-sha2-nistp256`; the client signs with a private key file or through an ssh-agent holding the key, given its public key. Code of its own signing with ECDSA makes `s` low, which `ssh-keygen` does only half the time. --- docs/guides/federation/building-on-the-api.md | 8 +++++--- docs/guides/federation/getting-started.md | 6 ++++-- docs/guides/federation/keys.md | 22 +++++++++++++++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/guides/federation/building-on-the-api.md b/docs/guides/federation/building-on-the-api.md index 9f144be..4f37b91 100644 --- a/docs/guides/federation/building-on-the-api.md +++ b/docs/guides/federation/building-on-the-api.md @@ -41,11 +41,13 @@ sorts them: * `deps`: the heads it read (`heads` in `GET /events`), each as 64 lower-case hex digits, ascending, one at least. -* `key`: the key it signs with, `ssh-ed25519`, a space, the base64 of its blob, no - comment; one of the party's keys. +* `key`: the key it signs with, its type (`ssh-ed25519` or `ecdsa-sha2-nistp256`), a + space, the base64 of its blob, no comment; one of the party's keys. * `sig`: an SSH signature (`ssh-keygen -Y sign`, namespace `continuum-federation`, hashed with `sha512`) over the JCS bytes of the object without `sig`: the SSHSIG blob, its - reserved field empty, in base64, unarmored. + reserved field empty, in base64, unarmored. Of an ECDSA key, its `s` low, at most half + the curve's order: `ssh-keygen` makes a high one half the time, which no node takes; + sign again, or put the order less `s` in its place. * The value is any JSON with integers only, from −2⁵³ to 2⁵³; the event up to 256 KiB. Put its bytes as they are: diff --git a/docs/guides/federation/getting-started.md b/docs/guides/federation/getting-started.md index ce2b614..3570ee3 100644 --- a/docs/guides/federation/getting-started.md +++ b/docs/guides/federation/getting-started.md @@ -17,8 +17,10 @@ That builds the node, `continuum`, and the party's client, `continuum-party`, in ## A key for each party -The version names each party's keys, and the party signs with them. The client reads an -OpenSSH Ed25519 key without a passphrase: +The version names each party's keys, and the party signs with them. A key is +`ssh-ed25519` or `ecdsa-sha2-nistp256`. The client reads an OpenSSH private key file +without a passphrase, of an Ed25519 key, or signs through an ssh-agent holding the key +([`keys.md`](keys.md), Keys in an ssh-agent): ```sh ssh-keygen -t ed25519 -N '' -f tv.key diff --git a/docs/guides/federation/keys.md b/docs/guides/federation/keys.md index 48018a3..a84ed5a 100644 --- a/docs/guides/federation/keys.md +++ b/docs/guides/federation/keys.md @@ -25,12 +25,32 @@ continuum-party --node http://tv:secret@localhost:3000 --key laptop.key \ Each key goes as one argument, an `authorized_keys` line; its comment is left out. A set holds up to 16 keys. A node voting by itself keeps a key its version names on that -node (`--store-vote-key`): one stolen there votes for the party. +node (`--store-vote-key`), an Ed25519 key in a file: one stolen there votes for the +party. A set counts where it is written under a version numbered at least the `since` the current version gives the party's keys: once a version names a party's keys anew, no set written before counts, and the party writes its set again. +## Keys in an ssh-agent + +A key no file holds, in a security key, a phone or a Secure Enclave, signs through an +ssh-agent. Give the client its public key, a `.pub` file, as `--key`: it asks the agent +at `SSH_AUTH_SOCK` to sign, and writes the signature as `ssh-keygen -Y sign` does +through that agent. Such a key is `ecdsa-sha2-nistp256` or `ssh-ed25519`. + +```sh +ssh-add -L # ecdsa-sha2-nistp256 AAAA… tv@phone +ssh-add -L | grep tv@phone > phone.pub +cut -d' ' -f1,2 phone.pub # the key as a version or a set names it +continuum-party --node http://tv:secret@localhost:3000 --key phone.pub \ + --record tv.record write home/tv/motd '"from the phone"' +``` + +Of an ECDSA signature, `s` and the curve's order less `s` both check. The federation +takes the low one alone, so that nobody makes another event of what the party signed; +the client makes `s` low, whichever the agent gives. + ## Changing the keys of a set A write counts only while the key that signed it is among the party's keys: what a key -- 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') 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') 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 From b6a2649f54741e88a886fe8f64e916415e8a4b72 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 18 Nov 2026 11:14:21 +0000 Subject: guides: which keys an ssh-agent signs a party's events with A smartcard's or a security key's PIV key, through PKCS#11, or a key in a Secure Enclave or a phone, each ecdsa-sha2-nistp256 or ssh-ed25519; a security key's FIDO key (`-t ecdsa-sk`, `-t ed25519-sk`) is no party's key. --- docs/guides/federation/keys.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/guides/federation/keys.md b/docs/guides/federation/keys.md index a84ed5a..6448f9e 100644 --- a/docs/guides/federation/keys.md +++ b/docs/guides/federation/keys.md @@ -34,10 +34,16 @@ written before counts, and the party writes its set again. ## Keys in an ssh-agent -A key no file holds, in a security key, a phone or a Secure Enclave, signs through an -ssh-agent. Give the client its public key, a `.pub` file, as `--key`: it asks the agent -at `SSH_AUTH_SOCK` to sign, and writes the signature as `ssh-keygen -Y sign` does -through that agent. Such a key is `ecdsa-sha2-nistp256` or `ssh-ed25519`. +A key no file holds signs through an ssh-agent holding it: a smartcard's or a security +key's PIV key, which the agent reaches through PKCS#11 (`ssh-add -s`), or a key in a +Secure Enclave or a phone, held by an agent there. Such a key is `ecdsa-sha2-nistp256` or +`ssh-ed25519`. A security key's FIDO key (`ssh-keygen -t ecdsa-sk` or `-t ed25519-sk`, +its type ending in `@openssh.com`) is neither: it signs otherwise than the federation +takes, and is no party's key. + +Give the client its public key, a `.pub` file, as `--key`: it asks the agent at +`SSH_AUTH_SOCK` to sign, and writes the signature as `ssh-keygen -Y sign` does through +that agent. ```sh ssh-add -L # ecdsa-sha2-nistp256 AAAA… tv@phone -- cgit v1.3.1 From 2ac20de00d0535dcb2a0d327f73c0b61fbbe4749 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 18 Nov 2026 11:15:24 +0000 Subject: keys: signing through an ssh-agent tested wherever tests run The test fails without OpenSSH on the machine testing, rather than passing without asking anything. Its directory is a scratch directory, removed when the test ends, the agent stopped before it. --- docs/federation-tests.md | 2 +- src/federation/keys.rs | 42 +++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 22 deletions(-) (limited to 'docs') diff --git a/docs/federation-tests.md b/docs/federation-tests.md index 6754060..ba182ad 100644 --- a/docs/federation-tests.md +++ b/docs/federation-tests.md @@ -31,7 +31,7 @@ built to: a stage is done when its tests are. * **Keys.** Ed25519 keys made from seeds, signing as `ssh-keygen -Y sign` does; a vector checks one signature against `ssh-keygen` itself. An ECDSA key `ssh-keygen` made, and events it signed with it, are vectors; a test signs through a running `ssh-agent`, and - `ssh-keygen -Y verify` checks what it signed, where OpenSSH is installed. + `ssh-keygen -Y verify` checks what it signed: the machine testing needs OpenSSH. * **Events.** A builder for every kind (writes, key sets, node lists, proposals, votes, version events, checkpoints, roots and forks), each from a party, a key and its dependencies, encoded and signed as the design says; and for what is none: bytes that diff --git a/src/federation/keys.rs b/src/federation/keys.rs index fa13ec4..ed47b9b 100644 --- a/src/federation/keys.rs +++ b/src/federation/keys.rs @@ -421,47 +421,47 @@ mod tests { /// A signature through a running `ssh-agent` checks here and with `ssh-keygen -Y /// verify`, of an ECDSA key the agent alone holds and of an Ed25519 one; of ECDSA, also - /// one the agent gave with a high `s`. Where OpenSSH isn't installed, nothing is asked. + /// one the agent gave with a high `s`. The machine testing needs OpenSSH (`ssh-agent`, + /// `ssh-add`, `ssh-keygen`): without it, the test fails. #[test] fn signs_through_an_ssh_agent() { use std::process::{Command, Stdio}; - let dir = std::env::temp_dir().join(format!("continuum-agent-{}", std::process::id())); - std::fs::create_dir_all(&dir).expect("a directory"); + let dir = crate::files::scratch_dir("agent"); let socket = dir.join("agent"); - let agent = match Command::new("ssh-agent") - .arg("-D") - .arg("-a") - .arg(&socket) - .stdout(Stdio::null()) - .spawn() - { - Ok(agent) => agent, - Err(error) if error.kind() == std::io::ErrorKind::NotFound => { - eprintln!("no ssh-agent: skipped"); - return; - } - Err(error) => panic!("ssh-agent: {error}"), - }; - struct Stop(std::process::Child, std::path::PathBuf); + // The agent, stopped when the test ends: dropped before its directory, declared + // after it. + struct Stop(std::process::Child); impl Drop for Stop { fn drop(&mut self) { let _ = self.0.kill(); let _ = self.0.wait(); - let _ = std::fs::remove_dir_all(&self.1); } } - let _stop = Stop(agent, dir.clone()); + let _agent = Stop( + Command::new("ssh-agent") + .arg("-D") + .arg("-a") + .arg(&socket) + .stdout(Stdio::null()) + .spawn() + .expect("ssh-agent, of OpenSSH, which this test needs"), + ); for _ in 0..100 { if socket.exists() { break; } std::thread::sleep(std::time::Duration::from_millis(50)); } + assert!( + socket.exists(), + "ssh-agent made no socket at {}", + socket.display() + ); let run = |command: &mut Command| { let out = command .env("SSH_AUTH_SOCK", &socket) .output() - .expect("OpenSSH"); + .expect("OpenSSH, which this test needs"); assert!(out.status.success(), "{command:?}: {out:?}"); }; for kind in [["-t", "ecdsa", "-b", "256"].as_slice(), &["-t", "ed25519"]] { -- cgit v1.3.1 From ac66571a87cf36e769bb8308568808e3a0c2ce31 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 18 Nov 2026 11:17:06 +0000 Subject: continuum-party: a key the ssh-agent holds, given itself `--key` gives a public key itself, an `authorized_keys` line, as well as a file of them: of a file of several, the first signs, with a warning naming it, and another is given itself to sign with it. An agent that doesn't hold the key given signs nothing, and the client stops before it records or puts what it would have signed, saying which key it asked for. --- docs/configuration.md | 4 ++ docs/guides/federation/keys.md | 17 +++--- src/config/mod.rs | 4 +- src/federation/keys.rs | 3 +- src/federation/party.rs | 123 +++++++++++++++++++++++++++++++++++------ 5 files changed, 123 insertions(+), 28 deletions(-) (limited to 'docs') diff --git a/docs/configuration.md b/docs/configuration.md index d246082..989f268 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -256,4 +256,8 @@ record = "/home/tv/.config/continuum/tv.record" continuum-party --config tv.toml write home/tv/motd '"hello"' ``` +`key` is an OpenSSH private key file, or a public key an ssh-agent holds: the key itself +(`key = "ecdsa-sha2-nistp256 AAAA…"`), or a file of such lines, whose first signs +([`guides/federation/keys.md`](guides/federation/keys.md), Keys in an ssh-agent). + `node` and `token` are secrets: never logged, however they are given. diff --git a/docs/guides/federation/keys.md b/docs/guides/federation/keys.md index 6448f9e..3dd2834 100644 --- a/docs/guides/federation/keys.md +++ b/docs/guides/federation/keys.md @@ -41,16 +41,19 @@ Secure Enclave or a phone, held by an agent there. Such a key is `ecdsa-sha2-nis its type ending in `@openssh.com`) is neither: it signs otherwise than the federation takes, and is no party's key. -Give the client its public key, a `.pub` file, as `--key`: it asks the agent at -`SSH_AUTH_SOCK` to sign, and writes the signature as `ssh-keygen -Y sign` does through -that agent. +Give the client its public key as `--key`, the key itself (an `authorized_keys` line) or +a file holding it: it asks the agent at `SSH_AUTH_SOCK` to sign, and writes the signature +as `ssh-keygen -Y sign` does through that agent. Of a file holding several keys (all +`ssh-add -L` lists, say), the first signs, and the client warns: give another itself to +sign with it. An agent that doesn't hold the key given signs nothing, and the client stops +before it records or puts what it would have signed. ```sh ssh-add -L # ecdsa-sha2-nistp256 AAAA… tv@phone -ssh-add -L | grep tv@phone > phone.pub -cut -d' ' -f1,2 phone.pub # the key as a version or a set names it -continuum-party --node http://tv:secret@localhost:3000 --key phone.pub \ - --record tv.record write home/tv/motd '"from the phone"' +ssh-add -L | grep tv@phone | cut -d' ' -f1,2 # the key as a version or a set names it +continuum-party --node http://tv:secret@localhost:3000 \ + --key "$(ssh-add -L | grep tv@phone)" --record tv.record \ + write home/tv/motd '"from the phone"' ``` Of an ECDSA signature, `s` and the curve's order less `s` both check. The federation diff --git a/src/config/mod.rs b/src/config/mod.rs index 2ff0a45..f74f431 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -750,9 +750,9 @@ pub(crate) const PARTY_OPTIONS: &[OptionSpec] = &[ option( "key", Kind::Text, - "PATH", + "KEY", None, - "The party's key it signs with: an OpenSSH private key file, unencrypted, of an Ed25519 key; or a public key file (ssh-ed25519 or ecdsa-sha2-nistp256), signed with through the ssh-agent at SSH_AUTH_SOCK", + "The party's key it signs with: an OpenSSH private key file, unencrypted, of an Ed25519 key; or a public key (ssh-ed25519 or ecdsa-sha2-nistp256), signed with through the ssh-agent at SSH_AUTH_SOCK: itself, as an authorized_keys line, or a file of such lines, whose first signs", ), option( "record", diff --git a/src/federation/keys.rs b/src/federation/keys.rs index ed47b9b..22940ad 100644 --- a/src/federation/keys.rs +++ b/src/federation/keys.rs @@ -199,7 +199,8 @@ pub(crate) fn sign(key: &SigningKey, message: &[u8]) -> String { /// signature: what `ssh-keygen -Y sign -n continuum-federation` makes through the agent, /// unarmored, an ECDSA signature's `s` made low. pub(crate) fn sign_through(socket: &Path, key: &Key, message: &[u8]) -> Result { - let answer = super::agent::sign(socket, &key.blob(), &signed(message))?; + let answer = super::agent::sign(socket, &key.blob(), &signed(message)) + .map_err(|why| format!("{}: {why}", key.line()))?; from_agent(key, &answer, message) } diff --git a/src/federation/party.rs b/src/federation/party.rs index 4ba51ed..5d18eb8 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -1,10 +1,10 @@ //! `continuum-party`: a party's client of a federation (`docs/federation.md`). It signs its //! party's events with one of its keys (`--key`: an OpenSSH private key file, or a public -//! key the ssh-agent at `SSH_AUTH_SOCK` holds), puts them through a node's API (`--node`, -//! its user and password in the URL, or `--token`), and keeps its party's record -//! (`--record`, `client::Record`), by which it votes, written before a vote is sent. Its -//! options may be set in configuration files as the node's are (`--config`, -//! `config::PARTY_OPTIONS`): the same format, imports and all. +//! key the ssh-agent at `SSH_AUTH_SOCK` holds, given itself or in a file), puts them +//! through a node's API (`--node`, its user and password in the URL, or `--token`), and +//! keeps its party's record (`--record`, `client::Record`), by which it votes, written +//! before a vote is sent. Its options may be set in configuration files as the node's are +//! (`--config`, `config::PARTY_OPTIONS`): the same format, imports and all. //! //! * `init PARTY`: begins a record of `PARTY`, on the version current now; with `--root //! FILE`, from the file the store's swarm starts from, for a party that never voted in @@ -343,23 +343,70 @@ fn strings(matches: &ArgMatches, name: &str) -> Vec { .collect() } -/// The key `--key` names: a private key file's, or a public key's, held by the ssh-agent. +/// What `--key` gives: a private key, from an OpenSSH private key file; or a public key, +/// given itself (an `authorized_keys` line), or the first of a file of such lines, with +/// how many more the file holds. +enum Given { + Private(SigningKey), + Public(Key, usize), +} + +/// What `given`, `--key`'s value, gives (`Given`). +fn given_key(given: &str) -> Result { + let itself = match Key::parse(given) { + Ok(key) => return Ok(Given::Public(key, 0)), + Err(why) => why, + }; + let text = match std::fs::read_to_string(given) { + Ok(text) => text, + Err(error) if error.kind() == std::io::ErrorKind::NotFound => { + bail!("{given}: no file, nor a key ({itself})") + } + Err(error) => return Err(error).with_context(|| format!("Reading {given}")), + }; + if text.trim_start().starts_with("-----BEGIN") { + let key = client::signing_key(&text).map_err(|why| anyhow!("{given}: {why}"))?; + return Ok(Given::Private(key)); + } + let mut lines = text + .lines() + .map(str::trim) + .filter(|line| !line.is_empty() && !line.starts_with('#')); + let first = lines + .next() + .with_context(|| format!("{given} holds no key"))?; + let key = Key::parse(first).map_err(|why| anyhow!("{given}: {why}"))?; + Ok(Given::Public(key, lines.count())) +} + +/// The key `--key` gives (`given_key`): a private key, signing here; or a public key, +/// signing through the ssh-agent at `SSH_AUTH_SOCK`, which must hold it. Of a file of +/// several public keys, the first, with a warning: another is given as `--key` itself. fn signing_key(options: &Options) -> Result { - let file = options + let given = options .key .as_ref() .context("--key names the party's key")?; - let text = std::fs::read_to_string(file).with_context(|| format!("Reading {file}"))?; - if let Ok(key) = Key::parse(&text) { - let socket = std::env::var_os("SSH_AUTH_SOCK").with_context(|| { - format!( - "{file} is a public key, signed with through an ssh-agent: SSH_AUTH_SOCK names none" - ) - })?; - return Ok(Signing::Agent(key, PathBuf::from(socket))); - } - let key = client::signing_key(&text).map_err(|why| anyhow!("{file}: {why}"))?; - Ok(Signing::File(key)) + let key = match given_key(given)? { + Given::Private(key) => return Ok(Signing::File(key)), + Given::Public(key, 0) => key, + Given::Public(key, more) => { + eprintln!( + "Warning: {given} holds {} keys: signing with the first, {}; to sign with \ + another, give that key itself as --key", + more + 1, + key.line() + ); + key + } + }; + let socket = std::env::var_os("SSH_AUTH_SOCK").with_context(|| { + format!( + "{} signs through an ssh-agent: SSH_AUTH_SOCK names none", + key.line() + ) + })?; + Ok(Signing::Agent(key, PathBuf::from(socket))) } /// What signs: a key at hand, or a key the ssh-agent at a socket holds. @@ -699,6 +746,46 @@ mod tests { super::command().debug_assert(); } + /// `--key` gives a public key itself, or the first of a file's with how many more it + /// holds, or a private key file's key; a file of neither, or none, gives nothing. + #[test] + fn the_key_given() { + use super::{Given, given_key}; + use crate::federation::vectors::ECDSA_KEY; + let ed25519 = crate::federation::harness::key_line(1); + let dir = crate::files::scratch_dir("party-key"); + let file = |name: &str, text: &str| { + let path = dir.join(name); + std::fs::write(&path, text).unwrap(); + path.to_str().unwrap().to_owned() + }; + let public = |given: &str| match given_key(given).unwrap() { + Given::Public(key, more) => (key.line(), more), + Given::Private(_) => panic!("{given}: a private key"), + }; + assert_eq!(public(ECDSA_KEY), (ECDSA_KEY.to_owned(), 0)); + assert_eq!( + public(&format!("{ed25519} tv@laptop")), + (ed25519.clone(), 0) + ); + let one = file("phone.pub", &format!("{ECDSA_KEY} tv@phone\n")); + assert_eq!(public(&one), (ECDSA_KEY.to_owned(), 0)); + let two = file( + "agent.pub", + &format!("{ed25519} tv@laptop\n\n{ECDSA_KEY} tv@phone\n"), + ); + assert_eq!(public(&two), (ed25519, 1)); + assert!(given_key(&file("rsa.pub", "ssh-rsa AAAAB3NzaC1yc2E tv\n")).is_err()); + assert!(given_key(&file("empty.pub", "\n")).is_err()); + assert!(given_key(dir.join("missing").to_str().unwrap()).is_err()); + let private = file( + "tv.key", + "-----BEGIN OPENSSH PRIVATE KEY-----\n-----END OPENSSH PRIVATE KEY-----\n", + ); + let why = given_key(&private).err().expect("no key").to_string(); + assert!(why.contains("OpenSSH private key"), "{why}"); + } + /// Its options come from configuration files as the node's do, arguments winning. #[test] fn its_options_come_from_configuration_files_and_arguments() { -- cgit v1.3.1