diff options
| author | Brian Wellington <bwelling@xbill.org> | 2023-05-06 07:15:32 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-06 07:15:32 -0700 |
| commit | bf8deda6da437ec5fdaaf5261b8674deb8e6d31c (patch) | |
| tree | 6f8e7f770179aeaa8abb8d2cb700b3f9e982536b /dns | |
| parent | b7211a26bdefa7d655a71392bd126f3745f8b862 (diff) | |
| download | dnspython-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.py | 5 |
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) |
