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 2/2] Include dkim log output when -d/--debug argument is passed
Date: Mon, 7 Jun 2021 11:02:52 +0100 [thread overview]
Message-ID: <20210607100252.8253-3-paul@pbarker.dev> (raw)
In-Reply-To: <20210607100252.8253-1-paul@pbarker.dev>
We can pass a logger object to dkim.verify() which will be used to
report internal errors and debugging info. This can be helpful when
investigating DKIM verification issues but is probably not wanted during
normal operation so the log level of each message is reset to DEBUG.
Each message is also prefixed with 'DKIM: ' to identify its origin when
debug output is enabled.
Signed-off-by: Paul Barker <paul@pbarker.dev>
---
b4/__init__.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/b4/__init__.py b/b4/__init__.py
index 168b722..9721e22 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -47,6 +47,17 @@ __VERSION__ = '0.8-dev'
logger = logging.getLogger('b4')
+def _dkim_log_filter(record):
+ # Hide all dkim logging output in normal operation by setting the level to
+ # DEBUG. If debugging output has been enabled then prefix dkim logging
+ # output to make its origin clear.
+ record.levelno = logging.DEBUG
+ record.levelname = 'DEBUG'
+ record.msg = 'DKIM: ' + record.msg
+ return True
+dkimlogger = logger.getChild('dkim')
+dkimlogger.addFilter(_dkim_log_filter)
+
HUNK_RE = re.compile(r'^@@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? @@')
FILENAME_RE = re.compile(r'^(---|\+\+\+) (\S+)')
@@ -1028,7 +1039,7 @@ class LoreMessage:
signtime = self.date
self.msg._headers.append((hn, hval)) # noqa
- res = dkim.verify(self.msg.as_bytes())
+ res = dkim.verify(self.msg.as_bytes(), logger=dkimlogger)
attestor = LoreAttestorDKIM(res, identity, signtime, errors)
logger.debug('DKIM verify results: %s=%s', identity, res)
--
2.31.1
next prev parent reply other threads:[~2021-06-07 10:03 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 ` [b4][PATCH 1/2] Handle MIME encoded-word in DKIM-Signature headers Paul Barker
2021-06-07 10:02 ` Paul Barker [this message]
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-3-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).