Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2E6870 for ; Mon, 7 Jun 2021 10:02:58 +0000 (UTC) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 48B9319E8; Mon, 7 Jun 2021 06:02:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 07 Jun 2021 06:02:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pbarker.dev; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=YKspZ3Tg4vcZs DkcWsaTc5uoJNsSn0iitYiaGTmKqMk=; b=A24IXPSNVXbPW6JtKRLdomBa+1EWH RZhUijAaJ+Hb2Bx36vpBo39JOapdNgnJtw3JqQRU85efh2OizS/DN0xjIQxy+Dn7 ipr/UlBz+sl25jwwV4M/tciOY9UBmzxDKUUYBkNu8y+sZGRk1OMHXK45p8HuAyWB XJ14U1jx6h8VDgZfi5FxM2T7k4vLbp7rbaAsfluLNH7GWRS6LYRu5s5xNRCe8FaN HdMGWXtUSNHD5OpmopE6n23orDdRDWL6kKpPxGPM2+wcR3DvsbHy7r5HIWJOIgDY 3hr1WqkFrqBeGufmmqB46oR+njmhGvXHZ5zM/CBVM1DejBYa7Ys05B2IA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=YKspZ3Tg4vcZsDkcWsaTc5uoJNsSn0iitYiaGTmKqMk=; b=EoXB6ZSu 3jJ5Szh7UdhlbTm5nIX8+CoO5uLP7LRQEAQXp1CIfWtM9Dp4zp5PiKkunH+mSWfs JJ+WeSI73Z1a6zpN+cq/JZcitFxS/KagvQGq6PlUZ+uwhO/nooRfEwz1AGDM4qE7 fRwDMJry+E4Kd7gEgFadpG9yYlwFRrVODD1Eq4sVW7IAvIe1A/ypa4M1PZvALSyH EJ576FrsNuS5yucjLvKFNnAhOa0G4Fa81m1vnRGaAiIsy2CDKbZB6fUCqHfGwfVu 0ELm+dhoG4aeySH0dUaRauDrrSjKiZjeRFhCMjNHm/+Os812ej7Cn91K6AVfirjs bQTFUUVFGywZEQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfedtjedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefrrghulhcu uegrrhhkvghruceophgruhhlsehpsggrrhhkvghrrdguvghvqeenucggtffrrghtthgvrh hnpeeuvdduuddtjeehgeegudelkefggeethefhudduveehkeejleefjeekgeevteegvden ucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepphgruhhlsehpsggrrhhkvghrrdguvghv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 7 Jun 2021 06:02:56 -0400 (EDT) From: Paul Barker To: tools@linux.kernel.org, Konstantin Ryabitsev Cc: Paul Barker Subject: [b4][PATCH 1/2] Handle MIME encoded-word in DKIM-Signature headers Date: Mon, 7 Jun 2021 11:02:51 +0100 Message-Id: <20210607100252.8253-2-paul@pbarker.dev> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210607100252.8253-1-paul@pbarker.dev> References: <20210607100252.8253-1-paul@pbarker.dev> X-Mailing-List: tools@linux.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1557; h=from:subject; bh=C3NLYjgTik0TUCAAQ6hKT/y0J+HZzPXvo7pt8PtK5CY=; b=owGbwMvMwCG2OjnkzdxdX/IYT6slMSTsfXdyxezum2Zs31K+JlyP//rAb1r8z44z09uDFN2O/Ilm f9Dc2VHKwiDGwSArpsiyuefr/ae9jrwZIbcUYOawMoEMYeDiFICJJBUzMkwt/r1mtnia3PtPfgypt3 7OqlViLs/Lf77JxvOM0nVtHilGhoO74uLXskT1npv40O6za9Mu7d4Qj61mp1S8Fhx/u/LCFR4A X-Developer-Key: i=paul@pbarker.dev; a=openpgp; fpr=98B2AAC100AC3F82BB5D546774975C81B7E66BAC Content-Transfer-Encoding: 8bit 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 --- 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