From 44db74656315cd8928e4e6a32e44c19bddb4276f Mon Sep 17 00:00:00 2001 From: William Grant Date: Sat, 19 Mar 2011 21:01:54 +1100 Subject: [PATCH] More bytestring conversions in __init__. pydns seems to like to deal with unicode, so convert on the way in and back. --- dkim/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dkim/__init__.py b/dkim/__init__.py index 71ffb9a..3a6d2aa 100644 --- a/dkim/__init__.py +++ b/dkim/__init__.py @@ -423,13 +423,17 @@ def verify(message, logger=None, dnsfunc=dnstxt): h.update(body) bodyhash = h.digest() logger.debug("bh: %s" % base64.b64encode(bodyhash)) - if bodyhash != base64.b64decode(re.sub(br"\s+", "", sig[b'bh'])): + if bodyhash != base64.b64decode(re.sub(br"\s+", b"", sig[b'bh'])): logger.error( "body hash mismatch (got %s, expected %s)" % (base64.b64encode(bodyhash), sig[b'bh'])) return False - s = dnsfunc(sig[b's']+b"._domainkey."+sig[b'd']+b".") + # dnstxt wants Unicode + selector = sig[b's'].decode('latin-1') + domain = sig[b'd'].decode('latin-1') + name = "%s._domainkey.%s." % (selector, domain) + s = dnsfunc(name).encode('utf-8') if not s: return False try: @@ -446,7 +450,7 @@ def verify(message, logger=None, dnsfunc=dnstxt): h = hasher() hash_headers( h, canonicalize_headers, headers, include_headers, sigheaders, sig) - signature = base64.b64decode(re.sub(br"\s+", "", sig[b'b'])) + signature = base64.b64decode(re.sub(br"\s+", b"", sig[b'b'])) try: return RSASSA_PKCS1_v1_5_verify( h, signature, pk['publicExponent'], pk['modulus'])