From 540c56cac6c0753d5d8a9057fc7d3596b172807a Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Fri, 10 Feb 2023 15:33:24 +0000 Subject: [PATCH] radicle: sign blob hash instead of content The signatures for Radicle identities were using the documents content. It is standard to use the hash of the content instead, since signing and verification is faster on a smaller set of data. Use the resulting Git blob's object id, i.e. `git hash-object`, as the signing and verifying payload. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle/src/identity/doc.rs | 6 +++--- radicle/src/storage/git.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/radicle/src/identity/doc.rs b/radicle/src/identity/doc.rs index e52d607c..c2e1a61e 100644 --- a/radicle/src/identity/doc.rs +++ b/radicle/src/identity/doc.rs @@ -208,8 +208,8 @@ impl Doc { } pub fn sign(&self, signer: &G) -> Result<(git::Oid, Signature), DocError> { - let (oid, bytes) = self.encode()?; - let sig = signer.sign(&bytes); + let (oid, _) = self.encode()?; + let sig = signer.sign(oid.as_bytes()); Ok((oid, sig)) } @@ -224,7 +224,7 @@ impl Doc { let sigs = trailers::parse_signatures(msg)?; for (pk, sig) in &sigs { - if let Err(err) = pk.verify(blob.content(), sig) { + if let Err(err) = pk.verify(blob.id().as_bytes(), sig) { return Err(DocError::Signature(*pk, err)); } } diff --git a/radicle/src/storage/git.rs b/radicle/src/storage/git.rs index 862ebacd..9d9a5695 100644 --- a/radicle/src/storage/git.rs +++ b/radicle/src/storage/git.rs @@ -245,7 +245,7 @@ impl Repository { let oid = Doc::init( doc.as_slice(), remote, - &[(signer.public_key(), signer.sign(&doc))], + &[(signer.public_key(), signer.sign(doc_oid.as_bytes()))], repo.raw(), )?;