From: Brian Wellington Date: Tue, 16 Jun 2020 22:33:34 +0000 (-0700) Subject: Add support for TSIG on multi-message responses. X-Git-Tag: v2.0.0rc1~80 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76d726a769f39aff45433ddea3361f2429bcc59c;p=thirdparty%2Fdnspython.git Add support for TSIG on multi-message responses. --- diff --git a/tests/nanonameserver.py b/tests/nanonameserver.py index 43369968..4293d8a0 100644 --- a/tests/nanonameserver.py +++ b/tests/nanonameserver.py @@ -141,12 +141,6 @@ class Server(threading.Thread): else: return [thing] - def maybe_render(self, thing): - if isinstance(thing, dns.message.Message): - return thing.to_wire(self.origin) - else: - return thing - def handle_wire(self, wire, peer, connection_type): # # This is the common code to parse wire format, call handle() on @@ -168,7 +162,7 @@ class Server(threading.Thread): q = dns.message.from_wire(wire, keyring=self.keyring) except dns.message.ShortHeader: # There is no hope of answering this one! - return [] + return except Exception: # Try to make a FORMERR using just the question section. try: @@ -181,7 +175,7 @@ class Server(threading.Thread): # if dnspython had a header_only option to # from_wire(), or if we truncated wire outselves, but # for now we just drop. - return [] + return try: # items might have been appended to above, so skip # handle() if we already have a response. @@ -193,7 +187,16 @@ class Server(threading.Thread): r = dns.message.make_response(q) r.set_rcode(dns.rcode.SERVFAIL) items = [r] - return [self.maybe_render(x) for x in items] + + tsig_ctx = None + multi = len(items) > 1 + for thing in items: + if isinstance(thing, dns.message.Message): + out = thing.to_wire(self.origin, multi=multi, tsig_ctx=tsig_ctx) + tsig_ctx = thing.tsig_ctx + yield out + else: + yield thing async def serve_udp(self): with trio.socket.from_stdlib_socket(self.udp) as sock: