From a1e398621eec9472ad67f1eafeba9ff23b012c2f Mon Sep 17 00:00:00 2001 From: slopulus Date: Tue, 17 Nov 2026 19:57:56 +0100 Subject: keys: a party's key may be ecdsa-sha2-nistp256, its signature low-S only A party's keys may be held where no file has them, in a Secure Enclave or a phone, and those are ECDSA keys on NIST P-256. Everywhere a party's key counts (a version's keys, a key set, the key an event is signed with) such a key is taken beside an Ed25519 one, spelled as `ssh-keygen` writes it, without a comment: `ecdsa-sha2-nistp256`, a space, and the base64 of its SSH encoding, its point uncompressed and on the curve. Its signature is SSHSIG as an Ed25519 one is, hashed with `sha512`, its inner signature over SHA-256 as SSH signs with such a key. ECDSA signatures are malleable: of `s` and the curve's order less `s`, both check. So the federation takes one spelling alone: `s` low, at most half the order, `r` and `s` each SSH's shortest mpint, and the blob reading back to itself as an Ed25519 one does. What anyone makes of a party's signature is then none, as before. The vectors are a key `ssh-keygen -t ecdsa -b 256` made, a first version naming it, and a write and a key set `ssh-keygen -Y sign` signed with it, each taken; the signature's high-S twin, which checks as ECDSA, and its `r` spelled longer are none. Ed25519 keys and signatures are spelled and checked as they were. --- src/federation/vectors.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/federation/vectors.rs') diff --git a/src/federation/vectors.rs b/src/federation/vectors.rs index 25c6a41..3d839c8 100644 --- a/src/federation/vectors.rs +++ b/src/federation/vectors.rs @@ -5,9 +5,11 @@ //! change of the federation, which takes its next number. use super::event::{self, Checkpoint, Event}; +use super::fold::Federation; use super::harness::{self, Party, Spec}; use super::jcs::Json; use super::store::Id; +use super::store::memory::{Offered, Store}; use super::version::{self, Version}; /// A write by tv (keys from seeds: tv's of 1s, lass's of 2s), on the ID of @@ -145,6 +147,48 @@ fn events_at_federation_1s_sizes_and_just_past_them() { assert!(Event::read(&tv.write(&[dep()], "home/tv/n", largest)).is_some()); } +/// tv's key on NIST P-256, made by `ssh-keygen -t ecdsa -b 256`; the first version naming +/// it for tv, beside lass's key of 2s, with tv's node and a namespace each; its root; and a +/// write and a key set tv signed with it, on the root, by `ssh-keygen -Y sign -n +/// continuum-federation`, each signature's `s` low. +pub(crate) const ECDSA_KEY: &str = "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBI6uK92X+y9N7jbrgH7grypeMRnxRsEFGnbhV97LJ/7UFKmBtDn0p6V5EBz9WAeeb3BUMCMlkFq3VxEvySs35ss="; +const ECDSA_VERSION: &str = r#"{"changes":null,"federation":1,"keys":{"lass":{"keys":["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIE5dw6ofRdfVqNUZsNMfszLjYqRtO43ol32D1uPybOU"],"since":0},"tv":{"keys":["ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBI6uK92X+y9N7jbrgH7grypeMRnxRsEFGnbhV97LJ/7UFKmBtDn0p6V5EBz9WAeeb3BUMCMlkFq3VxEvySs35ss="],"since":0}},"nodes":{"lass":{"nodes":[],"since":0},"tv":{"nodes":["continuum:e5687b6d11ccfb632abbafe844f8f1693d160aa582156ed66eea38ab5e7d1e12"],"since":0}},"number":0,"rules":[{"path":"home/{party}/**","writer":"{party}"}]}"#; +const ECDSA_ROOT_ID: &str = "6bca61798e124250309330835c674f3c4e7b4547e13fad954674c41b338d7859"; +pub(crate) const ECDSA_WRITE: &str = r#"{"deps":["6bca61798e124250309330835c674f3c4e7b4547e13fad954674c41b338d7859"],"key":"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBI6uK92X+y9N7jbrgH7grypeMRnxRsEFGnbhV97LJ/7UFKmBtDn0p6V5EBz9WAeeb3BUMCMlkFq3VxEvySs35ss=","party":"tv","sig":"U1NIU0lHAAAAAQAAAGgAAAATZWNkc2Etc2hhMi1uaXN0cDI1NgAAAAhuaXN0cDI1NgAAAEEEjq4r3Zf7L03uNuuAfuCvKl4xGfFGwQUaduFX3ssn/tQUqYG0OfSnpXkQHP1YB55vcFQwIyWQWrdXES/JKzfmywAAABRjb250aW51dW0tZmVkZXJhdGlvbgAAAAAAAAAGc2hhNTEyAAAAYwAAABNlY2RzYS1zaGEyLW5pc3RwMjU2AAAASAAAACA9LGG7MLFobYksXCVEMCda7M5iGcxB8vunTxypmyf3+wAAACBWct5p0CI3w3+OpKCS4w7DJKqpP8+oxgCbRFkvlhZ73A==","write":{"path":"home/tv/laptop","value":"10.243.7.3"}}"#; +const ECDSA_WRITE_ID: &str = "f1f4bf7c1226d920c37d20a8228d490ea7249a4df4005a38f7d5993bd6923cb2"; +const ECDSA_KEYS: &str = r#"{"deps":["6bca61798e124250309330835c674f3c4e7b4547e13fad954674c41b338d7859"],"key":"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBI6uK92X+y9N7jbrgH7grypeMRnxRsEFGnbhV97LJ/7UFKmBtDn0p6V5EBz9WAeeb3BUMCMlkFq3VxEvySs35ss=","keys":["ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBI6uK92X+y9N7jbrgH7grypeMRnxRsEFGnbhV97LJ/7UFKmBtDn0p6V5EBz9WAeeb3BUMCMlkFq3VxEvySs35ss=","ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAzB4a38+wy5iWPeKWbYF5hoHAxLVqYMO73eO8on/XYH"],"party":"tv","sig":"U1NIU0lHAAAAAQAAAGgAAAATZWNkc2Etc2hhMi1uaXN0cDI1NgAAAAhuaXN0cDI1NgAAAEEEjq4r3Zf7L03uNuuAfuCvKl4xGfFGwQUaduFX3ssn/tQUqYG0OfSnpXkQHP1YB55vcFQwIyWQWrdXES/JKzfmywAAABRjb250aW51dW0tZmVkZXJhdGlvbgAAAAAAAAAGc2hhNTEyAAAAZAAAABNlY2RzYS1zaGEyLW5pc3RwMjU2AAAASQAAACEA8W+2M0hB62y5PDq3TrERSA/TJBFjI21dg+u3GJzU7cUAAAAgYqFtgJ/74JtWUWGN/kBQBibbCE5EbXR/Phz4VbzBbko="}"#; +const ECDSA_KEYS_ID: &str = "4703ad7b712372f737fcd52c73c071f81d9c48f8cd63404e91cdec249a33347d"; + +#[test] +fn an_ecdsa_key_and_what_it_signs() { + let (write, keys) = (ECDSA_WRITE.as_bytes(), ECDSA_KEYS.as_bytes()); + assert!( + Event::read(write).is_some(), + "a write signed with an ECDSA key" + ); + assert!( + Event::read(keys).is_some(), + "a key set signed with an ECDSA key" + ); + assert_eq!(Id::of(write).to_string(), ECDSA_WRITE_ID); + assert_eq!(Id::of(keys).to_string(), ECDSA_KEYS_ID); + let mut spec = Spec::first(&[&tv(), &Party::new("lass", 2)], &[]); + spec.parties[0].keys = vec![ECDSA_KEY.to_owned()]; + assert_eq!( + String::from_utf8(spec.json().bytes()).expect("UTF-8"), + ECDSA_VERSION + ); + let root = spec.root(); + assert_eq!(Id::of(&root).to_string(), ECDSA_ROOT_ID); + let mut store = Store::::new(root, Vec::new()).expect("a root"); + for event in [write, keys] { + assert_eq!( + store.offer(event.to_vec()), + Offered::Taken(vec![Id::of(event)]) + ); + } +} + /// The changes founding the swarm of `first`'s root, and those founding the fork whose /// root is `FORK_ROOT`, keeping tv's write: each its hash and its bytes. Automerge encodes /// them, so no script apart computes them; a run of this code printed them, and they were -- cgit v1.3.1