From b7b8903b6a7c3342933b9984afa72fb6527b5f72 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Tue, 24 Jan 2017 09:16:28 +0100 Subject: Parallelised merge, distribution phase. --- tools/initlog.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 tools/initlog.py (limited to 'tools/initlog.py') diff --git a/tools/initlog.py b/tools/initlog.py new file mode 100755 index 0000000..11ebc2e --- /dev/null +++ b/tools/initlog.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2017, NORDUnet A/S. +# See LICENSE for licensing information. +# +# Initialise a new CT log. +# + +import sys +import os +import argparse +import yaml +import errno +from time import time +from base64 import b64encode +from certtools import build_merkle_tree, write_file +from mergetools import get_sth, perm, get_logorder + +def parse_args(): + parser = argparse.ArgumentParser(description="") + parser.add_argument('--config', help="System configuration", + required=True) + parser.add_argument('--localconfig', help="Local configuration", + required=True) + + args = parser.parse_args() + config = yaml.load(open(args.config)) + localconfig = yaml.load(open(args.localconfig)) + + return (args, config, localconfig) + +def main(): + """ + Initialise a log by creating + - perm database if it doesn't exist + """ + args, config, localconfig = parse_args() + signingnodes = config["signingnodes"] + paths = localconfig["paths"] + own_key = (localconfig["nodename"], + "%s/%s-private.pem" % (paths["privatekeys"], + localconfig["nodename"])) + mergedb = paths["mergedb"] + logorderfile = mergedb + "/logorder" + sthfile = mergedb + "/sth" + + # Don't do anything if there's already an sth file. + sth = get_sth(sthfile) + if sth['tree_size'] >= 0: + print >>sys.stderr, \ + "This log has an STH file with tree size %s." % sth['tree_size'] + print >>sys.stderr, "I refuse to destroy this log." + return 1 + + # Ensure that we can find our keyfile. + try: + os.stat(own_key[1]) + except OSError, e: + if e.errno == errno.ENOENT: + print >>sys.stderr, "Unable to open keyfile: %s" % own_key[1] + return 1 + raise + + # Create a chains database. + chainsdb = perm(localconfig.get("dbbackend", "filedb"), mergedb + "/chains") + + return 0 + +if __name__ == '__main__': + sys.exit(main()) -- cgit v1.1