소스 검색

fix(api): accept IPv4-mapped IPv6 addresses in AAAA records

We convert them to "pure IPv6 hex format".

Can be reverted once https://github.com/PowerDNS/pdns/issues/8182 is fixed.
Peter Thomassen 4 년 전
부모
커밋
8935fabb5f
4개의 변경된 파일15개의 추가작업 그리고 2개의 파일을 삭제
  1. 10 0
      api/desecapi/dns.py
  2. 2 1
      api/desecapi/models.py
  3. 2 0
      api/desecapi/tests/test_rrsets.py
  4. 1 1
      test/e2e2/spec/test_api_rr.py

+ 10 - 0
api/desecapi/dns.py

@@ -1,8 +1,11 @@
 import struct
 
+from ipaddress import IPv6Address
+
 import dns
 import dns.rdtypes.txtbase, dns.rdtypes.svcbbase
 import dns.rdtypes.ANY.CDS, dns.rdtypes.ANY.DLV, dns.rdtypes.ANY.DS
+import dns.rdtypes.IN.AAAA
 
 
 def _strip_quotes_decorator(func):
@@ -20,6 +23,13 @@ dns.rdtypes.svcbbase.MandatoryParam.to_text = _strip_quotes_decorator(dns.rdtype
 dns.rdtypes.svcbbase.PortParam.to_text = _strip_quotes_decorator(dns.rdtypes.svcbbase.PortParam.to_text)
 
 
+@dns.immutable.immutable
+class AAAA(dns.rdtypes.IN.AAAA.AAAA):
+    def to_text(self, origin=None, relativize=True, **kw):
+        address = super().to_text(origin, relativize, **kw)
+        return IPv6Address(address).compressed
+
+
 @dns.immutable.immutable
 class LongQuotedTXT(dns.rdtypes.txtbase.TXTBase):
     """

+ 2 - 1
api/desecapi/models.py

@@ -40,7 +40,7 @@ from rest_framework.exceptions import APIException
 
 from desecapi import metrics
 from desecapi import pdns
-from desecapi.dns import CDS, DLV, DS, LongQuotedTXT
+from desecapi.dns import AAAA, CDS, DLV, DS, LongQuotedTXT
 
 logger = logging.getLogger(__name__)
 psl = psl_dns.PSL(resolver=settings.PSL_RESOLVER, timeout=.5)
@@ -681,6 +681,7 @@ class RR(ExportModelOperationsMixin('RR'), models.Model):
     objects = RRManager()
 
     _type_map = {
+        dns.rdatatype.AAAA: AAAA,  # TODO remove when https://github.com/PowerDNS/pdns/issues/8182 is fixed
         dns.rdatatype.CDS: CDS,  # TODO remove when https://github.com/rthalley/dnspython/pull/625 is in main codebase
         dns.rdatatype.DLV: DLV,  # TODO remove when https://github.com/rthalley/dnspython/pull/625 is in main codebase
         dns.rdatatype.DS: DS,  # TODO remove when https://github.com/rthalley/dnspython/pull/625 is in main codebase

+ 2 - 0
api/desecapi/tests/test_rrsets.py

@@ -350,6 +350,8 @@ class AuthenticatedRRSetTestCase(AuthenticatedRRSetBaseTestCase):
             # record type: (non-canonical input, canonical output expectation)
             ('A', ('127.0.0.1', '127.0.0.1')),
             ('AAAA', ('0000::0000:0001', '::1')),
+            ('AAAA', ('::ffff:127.0.0.1', '::ffff:7f00:1')),
+            ('AAAA', ('2001:db8::128.2.129.4', '2001:db8::8002:8104')),
             ('AFSDB', ('02 turquoise.FEMTO.edu.', '2 turquoise.femto.edu.')),
             ('APL', ('2:FF00:0:0:0:0::/8  !1:192.168.38.0/28', '2:ff00::/8 !1:192.168.38.0/28')),
             ('CAA', ('0128 "issue" "letsencrypt.org"', '128 issue "letsencrypt.org"')),

+ 1 - 1
test/e2e2/spec/test_api_rr.py

@@ -145,7 +145,7 @@ VALID_RECORDS_CANONICAL = {
 
 VALID_RECORDS_NON_CANONICAL = {
     'A': ['127.0.0.3'],
-    'AAAA': ['0000::0000:0003'],
+    'AAAA': ['0000::0000:0003', '2001:db8::128.2.129.4'],
     'AFSDB': ['03 turquoise.FEMTO.edu.'],
     'APL': ['2:FF00:0:0:0:0::/8 !1:192.168.38.0/28'],
     'CAA': ['0128 "issue" "letsencrypt.org"'],