From: Christoph Egger Date: Fri, 8 Jan 2016 16:24:32 +0000 (+0100) Subject: Actually output zonefilesnippets X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=35b58fd107ce76a42ec6e393621abc9e5f426d90;p=tools.git Actually output zonefilesnippets --- diff --git a/make-tlsa b/make-tlsa index bdc9e46..9625f8d 100755 --- a/make-tlsa +++ b/make-tlsa @@ -8,15 +8,31 @@ import os import subprocess def main(): + records = dict() for root, _, files in os.walk(sys.argv[1]): for filename in files: if filename == 'cert.pem': certname = os.path.join(root, filename) altnames = parse_cert(certname) for altname in altnames: - subprocess.Popen(["ldns-dane", "create", "-c", certname, - altname, "443", "3", "1", "1"]) - + nameparts = altname.split('.') + zone = '.'.join(nameparts[-2:]) + domain = '.'.join(nameparts[:-2]) + if domain == "": + continue + + ldns = subprocess.Popen(["ldns-dane", "create", "-c", certname, + altname, "443", "3", "1", "1"], + stdout=subprocess.PIPE) + data = ldns.stdout.read().decode().strip().split('\t') + record = "{0:<35s}\t{1}".format(data[0], '\t'.join(data[2:])) + if not zone in records: + records[zone] = [] + records[zone].append(record) + + for zone, data in records.items(): + with open(os.path.join("output", zone), "w") as zonefile: + zonefile.write('\n'.join(data)) def parse_cert(fname):