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