Commit cd259541 authored by aoh's avatar aoh
Browse files

Move generate_keys.py to generator.py


Signed-off-by: aoh's avataraoh <aoh@lysator.liu.se>
parent 5a3c2113
#!/usr/bin/env python3
from db import DB
from dnssec_keygen import dnssec_keygen
def application(env, start_response):
with DB() as d:
for id in d.get_domain_ids():
domain_name = d.get_domain_name(id)
for sid in d.get_subdomain_ids_without_keys(id):
subdomain_name = d.get_subdomain_name(sid)
fqdn = subdomain_name + '.' + domain_name
with dnssec_keygen() as dk:
print('Generating keys for {}'.format(sid))
public_key, private_key = dk.create_keys(fqdn)
if not d.set_subdomain_keys(sid, public_key, private_key):
print('Could not save keys for {}!'.format(sid))
start_response('200 OK', [('Content-Type', 'text/html')])
return [b""]
......@@ -3,6 +3,7 @@ from jinja2 import FileSystemLoader, Environment
from db import DB
from socket import gethostbyname
from dns.resolver import Resolver
from dnssec_keygen import dnssec_keygen
# Represents the client key for updating a DNS record.
class Key:
......@@ -60,6 +61,18 @@ def lookup(fully_qualified_domain_name):
def application(env, start_response):
env = Environment(loader = FileSystemLoader('.'))
# Generate keys
with DB() as d:
for id in d.get_domain_ids():
domain_name = d.get_domain_name(id)
for sid in d.get_subdomain_ids_without_keys(id):
subdomain_name = d.get_subdomain_name(sid)
fqdn = subdomain_name + '.' + domain_name
with dnssec_keygen() as dk:
public_key, private_key = dk.create_keys(fqdn)
if not d.set_subdomain_keys(sid, public_key, private_key):
print('Could not save keys for {}!'.format(sid))
# Keys
# XXX This file should be included from named.conf
with open("/usr/local/etc/namedb/keys", "w") as keys_file, DB() as d:
......
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