From 1ffa2cb090c54f8002a697f6ef585ef6f211b566 Mon Sep 17 00:00:00 2001 From: Scott Kitterman Date: Sun, 23 Jun 2024 17:26:31 -0400 Subject: [PATCH] Correct signature in ARC-Seal on LF as linesep (LP: #2052720) - Thanks to Nikolay Vizovitin for the report and the fix --- ChangeLog | 2 ++ dkim/__init__.py | 10 ++++------ dkim/canonicalization.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index afbf4a1..5692c15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ UNRELEASED Version 1.1.7 report and the fix - Correct line separtor after AAR header field (LP: #2049018) - Thanks to Nikolay Vizovitin for the report and the fix + - Correct signature in ARC-Seal on LF as linesep (LP: #2052720) - Thanks to + Nikolay Vizovitin for the report and the fix 2024-04-14 Version 1.1.6 - Use raw byte string for regex; fixes SyntaxWarning in Python 3.12 due to diff --git a/dkim/__init__.py b/dkim/__init__.py index 758efdd..9a9c8c3 100644 --- a/dkim/__init__.py +++ b/dkim/__init__.py @@ -1119,14 +1119,12 @@ class ARC(DomainSigner): # Compute ARC-Authentication-Results aar_value = ("i=%d; " % instance).encode('utf-8') + auth_results.rstrip() + self.linesep - + canon_policy = CanonicalizationPolicy.from_c_value(b'relaxed/relaxed') new_arc_set.append(b"ARC-Authentication-Results: " + aar_value) - self.headers.insert(0, (b"arc-authentication-results", aar_value)) arc_headers.insert(0, (b"ARC-Authentication-Results", aar_value)) + self.headers = canon_policy.canonicalize_headers(arc_headers[:1]) + self.headers # Compute bh= - canon_policy = CanonicalizationPolicy.from_c_value(b'relaxed/relaxed') - self.hasher = HASH_ALGORITHMS[self.signature_algorithm] h = HashThrough(self.hasher(), self.debug_content) h.update(canon_policy.canonicalize_body(self.body)) @@ -1154,8 +1152,8 @@ class ARC(DomainSigner): b"ARC-Message-Signature", pk, standardize) new_arc_set.append(b"ARC-Message-Signature: " + res) - self.headers.insert(0, (b"ARC-Message-Signature", res)) arc_headers.insert(0, (b"ARC-Message-Signature", res)) + self.headers = canon_policy.canonicalize_headers(arc_headers[:1]) + self.headers # Compute ARC-Seal as_fields = [x for x in [ @@ -1183,8 +1181,8 @@ class ARC(DomainSigner): b"ARC-Seal", pk, standardize) new_arc_set.append(b"ARC-Seal: " + res) - self.headers.insert(0, (b"ARC-Seal", res)) arc_headers.insert(0, (b"ARC-Seal", res)) + self.headers = canon_policy.canonicalize_headers(arc_headers[:1]) + self.headers new_arc_set.reverse() diff --git a/dkim/canonicalization.py b/dkim/canonicalization.py index 1860848..c0e3ebe 100644 --- a/dkim/canonicalization.py +++ b/dkim/canonicalization.py @@ -58,7 +58,7 @@ def strip_trailing_lines(content): return content[:end] def unfold_header_value(content): - return re.sub(b"\r\n", b"", content) + return re.sub(b"\r?\n", b"", content) def correct_empty_body(content):