summaryrefslogtreecommitdiff
path: root/tools/initlog.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/initlog.py')
-rwxr-xr-xtools/initlog.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/tools/initlog.py b/tools/initlog.py
index 11ebc2e..3ef5720 100755
--- a/tools/initlog.py
+++ b/tools/initlog.py
@@ -14,7 +14,7 @@ import yaml
import errno
from time import time
from base64 import b64encode
-from certtools import build_merkle_tree, write_file
+from certtools import build_merkle_tree, write_file, generate_tree_head_signature
from mergetools import get_sth, perm, get_logorder
def parse_args():
@@ -33,6 +33,9 @@ def parse_args():
def main():
"""
Initialise a log by creating
+ - sth file
+ - must not exist before
+ - consulting 'logorder' if it exists
- perm database if it doesn't exist
"""
args, config, localconfig = parse_args()
@@ -65,6 +68,31 @@ def main():
# Create a chains database.
chainsdb = perm(localconfig.get("dbbackend", "filedb"), mergedb + "/chains")
+ # Create sth file.
+ tree_size = 0
+ root_hash = build_merkle_tree('')[-1][0]
+ try:
+ logorder = get_logorder(logorderfile)
+ tree_size = len(logorder)
+ root_hash = build_merkle_tree(logorder[:tree_size])[-1][0]
+ except IOError, e:
+ if e.errno == errno.ENOENT:
+ pass
+ timestamp = int(time() * 1000)
+ tree_head_signature = \
+ generate_tree_head_signature(signingnodes, own_key,
+ tree_size, timestamp, root_hash)
+ if tree_head_signature == None:
+ return 1
+
+ sth = {"tree_size": tree_size,
+ "timestamp": timestamp,
+ "sha256_root_hash": b64encode(root_hash),
+ "tree_head_signature": b64encode(tree_head_signature)}
+ print "Creating sth file with tree size", tree_size, \
+ "and timestamp", timestamp
+ write_file(sthfile, sth)
+
return 0
if __name__ == '__main__':