aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-18 11:14:05 +0000
committertv <tv@krebsco.de>2026-11-18 12:21:46 +0100
commite95909e1c0bf6e0b87b1dd8bafd44c6110656c0d (patch)
treecba908ec96491c00a532ef81e17ed933aa362678
parentcb9c78d0b76c401435aea781fc36845983c8f1f3 (diff)
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.
-rw-r--r--docs/federation.md2
-rw-r--r--src/federation/attacks.rs17
-rw-r--r--src/federation/keys.rs17
3 files changed, 35 insertions, 1 deletions
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<u8> {
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::*;