Commit c375f586 authored by Alexandre's avatar Alexandre
Browse files

[DoT] Use a request object holding a message and its response

parent 3e48b3c6
......@@ -167,6 +167,16 @@ def validate_hostname(hostname, cert):
return False
class RequestDoT:
def __init__(self, qname, qtype=rtype):
self.message = dns.message.make_query(qname, dns.rdatatype.from_text(qtype), use_edns=True, want_dnssec=True)
self.data = self.message.to_wire()
def check_response(self):
if self.response.id != self.message.id:
raise Exception("The ID in the answer does not match the one in the query")
class RequestDoH:
def __init__(self, qname, qtype=rtype):
self.message = dns.message.make_query(qname, dns.rdatatype.from_text(qtype), use_edns=True, want_dnssec=True)
......@@ -364,18 +374,15 @@ class ConnectionDoT(Connection):
self.session.close()
def do_test(self, qname, qtype=rtype):
message = dns.message.make_query(qname, dns.rdatatype.from_text(qtype), use_edns=True, want_dnssec=True)
messagew = message.to_wire()
length = len(messagew)
id = message.id
n = self.session.send(length.to_bytes(2, byteorder='big') + messagew)
self.request = RequestDoT(qname, qtype)
length = len(self.request.data)
self.session.send(length.to_bytes(2, byteorder='big') + self.request.data)
buf = self.session.recv(2)
received = int.from_bytes(buf, byteorder='big')
buf = self.session.recv(received)
response = dns.message.from_wire(buf)
if response.id != message.id:
raise Exception("The ID in the answer does not match the one in the query")
return (True, response, received)
self.request.received = int.from_bytes(buf, byteorder='big')
buf = self.session.recv(self.request.received)
self.request.response = dns.message.from_wire(buf)
self.request.check_response()
return (True, self.request.response, self.request.received)
class ConnectionDoH(Connection):
......
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