Commit 54a54936 authored by Andreas Kempe's avatar Andreas Kempe
Browse files

Add saving of update keys to the database.

parent 22686e68
......@@ -58,3 +58,13 @@ class DB():
'LEFT OUTER JOIN update_key ON subdomain.id = update_key.subid '
'WHERE subdomain.id = %s AND update_key.secret IS NULL', domainid)
return [item.get("id") for item in cursor.fetchall()]
def set_subdomain_keys(self, domainid, public, private):
with self.connection.cursor() as cursor:
res = cursor.execute('INSERT INTO update_key '
'(`subid`, `update_key`, `secret`) VALUES (%s, %s, %s)',
(domainid, public, private,))
if res == 1:
self.connection.commit()
return (res == 1)
......@@ -20,7 +20,7 @@ class dnssec_keygen():
row = kf.readline()
public_key, part = row.split(" ")[6:8]
self.public_key = public_key
self.private_key = public_key + part
self.private_key = (public_key + part).replace('\n', '')
os.unlink(keyfile)
privatefile = keyfile.replace("key", "private")
os.unlink(privatefile)
......
......@@ -5,10 +5,11 @@ from dnssec_keygen import dnssec_keygen
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(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)
print(public_key)
print(private_key)
if not d.set_subdomain_keys(sid, public_key, private_key):
print('Could not save keys for {}!'.format(sid))
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