diff options
author | Magnus Ahltorp <map@kth.se> | 2015-04-23 16:32:21 +0200 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2015-04-23 16:34:07 +0200 |
commit | 2bd043cb386e3b0fcab28ca2b27e9be21450a72c (patch) | |
tree | 7d37ae3b9c03e9e65b59e665fdfe36bad767c2f4 /tools/mergetools.py | |
parent | 8fce884a61fb2ecb626f6df41e214d3dfdbe91fd (diff) |
Add support for merge secondaries
Diffstat (limited to 'tools/mergetools.py')
-rw-r--r-- | tools/mergetools.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/mergetools.py b/tools/mergetools.py new file mode 100644 index 0000000..c25214c --- /dev/null +++ b/tools/mergetools.py @@ -0,0 +1,57 @@ +# Copyright (c) 2014, NORDUnet A/S. +# See LICENSE for licensing information. +import base64 +import sys +import struct +from certtools import get_leaf_hash + +def parselogrow(row): + return base64.b16decode(row) + +def get_logorder(filename): + f = open(filename, "r") + return [parselogrow(row.rstrip()) for row in f] + +def read_chain(chainsdir, key): + filename = base64.b16encode(key) + path = chainsdir + "/" + filename[0:2] + "/" + filename[2:4] + "/" + filename[4:6] + try: + f = open(path + "/" + filename, "r") + except IOError, e: + f = open(chainsdir + "/" + filename, "r") + value = f.read() + f.close() + return value + +def unpack_entry(entry): + pieces = [] + while len(entry): + (length,) = struct.unpack(">I", entry[0:4]) + data = entry[4:4+length] + entry = entry[4+length:] + pieces.append(data) + return pieces + +def verify_entry(verifycert, entry, hash): + unpacked = unpack_entry(entry) + mtl = unpacked[0] + assert hash == get_leaf_hash(mtl) + s = struct.pack(">I", len(entry)) + entry + try: + verifycert.stdin.write(s) + except IOError, e: + sys.stderr.write("merge: unable to write to verifycert process: ") + while 1: + line = verifycert.stdout.readline() + if line: + sys.stderr.write(line) + else: + sys.exit(1) + result_length_packed = verifycert.stdout.read(4) + (result_length,) = struct.unpack(">I", result_length_packed) + result = verifycert.stdout.read(result_length) + assert len(result) == result_length + (error_code,) = struct.unpack("B", result[0:1]) + if error_code != 0: + print >>sys.stderr, result[1:] + sys.exit(1) |