Commit d97dd19f authored by aoh's avatar aoh
Browse files

Add dnssec_keygen.py module



Update generate_key_example.py as well which explains how to use the
dnssec_keygen.py module.
Signed-off-by: aoh's avataraoh <aoh@lysator.liu.se>
parent d0d2e98c
#!/bin/bash
echo "K$9.+157+20416"
import subprocess
import os
class dnssec_keygen():
def __init__(self):
pass
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
pass
def create_keys(self, fqdn):
command = 'dnssec-keygen -r /dev/urandom -a HMAC-MD5 -b 512 -K /tmp/ -n HOST'
args = command.split(' ')
args += [fqdn]
with subprocess.Popen(args, stdout=subprocess.PIPE) as proc:
keyfile = "{}.key".format(proc.stdout.read().decode('utf-8'))
keyfile = keyfile.replace("\n", "")
keyfile = "/tmp/" + keyfile
with open(keyfile, "r") as kf:
row = kf.readline()
public_key, part = row.split(" ")[6:8]
self.public_key = public_key
self.private_key = public_key + part
os.unlink(keyfile)
privatefile = keyfile.replace("key", "private")
os.unlink(privatefile)
return self.public_key, self.private_key
#!/usr/bin/env python3
from db import DB
import subprocess
from dnssec_keygen import dnssec_keygen
with DB() as d:
for id in d.get_domain_ids():
......@@ -8,18 +8,7 @@ with DB() as d:
for sid in d.get_subdomain_ids(id):
subdomain_name = d.get_subdomain_name(sid)
fqdn = subdomain_name + '.' + domain_name
# TODO remove "./" from dnssec-keygen
command = './dnssec-keygen -r /dev/urandom -a HMAC-MD5 -b 512 -n HOST' # TODO add -K <dirname>
args = command.split(' ')
args += [fqdn]
with subprocess.Popen(args, stdout=subprocess.PIPE) as proc:
filename = "{}.key".format(proc.stdout.read().decode('utf-8'))
filename = filename.replace("\n", "")
# TODO read file from correct dir
with open(filename, "r") as keyfile:
row = keyfile.readline()
# TODO not sure about the syntax of the keyfile, this is just a guess..
public_key, part = row.split(" ")[6:8]
private_key = public_key + part
print(public_key)
print(private_key)
with dnssec_keygen() as dk:
public_key, private_key = dk.create_keys(fqdn)
print(public_key)
print(private_key)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment