f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt############################################################################
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# Permission to use, copy, modify, and/or distribute this software for any
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# purpose with or without fee is hereby granted, provided that the above
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# copyright notice and this permission notice appear in all copies.
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# PERFORMANCE OF THIS SOFTWARE.
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt############################################################################
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# This translates the Keys section of a KASP XML file into a dnssec.policy
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# file that can be used by dnssec-keymgr.
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt############################################################################
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt############################################################################
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# Translate KASP duration values into seconds
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt############################################################################
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt tokens = ( 'P', 'T', 'Y', 'M', 'D', 'H', 'S', 'NUM' )
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt self.parser = yacc.yacc(debug=False, write_tables=False, module=self)
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt "ktime : P periods T times"
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt "ktime : P T times"
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt "ktime : P periods"
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt "periods : period"
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt "periods : periods period"
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt "times : time"
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt "times : times time"
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt '''period : NUM Y
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt '''time : NUM H
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt print("Syntax error")
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt############################################################################
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# Load the contents of a KASP XML file as a python dictionary
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt############################################################################
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt {k:v[0] if len(v) == 1 else v for k, v in dd.iteritems()}}
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt d[t.tag].update(('@' + k, v) for k, v in t.attrib.iteritems())
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt self._dict = kasp._todict(ET.parse(filename).getroot())
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt############################################################################
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt# Load the contents of a KASP XML file as a python dictionary
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt############################################################################
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt from pprint import *
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt print("Usage: kasp2policy <filename>")
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt print("%s: unable to load KASP file '%s'" % (sys.argv[0], sys.argv[1]))
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt if p['Description']:
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt print("\talgorithm %s;" % dnskey.algstr(int(algnum)))
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt print("\tkeyttl %d;" % kt.parse(p['Keys']['TTL']))
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt print("\tkey-size ksk %d;" % int(kalg['@length']))
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt print("\tkey-size zsk %d;" % int(zalg['@length']))
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt print("\troll-period ksk %d;" % kt.parse(ksk['Lifetime']))
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt print("\troll-period zsk %d;" % kt.parse(zsk['Lifetime']))