Commit 203247a6 authored by Alexandre's avatar Alexandre
Browse files

[DoT] Dump data with trunc test with --debug

parent c17991a7
......@@ -190,6 +190,12 @@ def validate_hostname(hostname, cert):
return True
return False
def dump_data(data, text="data"):
pref = ' ' * (len(text) - 4)
print(f'{text}: ', data)
print(pref, 'hex:', " ".join(format(c, '02x') for c in data))
print(pref, 'bin:', " ".join(format(c, '08b') for c in data))
def timeout_connection(signum, frame):
raise TimeoutConnectionError('Connection timeout')
......@@ -432,20 +438,24 @@ class ConnectionDoT(Connection):
self.session.shutdown()
self.session.close()
def send_data(self, data):
def send_data(self, data, dump=False):
if dump:
dump_data(data, 'data sent')
length = len(data)
self.session.send(length.to_bytes(2, byteorder='big') + data)
def receive_data(self, request):
def receive_data(self, request, dump=False):
buf = self.session.recv(2)
request.response_size = int.from_bytes(buf, byteorder='big')
buf = self.session.recv(request.response_size)
if dump:
dump_data(buf, 'data recv')
request.response = dns.message.from_wire(buf)
request.rcode = True
def send_and_receive(self, request):
self.send_data(request.data)
self.receive_data(request)
def send_and_receive(self, request, dump=False):
self.send_data(request.data, dump=dump)
self.receive_data(request, dump=dump)
def do_test(self, qname, qtype=rtype):
request = RequestDoT(qname, qtype, want_dnssec=dnssec, use_edns=edns)
......@@ -549,7 +559,7 @@ class ConnectionDoH(Connection):
request.ctype = content_type
self.buffer.close()
def send_and_receive(self, request):
def send_and_receive(self, request, dump=False):
self.prepare(request)
self.perform()
self.receive(request)
......@@ -725,7 +735,7 @@ def run_check_trunc(connection):
request.post = True
try:
# 8.8.8.8 replies FORMERR but most DoT servers violently shut down the connection (which is legal)
connection.send_and_receive(request)
connection.send_and_receive(request, dump=debug)
except CustomException as e:
ok = False
error(e)
......
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