More bytestring conversions in __init__. pydns seems to like to deal with unicode, so convert on the way in and back.

This commit is contained in:
William Grant
2011-03-19 21:01:54 +11:00
parent 3cf0a5ce9f
commit 44db746563
+7 -3
View File
@@ -423,13 +423,17 @@ def verify(message, logger=None, dnsfunc=dnstxt):
h.update(body) h.update(body)
bodyhash = h.digest() bodyhash = h.digest()
logger.debug("bh: %s" % base64.b64encode(bodyhash)) 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( logger.error(
"body hash mismatch (got %s, expected %s)" % "body hash mismatch (got %s, expected %s)" %
(base64.b64encode(bodyhash), sig[b'bh'])) (base64.b64encode(bodyhash), sig[b'bh']))
return False 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: if not s:
return False return False
try: try:
@@ -446,7 +450,7 @@ def verify(message, logger=None, dnsfunc=dnstxt):
h = hasher() h = hasher()
hash_headers( hash_headers(
h, canonicalize_headers, headers, include_headers, sigheaders, sig) 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: try:
return RSASSA_PKCS1_v1_5_verify( return RSASSA_PKCS1_v1_5_verify(
h, signature, pk['publicExponent'], pk['modulus']) h, signature, pk['publicExponent'], pk['modulus'])