signatures.lore.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Konstantin Ryabitsev <konstantin.ryabitsev@linux.dev>
To: signatures@kernel.org
Subject: [PATCH 2/3] Perform bh validation first
Date: Tue, 25 May 2021 18:34:45 -0400	[thread overview]
Message-ID: <a3e4f4a07aa4522dbd80124cdf1a511c6774d9a0.1621982010.git.konstantin.ryabitsev@linux.dev> (raw)
In-Reply-To: <de52b2dfa742e87b7357d524cd1f80cbc8f4042c.1621982010.git.konstantin.ryabitsev@linux.dev>

From: Konstantin Ryabitsev <konstantin@linuxfoundation.org>

Instead of doing bh validation as the last step, do it at the very
start. This way we can recognize body content modifications early on
before needing to do any signature validation at all.

Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
---
 patatt/__init__.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/patatt/__init__.py b/patatt/__init__.py
index 8365a4d..042a747 100644
--- a/patatt/__init__.py
+++ b/patatt/__init__.py
@@ -188,6 +188,10 @@ class DevsigHeader:
 
     def validate(self, keyinfo: Union[str, bytes, None]) -> str:
         self.sanity_check()
+        # Start by validating the body hash. If it fails to match, we can
+        # bail early, before needing to do any signature validation.
+        if self.get_field('bh') != self._body_hash:
+            raise BodyValidationError('Body content validation failed')
         # Check that we have a b= field
         if not self.get_field('b'):
             raise RuntimeError('Missing "b=" value')
@@ -214,9 +218,6 @@ class DevsigHeader:
         vdigest = hashed.digest()
         if sdigest != vdigest:
             raise ValidationError('Header validation failed')
-        # Now validate body hash
-        if self.get_field('bh') != self._body_hash:
-            raise BodyValidationError('Body content validation failed')
 
         return signtime
 
-- 
2.31.1


  reply	other threads:[~2021-05-25 22:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-25 22:34 [PATCH 1/3] Release 0.4.1 as a minor bugfix Konstantin Ryabitsev
2021-05-25 22:34 ` Konstantin Ryabitsev [this message]
2021-05-25 22:34 ` [PATCH 3/3] Bump version to 0.4.2 Konstantin Ryabitsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a3e4f4a07aa4522dbd80124cdf1a511c6774d9a0.1621982010.git.konstantin.ryabitsev@linux.dev \
    --to=konstantin.ryabitsev@linux.dev \
    --cc=signatures@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).