mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 22:15:23 +00:00
[#3287] fix pycodestyle warnings
- E111 indentation is not a multiple of 4 - E117 over-indented - E125 continuation line with same indent as next logical line - E127 continuation line over-indented for visual indent - E128 continuation line under-indented for visual indent - E129 visually indented line with same indent as next logical line - E131 continuation line unaligned for hanging indent - E201 whitespace after '[' - E201 whitespace after '{' - E202 whitespace before ')' - E202 whitespace before ']' - E202 whitespace before '}' - E203 whitespace before ' - E203 whitespace before ',' - E222 multiple spaces after operator - E225 missing whitespace around operator - E228 missing whitespace around modulo operator - E231 missing whitespace after ',' - E251 unexpected spaces around keyword / parameter equals - E261 at least two spaces before inline comment - E262 inline comment should start with '# ' - E265 block comment should start with '# ' - E301 expected 1 blank line, found 0 - E302 expected 2 blank lines, found 1 - E303 too many blank lines (2) - E305 expected 2 blank lines after class or function definition, found 1 - E306 expected 1 blank line before a nested definition, found 0 - E401 multiple imports on one line - E402 module level import not at top of file - E501 line too long - E502 the backslash is redundant between brackets - E703 statement ends with a semicolon - E713 test for membership should be 'not in' - E722 do not use bare 'except' - E741 ambiguous variable name 'l' - W605 invalid escape sequence '\/'
This commit is contained in:
@@ -316,7 +316,12 @@ What you are expected to do is as follows:
|
||||
examples.
|
||||
"""
|
||||
|
||||
import configparser, re, time, socket, sys, base64
|
||||
import configparser
|
||||
import re
|
||||
import time
|
||||
import socket
|
||||
import sys
|
||||
import base64
|
||||
from datetime import datetime
|
||||
from optparse import OptionParser
|
||||
|
||||
@@ -326,44 +331,42 @@ re_string = re.compile(r"\'(.*)\'$")
|
||||
|
||||
dnssec_timefmt = '%Y%m%d%H%M%S'
|
||||
|
||||
dict_qr = { 'query' : 0, 'response' : 1 }
|
||||
dict_opcode = { 'query' : 0, 'iquery' : 1, 'status' : 2, 'notify' : 4,
|
||||
'update' : 5 }
|
||||
dict_qr = {'query': 0, 'response': 1}
|
||||
dict_opcode = {'query': 0, 'iquery': 1, 'status': 2, 'notify': 4,
|
||||
'update': 5}
|
||||
rdict_opcode = dict([(dict_opcode[k], k.upper()) for k in dict_opcode.keys()])
|
||||
dict_rcode = { 'noerror' : 0, 'formerr' : 1, 'servfail' : 2, 'nxdomain' : 3,
|
||||
'notimp' : 4, 'refused' : 5, 'yxdomain' : 6, 'yxrrset' : 7,
|
||||
'nxrrset' : 8, 'notauth' : 9, 'notzone' : 10 }
|
||||
dict_rcode = {'noerror': 0, 'formerr': 1, 'servfail': 2, 'nxdomain': 3,
|
||||
'notimp': 4, 'refused': 5, 'yxdomain': 6, 'yxrrset': 7,
|
||||
'nxrrset': 8, 'notauth': 9, 'notzone': 10}
|
||||
rdict_rcode = dict([(dict_rcode[k], k.upper()) for k in dict_rcode.keys()])
|
||||
dict_rrtype = { 'none' : 0, 'a' : 1, 'ns' : 2, 'md' : 3, 'mf' : 4, 'cname' : 5,
|
||||
'soa' : 6, 'mb' : 7, 'mg' : 8, 'mr' : 9, 'null' : 10,
|
||||
'wks' : 11, 'ptr' : 12, 'hinfo' : 13, 'minfo' : 14, 'mx' : 15,
|
||||
'txt' : 16, 'rp' : 17, 'afsdb' : 18, 'x25' : 19, 'isdn' : 20,
|
||||
'rt' : 21, 'nsap' : 22, 'nsap_tr' : 23, 'sig' : 24, 'key' : 25,
|
||||
'px' : 26, 'gpos' : 27, 'aaaa' : 28, 'loc' : 29, 'nxt' : 30,
|
||||
'srv' : 33, 'naptr' : 35, 'kx' : 36, 'cert' : 37, 'a6' : 38,
|
||||
'dname' : 39, 'opt' : 41, 'apl' : 42, 'ds' : 43, 'sshfp' : 44,
|
||||
'ipseckey' : 45, 'rrsig' : 46, 'nsec' : 47, 'dnskey' : 48,
|
||||
'dhcid' : 49, 'nsec3' : 50, 'nsec3param' : 51, 'tlsa' : 52, 'hip' : 55,
|
||||
'spf' : 99, 'unspec' : 103, 'tkey' : 249, 'tsig' : 250,
|
||||
'dlv' : 32769, 'ixfr' : 251, 'axfr' : 252, 'mailb' : 253,
|
||||
'maila' : 254, 'any' : 255, 'caa' : 257 }
|
||||
dict_rrtype = {'none': 0, 'a': 1, 'ns': 2, 'md': 3, 'mf': 4, 'cname': 5,
|
||||
'soa': 6, 'mb': 7, 'mg': 8, 'mr': 9, 'null': 10,
|
||||
'wks': 11, 'ptr': 12, 'hinfo': 13, 'minfo': 14, 'mx': 15,
|
||||
'txt': 16, 'rp': 17, 'afsdb': 18, 'x25': 19, 'isdn': 20,
|
||||
'rt': 21, 'nsap': 22, 'nsap_tr': 23, 'sig': 24, 'key': 25,
|
||||
'px': 26, 'gpos': 27, 'aaaa': 28, 'loc': 29, 'nxt': 30,
|
||||
'srv': 33, 'naptr': 35, 'kx': 36, 'cert': 37, 'a6': 38,
|
||||
'dname': 39, 'opt': 41, 'apl': 42, 'ds': 43, 'sshfp': 44,
|
||||
'ipseckey': 45, 'rrsig': 46, 'nsec': 47, 'dnskey': 48,
|
||||
'dhcid': 49, 'nsec3': 50, 'nsec3param': 51, 'tlsa': 52, 'hip': 55,
|
||||
'spf': 99, 'unspec': 103, 'tkey': 249, 'tsig': 250,
|
||||
'dlv': 32769, 'ixfr': 251, 'axfr': 252, 'mailb': 253,
|
||||
'maila': 254, 'any': 255, 'caa': 257}
|
||||
rdict_rrtype = dict([(dict_rrtype[k], k.upper()) for k in dict_rrtype.keys()])
|
||||
dict_rrclass = { 'in' : 1, 'ch' : 3, 'hs' : 4, 'any' : 255 }
|
||||
rdict_rrclass = dict([(dict_rrclass[k], k.upper()) for k in \
|
||||
dict_rrclass.keys()])
|
||||
dict_algorithm = { 'rsamd5' : 1, 'dh' : 2, 'dsa' : 3, 'ecc' : 4,
|
||||
'rsasha1' : 5 }
|
||||
dict_nsec3_algorithm = { 'reserved' : 0, 'sha1' : 1 }
|
||||
rdict_algorithm = dict([(dict_algorithm[k], k.upper()) for k in \
|
||||
dict_algorithm.keys()])
|
||||
rdict_nsec3_algorithm = dict([(dict_nsec3_algorithm[k], k.upper()) for k in \
|
||||
dict_nsec3_algorithm.keys()])
|
||||
dict_rrclass = {'in': 1, 'ch': 3, 'hs': 4, 'any': 255}
|
||||
rdict_rrclass = dict([(dict_rrclass[k], k.upper()) for k in dict_rrclass.keys()])
|
||||
dict_algorithm = {'rsamd5': 1, 'dh': 2, 'dsa': 3, 'ecc': 4,
|
||||
'rsasha1': 5}
|
||||
dict_nsec3_algorithm = {'reserved': 0, 'sha1': 1}
|
||||
rdict_algorithm = dict([(dict_algorithm[k], k.upper()) for k in dict_algorithm.keys()])
|
||||
rdict_nsec3_algorithm = dict([(dict_nsec3_algorithm[k], k.upper()) for k in dict_nsec3_algorithm.keys()])
|
||||
|
||||
header_xtables = { 'qr' : dict_qr, 'opcode' : dict_opcode,
|
||||
'rcode' : dict_rcode }
|
||||
question_xtables = { 'rrtype' : dict_rrtype, 'rrclass' : dict_rrclass }
|
||||
header_xtables = {'qr': dict_qr, 'opcode': dict_opcode,
|
||||
'rcode': dict_rcode}
|
||||
question_xtables = {'rrtype': dict_rrtype, 'rrclass': dict_rrclass}
|
||||
|
||||
def parse_value(value, xtable = {}):
|
||||
|
||||
def parse_value(value, xtable={}):
|
||||
if re.search(re_hex, value):
|
||||
return int(value, 16)
|
||||
if re.search(re_decimal, value):
|
||||
@@ -376,48 +379,54 @@ def parse_value(value, xtable = {}):
|
||||
return xtable[lovalue]
|
||||
return value
|
||||
|
||||
|
||||
def code_totext(code, dict):
|
||||
if code in dict.keys():
|
||||
return dict[code] + '(' + str(code) + ')'
|
||||
return str(code)
|
||||
|
||||
|
||||
def encode_name(name, absolute=True):
|
||||
# make sure the name is dot-terminated. duplicate dots will be ignored
|
||||
# below.
|
||||
name += '.'
|
||||
labels = name.split('.')
|
||||
wire = ''
|
||||
for l in labels:
|
||||
if len(l) > 4 and l[0:4] == 'ptr=':
|
||||
for label in labels:
|
||||
if len(label) > 4 and label[0:4] == 'ptr=':
|
||||
# special meta-syntax for compression pointer
|
||||
wire += '%04x' % (0xc000 | int(l[4:]))
|
||||
break
|
||||
if absolute or len(l) > 0:
|
||||
wire += '%02x' % len(l)
|
||||
wire += ''.join(['%02x' % ord(ch) for ch in l])
|
||||
if len(l) == 0:
|
||||
if absolute or len(label) > 0:
|
||||
wire += '%02x' % len(label)
|
||||
wire += ''.join(['%02x' % ord(ch) for ch in label])
|
||||
if len(label) == 0:
|
||||
break
|
||||
return wire
|
||||
|
||||
|
||||
def encode_string(name, len=None):
|
||||
if type(name) is int and len is not None:
|
||||
return '%0.*x' % (len * 2, name)
|
||||
return ''.join(['%02x' % ord(ch) for ch in name])
|
||||
|
||||
|
||||
def encode_bytes(name, len=None):
|
||||
if type(name) is int and len is not None:
|
||||
return '%0.*x' % (len * 2, name)
|
||||
return ''.join(['%02x' % ch for ch in name])
|
||||
|
||||
|
||||
def count_namelabels(name):
|
||||
if name == '.': # special case
|
||||
return 0
|
||||
m = re.match('^(.*)\.$', name)
|
||||
m = re.match(r'^(.*)\.$', name)
|
||||
if m:
|
||||
name = m.group(1)
|
||||
return len(name.split('.'))
|
||||
|
||||
def get_config(config, section, configobj, xtables = {}):
|
||||
|
||||
def get_config(config, section, configobj, xtables={}):
|
||||
try:
|
||||
for field in config.options(section):
|
||||
value = config.get(section, field)
|
||||
@@ -430,12 +439,14 @@ def get_config(config, section, configobj, xtables = {}):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def print_header(f, input_file):
|
||||
f.write('''###
|
||||
### This data file was auto-generated from ''' + input_file + '''
|
||||
###
|
||||
''')
|
||||
|
||||
|
||||
class Name:
|
||||
'''Implements rendering a single domain name in the test data format.
|
||||
|
||||
@@ -449,7 +460,8 @@ class Name:
|
||||
'''
|
||||
|
||||
name = 'example.com'
|
||||
pointer = None # no compression by default
|
||||
pointer = None # no compression by default
|
||||
|
||||
def dump(self, f):
|
||||
name = self.name
|
||||
if self.pointer is not None:
|
||||
@@ -464,6 +476,7 @@ class Name:
|
||||
f.write('%s' % name_wire)
|
||||
f.write('\n')
|
||||
|
||||
|
||||
class DNSHeader:
|
||||
'''Implements rendering a DNS Header section in the test data format.
|
||||
|
||||
@@ -516,6 +529,7 @@ class DNSHeader:
|
||||
f.write('%04x %04x %04x %04x\n' % (self.qdcount, self.ancount,
|
||||
self.nscount, self.arcount))
|
||||
|
||||
|
||||
class DNSQuestion:
|
||||
'''Implements rendering a DNS question in the test data format.
|
||||
|
||||
@@ -545,6 +559,7 @@ class DNSQuestion:
|
||||
f.write(encode_name(self.name))
|
||||
f.write(' %04x %04x\n' % (self.rrtype, self.rrclass))
|
||||
|
||||
|
||||
class EDNS:
|
||||
'''Implements rendering EDNS OPT RR in the test data format.
|
||||
|
||||
@@ -569,13 +584,14 @@ class EDNS:
|
||||
do = 0
|
||||
mbz = 0
|
||||
rdlen = 0
|
||||
|
||||
def dump(self, f):
|
||||
f.write('\n# EDNS OPT RR\n')
|
||||
f.write('# NAME=%s TYPE=%s UDPSize=%d ExtRcode=%s Version=%s DO=%d\n' %
|
||||
(self.name, code_totext(dict_rrtype['opt'], rdict_rrtype),
|
||||
self.udpsize, self.extrcode, self.version,
|
||||
1 if self.do else 0))
|
||||
|
||||
|
||||
code_vers = (self.extrcode << 8) | (self.version & 0x00ff)
|
||||
extflags = (self.do << 15) | (self.mbz & ~0x8000)
|
||||
f.write('%s %04x %04x %04x %04x\n' %
|
||||
@@ -584,6 +600,7 @@ class EDNS:
|
||||
f.write('# RDLEN=%d\n' % self.rdlen)
|
||||
f.write('%04x\n' % self.rdlen)
|
||||
|
||||
|
||||
class RR:
|
||||
'''This is a base class for various types of RR test data.
|
||||
For each RR type (A, AAAA, NS, etc), we define a derived class of RR
|
||||
@@ -647,6 +664,7 @@ class RR:
|
||||
f.write('\n# %s RDATA%s\n' % (type_txt, rdlen_spec))
|
||||
f.write('%s\n' % rdlen_data)
|
||||
|
||||
|
||||
class A(RR):
|
||||
'''Implements rendering A RDATA (of class IN) in the test data format.
|
||||
|
||||
@@ -667,6 +685,7 @@ class A(RR):
|
||||
f.write('%02x%02x%02x%02x\n' % (bin_address[0], bin_address[1],
|
||||
bin_address[2], bin_address[3]))
|
||||
|
||||
|
||||
class AAAA(RR):
|
||||
'''Implements rendering AAAA RDATA (of class IN) in the test data
|
||||
format.
|
||||
@@ -688,6 +707,7 @@ class AAAA(RR):
|
||||
[f.write('%02x' % x) for x in bin_address]
|
||||
f.write('\n')
|
||||
|
||||
|
||||
class NS(RR):
|
||||
'''Implements rendering NS RDATA in the test data format.
|
||||
|
||||
@@ -707,6 +727,7 @@ class NS(RR):
|
||||
f.write('# NS name=%s\n' % (self.nsname))
|
||||
f.write('%s\n' % nsname_wire)
|
||||
|
||||
|
||||
class SOA(RR):
|
||||
'''Implements rendering SOA RDATA in the test data format.
|
||||
|
||||
@@ -728,6 +749,7 @@ class SOA(RR):
|
||||
retry = 300
|
||||
expire = 3600000
|
||||
minimum = 1200
|
||||
|
||||
def dump(self, f):
|
||||
mname_wire = encode_name(self.mname)
|
||||
rname_wire = encode_name(self.rname)
|
||||
@@ -743,6 +765,7 @@ class SOA(RR):
|
||||
self.retry, self.expire,
|
||||
self.minimum))
|
||||
|
||||
|
||||
class TXT(RR):
|
||||
'''Implements rendering TXT RDATA in the test data format.
|
||||
|
||||
@@ -796,6 +819,7 @@ class TXT(RR):
|
||||
' ' if len(wirestring_list[i]) > 0 else '',
|
||||
wirestring_list[i]))
|
||||
|
||||
|
||||
class RP(RR):
|
||||
'''Implements rendering RP RDATA in the test data format.
|
||||
|
||||
@@ -807,6 +831,7 @@ class RP(RR):
|
||||
'''
|
||||
mailbox = 'root.example.com'
|
||||
text = 'rp-text.example.com'
|
||||
|
||||
def dump(self, f):
|
||||
mailbox_wire = encode_name(self.mailbox)
|
||||
text_wire = encode_name(self.text)
|
||||
@@ -818,6 +843,7 @@ class RP(RR):
|
||||
f.write('# MAILBOX=%s TEXT=%s\n' % (self.mailbox, self.text))
|
||||
f.write('%s %s\n' % (mailbox_wire, text_wire))
|
||||
|
||||
|
||||
class SSHFP(RR):
|
||||
'''Implements rendering SSHFP RDATA in the test data format.
|
||||
|
||||
@@ -830,6 +856,7 @@ class SSHFP(RR):
|
||||
algorithm = 2
|
||||
fingerprint_type = 1
|
||||
fingerprint = '123456789abcdef67890123456789abcdef67890'
|
||||
|
||||
def dump(self, f):
|
||||
if self.rdlen is None:
|
||||
self.rdlen = 2 + (len(self.fingerprint) / 2)
|
||||
@@ -841,6 +868,7 @@ class SSHFP(RR):
|
||||
self.fingerprint))
|
||||
f.write('%02x %02x %s\n' % (self.algorithm, self.fingerprint_type, self.fingerprint))
|
||||
|
||||
|
||||
class CAA(RR):
|
||||
'''Implements rendering CAA RDATA in the test data format.
|
||||
|
||||
@@ -853,20 +881,20 @@ class CAA(RR):
|
||||
flags = 0
|
||||
tag = 'issue'
|
||||
value = 'ca.example.net'
|
||||
|
||||
def dump(self, f):
|
||||
if self.rdlen is None:
|
||||
self.rdlen = 1 + 1 + len(self.tag) + len(self.value)
|
||||
else:
|
||||
self.rdlen = int(self.rdlen)
|
||||
self.dump_header(f, self.rdlen)
|
||||
f.write('# FLAGS=%d TAG=%s VALUE=%s\n' % \
|
||||
(self.flags, self.tag, self.value))
|
||||
f.write('%02x %02x ' % \
|
||||
(self.flags, len(self.tag)))
|
||||
f.write('# FLAGS=%d TAG=%s VALUE=%s\n' % (self.flags, self.tag, self.value))
|
||||
f.write('%02x %02x ' % (self.flags, len(self.tag)))
|
||||
f.write(encode_string(self.tag))
|
||||
f.write(encode_string(self.value))
|
||||
f.write('\n')
|
||||
|
||||
|
||||
class DNSKEY(RR):
|
||||
'''Implements rendering DNSKEY RDATA in the test data format.
|
||||
|
||||
@@ -903,6 +931,7 @@ class DNSKEY(RR):
|
||||
f.write('# DIGEST=%s\n' % (self.digest))
|
||||
f.write('%s\n' % (encode_bytes(decoded_digest)))
|
||||
|
||||
|
||||
class NSECBASE(RR):
|
||||
'''Implements rendering NSEC/NSEC3 type bitmaps commonly used for
|
||||
these RRs. The NSEC and NSEC3 classes will be inherited from this
|
||||
@@ -928,8 +957,9 @@ class NSECBASE(RR):
|
||||
'''
|
||||
nbitmap = 1 # number of bitmaps
|
||||
block = 0
|
||||
maplen = None # default bitmap length, auto-calculate
|
||||
maplen = None # default bitmap length, auto-calculate
|
||||
bitmap = '040000000003' # an arbitrarily chosen bitmap sample
|
||||
|
||||
def dump(self, f):
|
||||
# first, construct the bitmap data
|
||||
block_list = []
|
||||
@@ -946,17 +976,16 @@ class NSECBASE(RR):
|
||||
maplen_list.append(self.__dict__[key_maplen])
|
||||
else:
|
||||
maplen_list.append(self.maplen)
|
||||
if maplen_list[-1] is None: # calculate it if not specified
|
||||
if maplen_list[-1] is None: # calculate it if not specified
|
||||
maplen_list[-1] = int(len(bitmap_list[-1]) / 2)
|
||||
key_block = 'block' + str(i)
|
||||
if key_block in self.__dict__:
|
||||
block_list.append(self.__dict__[key_block])
|
||||
block_list.append(self.__dict__[key_block])
|
||||
else:
|
||||
block_list.append(self.block)
|
||||
|
||||
# dump RR-type specific part (NSEC or NSEC3)
|
||||
self.dump_fixedpart(f, 2 * self.nbitmap + \
|
||||
int(len(''.join(bitmap_list)) / 2))
|
||||
self.dump_fixedpart(f, 2 * self.nbitmap + int(len(''.join(bitmap_list)) / 2))
|
||||
|
||||
# dump the bitmap
|
||||
for i in range(0, self.nbitmap):
|
||||
@@ -965,6 +994,7 @@ class NSECBASE(RR):
|
||||
f.write('%02x %02x %s\n' %
|
||||
(block_list[i], maplen_list[i], bitmap_list[i]))
|
||||
|
||||
|
||||
class NSEC(NSECBASE):
|
||||
'''Implements rendering NSEC RDATA in the test data format.
|
||||
|
||||
@@ -976,6 +1006,7 @@ class NSEC(NSECBASE):
|
||||
'''
|
||||
|
||||
nextname = 'next.example.com'
|
||||
|
||||
def dump_fixedpart(self, f, bitmap_totallen):
|
||||
name_wire = encode_name(self.nextname)
|
||||
if self.rdlen is None:
|
||||
@@ -987,6 +1018,7 @@ class NSEC(NSECBASE):
|
||||
int(len(name_wire) / 2)))
|
||||
f.write('%s\n' % name_wire)
|
||||
|
||||
|
||||
class NSEC3PARAM(RR):
|
||||
'''Implements rendering NSEC3PARAM RDATA in the test data format.
|
||||
|
||||
@@ -1035,6 +1067,7 @@ class NSEC3PARAM(RR):
|
||||
' ' if len(self.salt) > 0 else '',
|
||||
encode_string(self.salt)))
|
||||
|
||||
|
||||
class NSEC3(NSECBASE, NSEC3PARAM):
|
||||
'''Implements rendering NSEC3 RDATA in the test data format.
|
||||
|
||||
@@ -1049,12 +1082,12 @@ class NSEC3(NSECBASE, NSEC3PARAM):
|
||||
|
||||
hashlen = 20
|
||||
hash = 'h' * hashlen
|
||||
|
||||
def dump_fixedpart(self, f, bitmap_totallen):
|
||||
if self.rdlen is None:
|
||||
# if rdlen needs to be calculated, it must be based on the bitmap
|
||||
# length, because the configured maplen can be fake.
|
||||
self.rdlen = 4 + 1 + len(self.salt) + 1 + len(self.hash) \
|
||||
+ bitmap_totallen
|
||||
self.rdlen = 4 + 1 + len(self.salt) + 1 + len(self.hash) + bitmap_totallen
|
||||
self.dump_header(f, self.rdlen)
|
||||
self._dump_params(f)
|
||||
f.write("# Hash Len=%d, Hash='%s'\n" % (self.hashlen, self.hash))
|
||||
@@ -1062,6 +1095,7 @@ class NSEC3(NSECBASE, NSEC3PARAM):
|
||||
' ' if len(self.hash) > 0 else '',
|
||||
encode_string(self.hash)))
|
||||
|
||||
|
||||
class RRSIG(RR):
|
||||
'''Implements rendering RRSIG RDATA in the test data format.
|
||||
|
||||
@@ -1130,6 +1164,7 @@ class RRSIG(RR):
|
||||
f.write('# Tag=%d Signer=%s and Signature\n' % (self.tag, self.signer))
|
||||
f.write('%04x %s %s\n' % (self.tag, name_wire, sig_wire))
|
||||
|
||||
|
||||
class TKEY(RR):
|
||||
'''Implements rendering TKEY RDATA in the test data format.
|
||||
|
||||
@@ -1201,8 +1236,7 @@ class TKEY(RR):
|
||||
else:
|
||||
other_data = encode_string(self.other_data, other_len)
|
||||
if self.rdlen is None:
|
||||
self.rdlen = int(len(name_wire) / 2 + 16 + len(key) / 2 + \
|
||||
len(other_data) / 2)
|
||||
self.rdlen = int(len(name_wire) / 2 + 16 + len(key) / 2 + len(other_data) / 2)
|
||||
self.dump_header(f, self.rdlen)
|
||||
f.write('# Algorithm=%s\n' % self.algorithm)
|
||||
f.write('%s\n' % name_wire)
|
||||
@@ -1216,6 +1250,7 @@ class TKEY(RR):
|
||||
f.write('%04x%s\n' % (other_len,
|
||||
' ' + other_data if len(other_data) > 0 else ''))
|
||||
|
||||
|
||||
class TLSA(RR):
|
||||
'''Implements rendering TLSA RDATA in the test data format.
|
||||
|
||||
@@ -1230,18 +1265,20 @@ class TLSA(RR):
|
||||
selector = 0
|
||||
matching_type = 1
|
||||
certificate_association_data = 'd2abde240d7cd3ee6b4b28c54df034b97983a1d16e8a410e4561cb106618e971'
|
||||
|
||||
def dump(self, f):
|
||||
if self.rdlen is None:
|
||||
self.rdlen = 2 + (len(self.certificate_association_data) / 2)
|
||||
else:
|
||||
self.rdlen = int(self.rdlen)
|
||||
self.dump_header(f, self.rdlen)
|
||||
f.write('# CERTIFICATE_USAGE=%d SELECTOR=%d MATCHING_TYPE=%d CERTIFICATE_ASSOCIATION_DATA=%s\n' %\
|
||||
(self.certificate_usage, self.selector, self.matching_type,\
|
||||
f.write('# CERTIFICATE_USAGE=%d SELECTOR=%d MATCHING_TYPE=%d CERTIFICATE_ASSOCIATION_DATA=%s\n' %
|
||||
(self.certificate_usage, self.selector, self.matching_type,
|
||||
self.certificate_association_data))
|
||||
f.write('%02x %02x %02x %s\n' % (self.certificate_usage, self.selector, self.matching_type,\
|
||||
f.write('%02x %02x %02x %s\n' % (self.certificate_usage, self.selector, self.matching_type,
|
||||
self.certificate_association_data))
|
||||
|
||||
|
||||
class TSIG(RR):
|
||||
'''Implements rendering TSIG RDATA in the test data format.
|
||||
|
||||
@@ -1293,7 +1330,7 @@ class TSIG(RR):
|
||||
error = 0
|
||||
other_len = None # 6 if error is BADTIME; otherwise 0
|
||||
other_data = None # use time_signed + fudge + 1 for BADTIME
|
||||
dict_macsize = { 'hmac-md5' : 16, 'hmac-sha1' : 20, 'hmac-sha256' : 32 }
|
||||
dict_macsize = {'hmac-md5': 16, 'hmac-sha1': 20, 'hmac-sha256': 32}
|
||||
|
||||
# TSIG has some special defaults
|
||||
def __init__(self):
|
||||
@@ -1312,21 +1349,18 @@ class TSIG(RR):
|
||||
mac_size = self.dict_macsize[self.algorithm]
|
||||
else:
|
||||
raise RuntimeError('TSIG Mac Size cannot be determined')
|
||||
mac = encode_string('x' * mac_size) if self.mac is None else \
|
||||
encode_string(self.mac, mac_size)
|
||||
mac = encode_string('x' * mac_size) if self.mac is None else encode_string(self.mac, mac_size)
|
||||
other_len = self.other_len
|
||||
if other_len is None:
|
||||
# 18 = BADTIME
|
||||
other_len = 6 if self.error == 18 else 0
|
||||
other_data = self.other_data
|
||||
if other_data is None:
|
||||
other_data = '%012x' % (self.time_signed + self.fudge + 1) \
|
||||
if self.error == 18 else ''
|
||||
other_data = '%012x' % (self.time_signed + self.fudge + 1) if self.error == 18 else ''
|
||||
else:
|
||||
other_data = encode_string(self.other_data, other_len)
|
||||
if self.rdlen is None:
|
||||
self.rdlen = int(len(name_wire) / 2 + 16 + len(mac) / 2 + \
|
||||
len(other_data) / 2)
|
||||
self.rdlen = int(len(name_wire) / 2 + 16 + len(mac) / 2 + len(other_data) / 2)
|
||||
self.dump_header(f, self.rdlen)
|
||||
f.write('# Algorithm=%s Time-Signed=%d Fudge=%d\n' %
|
||||
(self.algorithm, self.time_signed, self.fudge))
|
||||
@@ -1334,11 +1368,12 @@ class TSIG(RR):
|
||||
f.write('# MAC Size=%d MAC=(see hex)\n' % mac_size)
|
||||
f.write('%04x%s\n' % (mac_size, ' ' + mac if len(mac) > 0 else ''))
|
||||
f.write('# Original-ID=%d Error=%d\n' % (self.original_id, self.error))
|
||||
f.write('%04x %04x\n' % (self.original_id, self.error))
|
||||
f.write('%04x %04x\n' % (self.original_id, self.error))
|
||||
f.write('# Other-Len=%d Other-Data=(see hex)\n' % other_len)
|
||||
f.write('%04x%s\n' % (other_len,
|
||||
' ' + other_data if len(other_data) > 0 else ''))
|
||||
|
||||
|
||||
class MINFO(RR):
|
||||
'''Implements rendering MINFO RDATA in the test data format.
|
||||
|
||||
@@ -1350,6 +1385,7 @@ class MINFO(RR):
|
||||
'''
|
||||
rmailbox = 'rmailbox.example.com'
|
||||
emailbox = 'emailbox.example.com'
|
||||
|
||||
def dump(self, f):
|
||||
rmailbox_wire = encode_name(self.rmailbox)
|
||||
emailbox_wire = encode_name(self.emailbox)
|
||||
@@ -1361,6 +1397,7 @@ class MINFO(RR):
|
||||
f.write('# RMAILBOX=%s EMAILBOX=%s\n' % (self.rmailbox, self.emailbox))
|
||||
f.write('%s %s\n' % (rmailbox_wire, emailbox_wire))
|
||||
|
||||
|
||||
class AFSDB(RR):
|
||||
'''Implements rendering AFSDB RDATA in the test data format.
|
||||
|
||||
@@ -1372,6 +1409,7 @@ class AFSDB(RR):
|
||||
'''
|
||||
subtype = 1
|
||||
server = 'afsdb.example.com'
|
||||
|
||||
def dump(self, f):
|
||||
server_wire = encode_name(self.server)
|
||||
if self.rdlen is None:
|
||||
@@ -1382,11 +1420,12 @@ class AFSDB(RR):
|
||||
f.write('# SUBTYPE=%d SERVER=%s\n' % (self.subtype, self.server))
|
||||
f.write('%04x %s\n' % (self.subtype, server_wire))
|
||||
|
||||
|
||||
# Build section-class mapping
|
||||
config_param = { 'name' : (Name, {}),
|
||||
'header' : (DNSHeader, header_xtables),
|
||||
'question' : (DNSQuestion, question_xtables),
|
||||
'edns' : (EDNS, {}) }
|
||||
config_param = {'name': (Name, {}),
|
||||
'header': (DNSHeader, header_xtables),
|
||||
'question': (DNSQuestion, question_xtables),
|
||||
'edns': (EDNS, {})}
|
||||
for rrtype in dict_rrtype.keys():
|
||||
# For any supported RR types add the tuple of (RR_CLASS, {}).
|
||||
# We expect KeyError as not all the types are supported, and simply
|
||||
@@ -1397,14 +1436,17 @@ for rrtype in dict_rrtype.keys():
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
||||
def get_config_param(section):
|
||||
s = section
|
||||
m = re.match('^([^:]+)/\d+$', section)
|
||||
m = re.match(r'^([^:]+)/\d+$', section)
|
||||
if m:
|
||||
s = m.group(1)
|
||||
return config_param[s]
|
||||
|
||||
usage = '''usage: %prog [options] input_file'''
|
||||
|
||||
usage = 'usage: %prog [options] input_file'
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = OptionParser(usage=usage)
|
||||
@@ -1419,7 +1461,7 @@ if __name__ == "__main__":
|
||||
|
||||
outputfile = options.output
|
||||
if not outputfile:
|
||||
m = re.match('(.*)\.[^.]+$', configfile)
|
||||
m = re.match(r'(.*)\.[^.]+$', configfile)
|
||||
if m:
|
||||
outputfile = m.group(1)
|
||||
else:
|
||||
|
Reference in New Issue
Block a user