From bcda4d67483239691b045c5b978047f017f3b9e3 Mon Sep 17 00:00:00 2001 From: slopulus Date: Tue, 17 Nov 2026 20:01:42 +0100 Subject: 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. --- src/federation/event.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/federation/event.rs') diff --git a/src/federation/event.rs b/src/federation/event.rs index 15cee45..864bedb 100644 --- a/src/federation/event.rs +++ b/src/federation/event.rs @@ -21,6 +21,21 @@ pub(crate) fn signed( deps: &[Id], does: (&str, Json), ) -> Vec { + signed_by(party, key, deps, does, |bytes| { + Ok(keys::sign(signer, bytes)) + }) + .expect("a key at hand signs") +} + +/// An event `party` signs, its key spelled `key`, on `deps`, doing `does`: its bytes, as +/// JCS, with the signature `sign` makes of them without `sig`, where it makes one. +pub(crate) fn signed_by( + party: &str, + key: &str, + deps: &[Id], + does: (&str, Json), + sign: impl FnOnce(&[u8]) -> Result, +) -> Result, String> { let mut members = vec![ ("deps".to_owned(), ids(deps)), ("party".to_owned(), Json::Str(party.to_owned())), @@ -28,11 +43,8 @@ pub(crate) fn signed( (does.0.to_owned(), does.1), ]; let unsigned = Json::object(members.clone()).expect("names once each"); - members.push(( - "sig".to_owned(), - Json::Str(keys::sign(signer, &unsigned.bytes())), - )); - Json::object(members).expect("names once each").bytes() + members.push(("sig".to_owned(), Json::Str(sign(&unsigned.bytes())?))); + Ok(Json::object(members).expect("names once each").bytes()) } /// What writing `value` at `path` does. -- cgit v1.3.1