Display the key algorithm name in DS output

master
Stephane Bortzmeyer 3 years ago
parent 25b19299cf
commit c9cc0a4003
  1. 26
      DNSLG/Formatter.py
  2. 8
      test_service.py

@ -1,6 +1,7 @@
#!/usr/bin/env python
import dns
import dns.dnssec
import dns.version as dnspythonversion
import base64
import platform
@ -103,8 +104,15 @@ class TextFormatter(Formatter):
elif rdata.rdtype == dns.rdatatype.NS:
self.output += "Name server: %s\n" % rdata.target
elif rdata.rdtype == dns.rdatatype.DS:
self.output += "Delegation of signature: key %i, hash type %i, hash %s\n" % \
(rdata.key_tag, rdata.digest_type, to_hexstring(rdata.digest))
key_algo_text = dns.dnssec.algorithm_to_text(rdata.algorithm)
if key_algo_text != "%i" % rdata.algorithm:
key_algo_text = " (%s)" % key_algo_text
else:
key_algo_text = ""
self.output += "Delegation of signature: key %i%s, hash type %i, hash %s\n" % \
(rdata.key_tag, key_algo_text,
rdata.digest_type,
to_hexstring(rdata.digest))
elif rdata.rdtype == dns.rdatatype.DLV:
self.output += "Delegation of signature: key %i, hash type %i\n" % \
(rdata.key_tag, rdata.digest_type)
@ -244,7 +252,11 @@ class ZoneFormatter(Formatter):
elif rdata.rdtype == dns.rdatatype.NSEC3PARAM:
self.output += "NSEC3PARAM\t%s\n" % rdata.to_text()
elif rdata.rdtype == dns.rdatatype.DS:
self.output += "DS\t%s\n" % rdata.to_text()
self.output += "DS\t%s " % rdata.to_text()
algo_text = dns.dnssec.algorithm_to_text(rdata.algorithm)
if algo_text != "%i" % rdata.algorithm:
self.output += " ; Key algorithm %s" % algo_text
self.output += '\n'
elif rdata.rdtype == dns.rdatatype.DLV:
self.output += "DLV\t%s\n" % rdata.to_text()
elif rdata.rdtype == dns.rdatatype.SSHFP:
@ -795,7 +807,7 @@ nsec3param_html_template = """
<span>NSEC3 parameters: hash type <span tal:replace="algorithm"/>, <span tal:replace="iterations"/> iterations, flags <span tal:replace="flags"/></span>
"""
ds_html_template = """
<span>Secure Delegation: Key <span tal:replace="keytag"/> (hash type <span tal:replace="digesttype"/>)</span>
<span>Secure Delegation: Key <span tal:replace="keytag"/> (key algorithm <span tal:replace="keyalgo"/>, hash type <span tal:replace="digesttype"/>)</span>
"""
dlv_html_template = """
<span>Lookaside Secure Delegation: Key <span tal:replace="keytag"/> (hash type <span tal:replace="digesttype"/>)</span>
@ -1051,13 +1063,17 @@ class HtmlFormatter(Formatter):
suppressXMLDeclaration=True,
outputEncoding=querier.encoding)
elif rdata.rdtype == dns.rdatatype.DS:
icontext.addGlobal ("algorithm", rdata.algorithm)
key_algo_text = dns.dnssec.algorithm_to_text(rdata.algorithm)
if key_algo_text == "%i" % rdata.algorithm:
key_algo_text = "Unknown algorithm"
icontext.addGlobal ("keyalgo", "%s - %s" % (rdata.algorithm, key_algo_text))
icontext.addGlobal ("digesttype", rdata.digest_type)
icontext.addGlobal ("digest", rdata.digest)
icontext.addGlobal ("keytag", rdata.key_tag)
self.ds_template.expand (icontext, iresult,
suppressXMLDeclaration=True,
outputEncoding=querier.encoding)
print(iresult.getvalue())
elif rdata.rdtype == dns.rdatatype.DLV:
icontext.addGlobal ("algorithm", rdata.algorithm)
icontext.addGlobal ("digesttype", rdata.digest_type)

@ -125,6 +125,14 @@ def test_ds(prefix):
(format == 'XML' and '<RRSet type="DS"' in r.text ) or
('Secure Delegation:' in r.text)), 'format is %s' % format
def test_ds_algos(prefix):
for format in formats:
r = requests.get(prefix + 'tf/DS%s' % fstring(format))
assert r.status_code == 200 and r.headers['content-type'] == formats[format] and \
(((format == 'ZONE' or format == 'HTML' or format == '' or format == 'TXT') and 'ECDSAP256' in r.text) or
(format == 'JSON' and '"Type": "DS"' in r.text) or
(format == 'XML' and '<RRSet type="DS"' in r.text)), 'format is %s' % format
def test_nsec3param(prefix):
for format in formats:
r = requests.get(prefix + 'pm/NSEC3PARAM%s' % fstring(format))

Loading…
Cancel
Save