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/guides/federation') 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/guides/federation') 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 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/guides/federation') 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 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/guides/federation') 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