tools.linux.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Barker <paul@pbarker.dev>
To: tools@linux.kernel.org,
	Konstantin Ryabitsev <konstantin.ryabitsev@linux.dev>
Cc: Paul Barker <paul@pbarker.dev>
Subject: [b4][PATCH 1/2] Handle MIME encoded-word in DKIM-Signature headers
Date: Mon,  7 Jun 2021 11:02:51 +0100	[thread overview]
Message-ID: <20210607100252.8253-2-paul@pbarker.dev> (raw)
In-Reply-To: <20210607100252.8253-1-paul@pbarker.dev>

As recently found in patatt [1], mail gateways and archivers may mangle
headers like DKIM-Signature if they are sent as an excessively long
line. An example of this occuring was found when the DKIM-Signature
header generated by Microsoft Office 365 collided with the
header re-encoding performed by lists.sr.ht when generating mbox
archive files. This encoding causes dkim.verify() to fail.

The Python email.header module provides the decode_header() and
make_header() functions which can be used to handle MIME encoded-word
syntax or other header manglings which may occur. Fixing up the header
content using these functions before calling dkim.verify() allows the
verification to succeed.

[1]: https://lore.kernel.org/tools/20210531140539.7630-1-paul@pbarker.dev/

Signed-off-by: Paul Barker <paul@pbarker.dev>
---
 b4/__init__.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/b4/__init__.py b/b4/__init__.py
index a163364..168b722 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -1006,6 +1006,10 @@ class LoreMessage:
 
         seenatts = list()
         for hn, hval in dkhdrs:
+            # Handle MIME encoded-word syntax or other types of header encoding if
+            # present.
+            if '?q?' in hval:
+                hval = str(email.header.make_header(email.header.decode_header(hval)))
             errors = list()
             hdata = LoreMessage.get_parts_from_header(hval)
             logger.debug('Loading DKIM attestation for d=%s, s=%s', hdata['d'], hdata['s'])
-- 
2.31.1


  reply	other threads:[~2021-06-07 10:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07 10:02 [b4][PATCH 0/2] Improvements to DKIM signature verification Paul Barker
2021-06-07 10:02 ` Paul Barker [this message]
2021-06-07 10:02 ` [b4][PATCH 2/2] Include dkim log output when -d/--debug argument is passed Paul Barker
2021-06-07 12:51 ` [b4][PATCH 0/2] Improvements to DKIM signature verification 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=20210607100252.8253-2-paul@pbarker.dev \
    --to=paul@pbarker.dev \
    --cc=konstantin.ryabitsev@linux.dev \
    --cc=tools@linux.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).