Displays DNSSEC algorithms as text in text, zone and HTML outputs. Closes #9

master
Stephane Bortzmeyer 3 years ago
parent 4a9e6fc082
commit 25b19299cf
  1. 25
      DNSLG/Formatter.py
  2. 6
      test_service.py

@ -135,7 +135,14 @@ class TextFormatter(Formatter):
# key_id appeared only in dnspython 1.9. Not
# always available on 2012-05-17
pass
self.output += "algorithm %i, length %i bits, flags %i\n" % (rdata.algorithm, keylength(rdata.algorithm, rdata.key), rdata.flags)
algo_text = dns.dnssec.algorithm_to_text(rdata.algorithm)
if algo_text == "%i" % rdata.algorithm:
algo_text = "Unknown algorithm"
flags_text = dns.rdtypes.dnskeybase.flags_to_text_set(rdata.flags)
self.output += "algorithm %i (%s), length %i bits, flags %i (%s)\n" % \
(rdata.algorithm, algo_text,
keylength(rdata.algorithm, rdata.key),
rdata.flags, flags_text)
elif rdata.rdtype == dns.rdatatype.NSEC3PARAM:
self.output += "NSEC3PARAM: algorithm %i, iterations %i, salt %s\n" % (rdata.algorithm, rdata.iterations, to_hexstring(rdata.salt))
elif rdata.rdtype == dns.rdatatype.SSHFP:
@ -225,11 +232,15 @@ class ZoneFormatter(Formatter):
self.output += "DNSKEY\t%s" % rdata.to_text()
try:
key_tag = dns.dnssec.key_id(rdata)
self.output += "; key ID = %i\n" % key_tag
self.output += " ; key ID = %i" % key_tag
except AttributeError:
# key_id appeared only in dnspython 1.9. Not
# always available on 2012-05-17
self.output += "\n"
pass
algo_text = dns.dnssec.algorithm_to_text(rdata.algorithm)
if algo_text != "%i" % rdata.algorithm:
self.output += " ; Algorithm %s" % algo_text
self.output += "\n"
elif rdata.rdtype == dns.rdatatype.NSEC3PARAM:
self.output += "NSEC3PARAM\t%s\n" % rdata.to_text()
elif rdata.rdtype == dns.rdatatype.DS:
@ -1056,11 +1067,13 @@ class HtmlFormatter(Formatter):
suppressXMLDeclaration=True,
outputEncoding=querier.encoding)
elif rdata.rdtype == dns.rdatatype.DNSKEY:
# TODO replace the algorithm number by a nice string http://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml#dns-sec-alg-numbers-1
icontext.addGlobal ("algorithm", rdata.algorithm)
algo_text = dns.dnssec.algorithm_to_text(rdata.algorithm)
if algo_text == "%i" % rdata.algorithm:
algo_text = "Unknown algorithm"
icontext.addGlobal ("algorithm", "%s (%s)" % (rdata.algorithm, algo_text))
icontext.addGlobal ("length", keylength(rdata.algorithm, rdata.key))
icontext.addGlobal ("protocol", rdata.protocol)
icontext.addGlobal ("flags", rdata.flags)
icontext.addGlobal ("flags", "%i %s" % (rdata.flags, dns.rdtypes.dnskeybase.flags_to_text_set(rdata.flags)))
try:
key_tag = dns.dnssec.key_id(rdata)
icontext.addGlobal ("keytag", key_tag)

@ -93,9 +93,9 @@ def test_dnskey(prefix):
for format in formats:
r = requests.get(prefix + 'paypal.com/DNSKEY%s' % fstring(format))
assert r.status_code == 200 and r.headers['content-type'] == formats[format] and \
'paypal.com' in r.text, 'format is %s' % format # Unfortunately,
# no text in the DNSKEY output, is available for all
# formats. Use one test per format, as in test_dnssec?
((format == 'JSON' and '"Algorithm": 5' in r.text) or
(format == 'XML' and 'algorithm="5"' in r.text) or
('RSASHA1' in r.text)), 'format is %s' % format
def test_loc(prefix):
for format in formats:

Loading…
Cancel
Save