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.dnsquery2log(r)
async def doh1handler(request): path, params = utils.extract_path_params(request.rel_url.path_qs) if request.method in ["GET", "HEAD"]: try: ct, body = utils.extract_ct_body(params) except DOHParamsException as e: return aiohttp.web.Response(status=400, body=e.body()) elif request.method == "POST": body = await request.content.read() ct = request.headers.get("content-type") else: return aiohttp.web.Response(status=501, body=b"Not Implemented") if ct != constants.DOH_MEDIA_TYPE: return aiohttp.web.Response(status=415, body=b"Unsupported content type") # Do actual DNS Query try: dnsq = utils.dns_query_from_body(body, debug=request.app.debug) except DOHDNSException as e: return aiohttp.web.Response(status=400, body=e.body()) clientip = utils.get_client_ip(request.transport) request.app.logger.info("[HTTPS] {} (Original IP: {}) {}".format( clientip, request.remote, utils.dnsquery2log(dnsq))) return await request.app.resolve(request, dnsq)
def send_helper(self, transport): self.transport = transport self.dnsq.id = dns.entropy.random_16() self.logger.info( "[DNS] {} {}".format(self.clientip, utils.dnsquery2log(self.dnsq)) ) self.time_stamp = time.time()
async def doh1handler(request): path, params = utils.extract_path_params(request.rel_url.path_qs) if request.method in ['GET', 'HEAD']: try: ct, body = utils.extract_ct_body(params) except DOHParamsException as e: return aiohttp.web.Response(status=400, body=e.body()) elif request.method == 'POST': body = await request.content.read() ct = request.headers.get('content-type') else: return aiohttp.web.Response(status=501, body=b'Not Implemented') if ct != constants.DOH_MEDIA_TYPE: return aiohttp.web.Response( status=415, body=b'Unsupported content type') # Do actual DNS Query try: dnsq = utils.dns_query_from_body(body, debug=request.app.debug) except DOHDNSException as e: return aiohttp.web.Response(status=400, body=e.body()) dnsq = dns.message.from_wire(body) clientip = request.transport.get_extra_info('peername')[0] request.app.logger.info('[HTTPS] {} (Original IP: {}) {}'.format( clientip, request.remote, utils.dnsquery2log(dnsq))) return await request.app.resolve(request, dnsq)
def stream_complete(self, stream_id: int): """ When a stream is complete, we can send our response. """ try: request_data = self.stream_data[stream_id] except KeyError: # Just return, we probably 405'd this already return headers = request_data.headers method = request_data.headers[':method'] # Handle the actual query path, params = utils.extract_path_params(headers[':path']) if path != self.uri: self.return_404(stream_id) return if method in ['GET', 'HEAD']: try: ct, body = utils.extract_ct_body(params) except DOHParamsException as e: self.return_400(stream_id, body=e.body()) return elif method == 'POST': body = request_data.data.getvalue() ct = headers.get('content-type') else: self.return_501(stream_id) return if ct != constants.DOH_MEDIA_TYPE: self.return_415(stream_id) return # Do actual DNS Query try: dnsq = utils.dns_query_from_body(body, self.debug) except DOHDNSException as e: self.return_400(stream_id, body=e.body()) return clientip = self.transport.get_extra_info('peername')[0] self.logger.info( '[HTTPS] {} {}'.format( clientip, utils.dnsquery2log(dnsq) ) ) self.time_stamp = time.time() asyncio.ensure_future(self.resolve(dnsq, stream_id))
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.dnsquery2log(r)
def test_valid_query(self): """ test that no exception is thrown with a legitimate query. """ utils.dnsquery2log(self._q)