def test_refused_response_no_question(self): """ test that no exception is thrown with a legitimate response. """ r = dns.message.make_response(self._q, recursion_available=True) r.set_rcode(dns.rcode.REFUSED) r.question = [] utils.dnsans2log(r)
def on_answer(self, request, dnsr=None, dnsq=None): headers = CIMultiDict() if dnsr is None: dnsr = dns.message.make_response(dnsq) dnsr.set_rcode(dns.rcode.SERVFAIL) elif len(dnsr.answer): ttl = min(r.ttl for r in dnsr.answer) headers["cache-control"] = "max-age={}".format(ttl) clientip = utils.get_client_ip(request.transport) interval = int((time.time() - self.time_stamp) * 1000) self.logger.info("[HTTPS] {} (Original IP: {}) {} {}ms".format( clientip, request.remote, utils.dnsans2log(dnsr), interval)) if request.method == "HEAD": body = b"" else: body = dnsr.to_wire() return aiohttp.web.Response( status=200, body=body, content_type=constants.DOH_MEDIA_TYPE, headers=headers, )
def on_answer(self, stream_id, dnsr=None, dnsq=None): try: request_data = self.stream_data[stream_id] except KeyError: # Just return, we probably 405'd this already return response_headers = [ (':status', '200'), ('content-type', constants.DOH_MEDIA_TYPE), ('server', 'asyncio-h2'), ] if dnsr is None: dnsr = dns.message.make_response(dnsq) dnsr.set_rcode(dns.rcode.SERVFAIL) elif len(dnsr.answer): ttl = min(r.ttl for r in dnsr.answer) response_headers.append( ('cache-control', 'max-age={}'.format(ttl))) clientip = self.transport.get_extra_info('peername')[0] interval = int((time.time() - self.time_stamp) * 1000) self.logger.info('[HTTPS] {} {} {}ms'.format(clientip, utils.dnsans2log(dnsr), interval)) if request_data.headers[':method'] == 'HEAD': body = b'' else: body = dnsr.to_wire() response_headers.append(('content-length', str(len(body)))) self.conn.send_headers(stream_id, response_headers) self.conn.send_data(stream_id, body, end_stream=True) self.transport.write(self.conn.data_to_send())
def on_answer(self, stream_id, dnsr=None, dnsq=None): try: request_data = self.stream_data[stream_id] except KeyError: # Just return, we probably 405'd this already return response_headers = [ (":status", "200"), ("content-type", constants.DOH_MEDIA_TYPE), ("server", "asyncio-h2"), ] if dnsr is None: dnsr = dns.message.make_response(dnsq) dnsr.set_rcode(dns.rcode.SERVFAIL) elif len(dnsr.answer): ttl = min(r.ttl for r in dnsr.answer) response_headers.append( ("cache-control", "max-age={}".format(ttl))) clientip = utils.get_client_ip(self.transport) interval = int((time.time() - self.time_stamp) * 1000) self.logger.info("[HTTPS] {} {} {}ms".format(clientip, utils.dnsans2log(dnsr), interval)) if request_data.headers[":method"] == "HEAD": body = b"" else: body = dnsr.to_wire() response_headers.append(("content-length", str(len(body)))) self.conn.send_headers(stream_id, response_headers) self.conn.send_data(stream_id, body, end_stream=True) self.transport.write(self.conn.data_to_send())
def receive_helper(self, dnsr): interval = int((time.time() - self.time_stamp) * 1000) log_message = "[DNS] {} {} {}ms".format( self.clientip, utils.dnsans2log(dnsr), interval ) if not self.fut.cancelled(): self.logger.info(log_message) self.fut.set_result(dnsr) else: self.logger.info(log_message + "(CANCELLED)")
def test_valid_response(self): """ test that no exception is thrown with a legitimate response. """ r = dns.message.make_response(self._q, recursion_available=True) utils.dnsans2log(r)
def test_valid_query(self): """ test that no exception is thrown with a legitimate query. """ utils.dnsans2log(self._q)
def receive_helper(self, dnsr): interval = int((time.time() - self.time_stamp) * 1000) self.logger.info('[DNS] {} {} {}ms'.format(self.clientip, utils.dnsans2log(dnsr), interval)) self.fut.set_result(dnsr)