summaryrefslogtreecommitdiff
path: root/tools/mergetools.py
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2015-04-23 23:24:11 +0200
committerLinus Nordberg <linus@nordberg.se>2015-04-23 23:24:11 +0200
commitcbb556663d8706138efb85a4e011c9fca349d33e (patch)
tree323328f3e5a01d3ccdc07a7921239ad8d0bcfbfe /tools/mergetools.py
parent5e93578d1f0f1908f70c0e77ed643e0b30cc3028 (diff)
parentf1630b6eb3dd525448aac8d722ccb9f8098e8593 (diff)
Merge branch 'mergesecondary'
Diffstat (limited to 'tools/mergetools.py')
-rw-r--r--tools/mergetools.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/mergetools.py b/tools/mergetools.py
new file mode 100644
index 0000000..5cb36c4
--- /dev/null
+++ b/tools/mergetools.py
@@ -0,0 +1,57 @@
+# Copyright (c) 2015, 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)