summaryrefslogtreecommitdiff
path: root/dns
diff options
context:
space:
mode:
authorBrian Wellington <bwelling@xbill.org>2023-05-06 07:15:32 -0700
committerGitHub <noreply@github.com>2023-05-06 07:15:32 -0700
commitbf8deda6da437ec5fdaaf5261b8674deb8e6d31c (patch)
tree6f8e7f770179aeaa8abb8d2cb700b3f9e982536b /dns
parentb7211a26bdefa7d655a71392bd126f3745f8b862 (diff)
downloaddnspython-bf8deda6da437ec5fdaaf5261b8674deb8e6d31c.tar.gz
Fix NSEC3 base32 processing. (#929)
The NSEC3 next name field is defined as base32 with no padding, but the code was doing base32 decoding with padding. This wouldn't have any effect in the normal case, since the only defined NSEC3 hashing algorithm is SHA1, and that generates a 160 bit hash that doesn't require padding when encoded in base32. This change removes generated padding after encode, rejects padded input on decode, and adds necessary padding for decode.
Diffstat (limited to 'dns')
-rw-r--r--dns/rdtypes/ANY/NSEC3.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/dns/rdtypes/ANY/NSEC3.py b/dns/rdtypes/ANY/NSEC3.py
index 6eae16e..fe4e71c 100644
--- a/dns/rdtypes/ANY/NSEC3.py
+++ b/dns/rdtypes/ANY/NSEC3.py
@@ -67,6 +67,7 @@ class NSEC3(dns.rdata.Rdata):
def to_text(self, origin=None, relativize=True, **kw):
next = base64.b32encode(self.next).translate(b32_normal_to_hex).lower().decode()
+ next = next.rstrip("=")
if self.salt == b"":
salt = "-"
else:
@@ -94,6 +95,10 @@ class NSEC3(dns.rdata.Rdata):
else:
salt = binascii.unhexlify(salt.encode("ascii"))
next = tok.get_string().encode("ascii").upper().translate(b32_hex_to_normal)
+ if next.endswith(b"="):
+ raise binascii.Error("Incorrect padding")
+ if len(next) % 8 != 0:
+ next += b"=" * (8 - len(next) % 8)
next = base64.b32decode(next)
bitmap = Bitmap.from_text(tok)
return cls(rdclass, rdtype, algorithm, flags, iterations, salt, next, bitmap)