Commit 8e3ad9a4 authored by Alexandre's avatar Alexandre
Browse files

[DoT] Parse the DNS response outside the connection object

parent 7f042988
......@@ -331,9 +331,9 @@ class RequestDOT(Request):
return False
return self.ok
def store_response(self, rcode, response, size):
def store_response(self, rcode, data, size):
self.rcode = True
self.response = response
self.response = dns.message.from_wire(data)
self.response_size = size
......@@ -595,25 +595,25 @@ class ConnectionDOT(Connection):
except OpenSSL.SSL.WantReadError:
return (False, None, None)
size = int.from_bytes(buf, byteorder='big')
buf = self.session.recv(size)
data = self.session.recv(size)
if dump:
dump_data(buf, 'data recv')
response = dns.message.from_wire(buf)
return (True, response, size)
dump_data(data, 'data recv')
return (True, data, size)
def send_and_receive(self, request, dump=False):
self.send_data(request.data, dump=dump)
rcode, response, size = self.receive_data(dump=dump)
request.store_response(rcode, response, size)
rcode, data, size = self.receive_data(dump=dump)
request.store_response(rcode, data, size)
# this function might need to be move outside
def do_test(self, request, synchronous=True):
self.send_data(request.data)
if synchronous:
rcode, response, size = self.receive_data()
request.store_response(rcode, response, size)
rcode, data, size = self.receive_data()
request.store_response(rcode, data, size)
request.check_response(self.debug)
# should the pipelining methods be part of ConnectionDOT ?
def pipelining_add_request(self, request):
self.all_requests.append({'request': request, 'response': None}) # No answer yet
......@@ -632,16 +632,20 @@ class ConnectionDOT(Connection):
self.pipelining_fill_pending(i)
return i
# this method might need to be moved somewhere else in order to avoid
# calling dns.message.from_wire()
def read_result(self, connection, requests, display_results=True):
rcode, response, size = self.receive_data() # TODO can raise
rcode, data, size = self.receive_data() # TODO can raise
# OpenSSL.SSL.ZeroReturnError
# if the
# conenction was
# connection was
# closed
if not rcode:
if display_results:
print("TIMEOUT")
return None
# TODO remove call to dns.message (use abstraction instead)
response = dns.message.from_wire(data)
id = response.id
if id not in requests:
raise Exception("Received response for ID %s which is unexpected" % id)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment