aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/party.rs
diff options
context:
space:
mode:
authorslopulus <slop@lassul.us>2026-11-17 20:01:42 +0100
committertv <tv@krebsco.de>2026-11-17 21:09:38 +0100
commitbcda4d67483239691b045c5b978047f017f3b9e3 (patch)
treef6a36de02d707969c1c78c03ce589cef171fbad3 /src/federation/party.rs
parenta1e398621eec9472ad67f1eafeba9ff23b012c2f (diff)
continuum-party: signing through an ssh-agent
A key held in hardware is never a file: only an ssh-agent signs with it. Given a public key as `--key` (a `.pub` file, `ssh-ed25519` or `ecdsa-sha2-nistp256`), the client asks the agent at `SSH_AUTH_SOCK` to sign what SSHSIG signs (a sign request with the key's blob, no flags) and writes the blob around the agent's signature as `ssh-keygen -Y sign` does. An ECDSA signature the agent gives with a high `s` is made low, the other of its two spellings, which the federation takes. What it makes is checked before it is used. A private key file signs as it did. A test starts `ssh-agent`, adds an ECDSA and an Ed25519 key to it and deletes their files, signs through it, and has both continuum and `ssh-keygen -Y verify` check each signature, one of an agent's high-S answers among them. Without OpenSSH it asks nothing.
Diffstat (limited to 'src/federation/party.rs')
-rw-r--r--src/federation/party.rs55
1 files changed, 41 insertions, 14 deletions
diff --git a/src/federation/party.rs b/src/federation/party.rs
index 21e1fb7..4ba51ed 100644
--- a/src/federation/party.rs
+++ b/src/federation/party.rs
@@ -1,9 +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 (an OpenSSH private key file, `--key`), 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.
+//! 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.
//!
//! * `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
@@ -42,7 +43,7 @@ use super::client::{self, Record};
use super::event::{self, Does, Event, Signed};
use super::fold::Federation;
use super::jcs::Json;
-use super::keys::Key;
+use super::keys::{self, Key};
use super::store::Id;
use super::store::memory::Store;
use super::version::Version;
@@ -342,25 +343,51 @@ fn strings(matches: &ArgMatches, name: &str) -> Vec<String> {
.collect()
}
-fn signing_key(options: &Options) -> Result<SigningKey> {
+/// The key `--key` names: a private key file's, or a public key's, held by the ssh-agent.
+fn signing_key(options: &Options) -> Result<Signing> {
let file = options
.key
.as_ref()
.context("--key names the party's key")?;
let text = std::fs::read_to_string(file).with_context(|| format!("Reading {file}"))?;
- client::signing_key(&text).map_err(|why| anyhow!("{file}: {why}"))
+ 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))
+}
+
+/// What signs: a key at hand, or a key the ssh-agent at a socket holds.
+enum Signing {
+ File(SigningKey),
+ Agent(Key, PathBuf),
}
/// Who signs: the party, with one of its keys.
struct Signer {
- key: SigningKey,
+ key: Signing,
party: String,
}
impl Signer {
- fn sign(&self, deps: &[Id], does: (&str, Json)) -> Vec<u8> {
- let line = PublicKey(self.key.verifying_key().to_bytes()).line();
- event::signed(&self.key, &self.party, &line, deps, does)
+ fn sign(&self, deps: &[Id], does: (&str, Json)) -> Result<Vec<u8>> {
+ match &self.key {
+ Signing::File(key) => {
+ let line = PublicKey(key.verifying_key().to_bytes()).line();
+ Ok(event::signed(key, &self.party, &line, deps, does))
+ }
+ Signing::Agent(key, socket) => {
+ event::signed_by(&self.party, &key.line(), deps, does, |bytes| {
+ keys::sign_through(socket, key, bytes)
+ })
+ .map_err(|why| anyhow!(why))
+ }
+ }
}
}
@@ -373,7 +400,7 @@ async fn sign(
does: (&str, Json),
) -> Result<()> {
let (_, heads) = node.summary().await?;
- let event = signer.sign(&heads, does);
+ let event = signer.sign(&heads, does)?;
record.signed(&event);
record.save(path).map_err(|why| anyhow!(why))?;
node.put(&event).await
@@ -438,7 +465,7 @@ async fn vote(
.map_err(|why| anyhow!(why))?;
// On the events proposing it: above the heads it names for a checkpoint wherever they
// are, so a version event may be written on it.
- let cast = signer.sign(&proposals, event::vote(current.hash, proposal, yes));
+ let cast = signer.sign(&proposals, event::vote(current.hash, proposal, yes))?;
record.cast(&current, &cast, kept);
record.save(path).map_err(|why| anyhow!(why))?;
node.put(&cast).await