aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/keys.rs
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 /src/federation/keys.rs
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.
Diffstat (limited to 'src/federation/keys.rs')
-rw-r--r--src/federation/keys.rs17
1 files changed, 17 insertions, 0 deletions
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::*;