Commit bc2c0bfa authored by Alexandre's avatar Alexandre
Browse files

Compute EDNS(0) "Padding" option size

In order to calculate the number of octets to pad, we need to know the
size of the DNS query so far. We use dnspython to generate the wire
query and get its length. We add an EDNS(0) field so we have to add 4
octets which are the size of the Option code and the Option length. Then
we can calculate the number of octets to pad based on the Block-length
strategy (using 128 octets block size).
See RFC 7830 and 8467.
parent 1d18460a
......@@ -19,9 +19,19 @@ class Request:
opt = dns.edns.ECSOption(address='', srclen=0) # Disable ECS (RFC 7871, section 7.1.2)
options.append(opt)
if padding:
pad_size = 10 # TODO calculate the padding size (see RFC 7830 and 8467)
opt = dns.edns.GenericOption(dns.edns.PADDING, b'\0' * pad_size)
if padding: # RFC 7830 and RFC 8467
BLOCK_SIZE = 128 # RFC 8467, section 4.1
PADDING_DATA = b'\x00'
# compute temporary size
msg = dns.message.make_query(qname, dns.rdatatype.from_text(qtype),
use_edns=use_edns, want_dnssec=want_dnssec, options=options)
wire_msg = msg.to_wire()
msg_size = len(wire_msg) + 4 # add 4 octets for PADDING OPTION + PADDING LENGTH
if msg_size % BLOCK_SIZE != 0:
pad_size = BLOCK_SIZE - (msg_size % BLOCK_SIZE)
else:
pad_size = 0
opt = dns.edns.GenericOption(dns.edns.PADDING, PADDING_DATA * pad_size)
options.append(opt)
self.message = dns.message.make_query(qname, dns.rdatatype.from_text(qtype),
......
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