From 3494e7f8c9edff27d9624a07c142c9839586ea06 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Mon, 1 Jun 2020 13:49:59 -0700 Subject: [PATCH] NSEC should NOT be downcased when canonicalized, nor should HIP or IPSECKEY; test all --- dns/rdtypes/ANY/NSEC.py | 2 +- tests/test_rdata.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/dns/rdtypes/ANY/NSEC.py b/dns/rdtypes/ANY/NSEC.py index 24936cbe..5db382bf 100644 --- a/dns/rdtypes/ANY/NSEC.py +++ b/dns/rdtypes/ANY/NSEC.py @@ -88,7 +88,7 @@ class NSEC(dns.rdata.Rdata): return cls(rdclass, rdtype, next, windows) def _to_wire(self, file, compress=None, origin=None, canonicalize=False): - self.next.to_wire(file, None, origin, canonicalize) + self.next.to_wire(file, None, origin, False) for (window, bitmap) in self.windows: file.write(struct.pack('!BB', window, len(bitmap))) file.write(bitmap) diff --git a/tests/test_rdata.py b/tests/test_rdata.py index ed2c3f3b..872bdd96 100644 --- a/tests/test_rdata.py +++ b/tests/test_rdata.py @@ -139,6 +139,8 @@ class RdataTestCase(unittest.TestCase): # # types that don't have names: HINFO # + # NSEC3, whose downcasing was removed by RFC 6840 section 5.1 + # cases = [ ('SOA', 'NAME NAME 1 2 3 4 5'), ('AFSDB', '0 NAME'), @@ -147,7 +149,6 @@ class RdataTestCase(unittest.TestCase): ('KX', '10 NAME'), ('MX', '10 NAME'), ('NS', 'NAME'), - ('NSEC', 'NAME A'), ('NAPTR', '0 0 a B c NAME'), ('PTR', 'NAME'), ('PX', '65535 NAME NAME'), @@ -173,5 +174,23 @@ class RdataTestCase(unittest.TestCase): expected_wire = f.getvalue() self.assertEqual(digestable_wire, expected_wire) + def test_digestable_no_downcasing(self): + # Make sure that currently known types with domain names that + # are NOT supposed to be downcased when canonicalized are + # handled properly. + # + cases = [ + ('HIP', '2 200100107B1A74DF365639CC39F1D578 Ym9ndXM= NAME name'), + ('IPSECKEY', '10 3 2 NAME Ym9ndXM='), + ('NSEC', 'NAME A'), + ] + for rdtype, text in cases: + origin = dns.name.from_text('example') + rdata = dns.rdata.from_text(dns.rdataclass.IN, rdtype, text, + origin=origin, relativize=False) + digestable_wire = rdata.to_digestable(origin) + expected_wire = rdata.to_wire(origin=origin) + self.assertEqual(digestable_wire, expected_wire) + if __name__ == '__main__': unittest.main() -- 2.47.3