summaryrefslogtreecommitdiff
path: root/tools/certtools.py
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2014-09-24 01:14:19 +0200
committerLinus Nordberg <linus@nordberg.se>2014-09-24 13:18:18 +0200
commitd0c0ab627445f1dcb8eb3dcdb7c6bda3809a088d (patch)
treeaa485dd9fa84857cb8bd56e6e46976492f70910e /tools/certtools.py
parent8904fb9e379aacfff6adcd3001aad3427b9a5fe7 (diff)
submitcert.py: Get submitted entry from log and compare
Diffstat (limited to 'tools/certtools.py')
-rw-r--r--tools/certtools.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/tools/certtools.py b/tools/certtools.py
index fa7f6ac..48e7b41 100644
--- a/tools/certtools.py
+++ b/tools/certtools.py
@@ -63,7 +63,7 @@ def get_proof_by_hash(baseurl, hash, tree_size):
print params
result = \
urllib2.urlopen(baseurl + "ct/v1/get-proof-by-hash?" + params).read()
- return result
+ return json.loads(result)
except urllib2.HTTPError, e:
print e.read()
sys.exit(1)
@@ -72,6 +72,15 @@ def tls_array(data, length_len):
length_bytes = struct.pack(">Q", len(data))[-length_len:]
return length_bytes + data
+def unpack_tls_array(packed_data, length_len):
+ padded_length = ["\x00"] * 8
+ padded_length[-length_len:] = packed_data[:length_len]
+ (length,) = struct.unpack(">Q", "".join(padded_length))
+ unpacked_data = packed_data[length_len:length_len+length]
+ assert len(unpacked_data) == length
+ rest_data = packed_data[length_len+length:]
+ return (unpacked_data, rest_data)
+
def add_chain(baseurl, submission):
try:
return json.loads(urllib2.urlopen(baseurl + "ct/v1/add-chain",
@@ -79,3 +88,22 @@ def add_chain(baseurl, submission):
except urllib2.HTTPError, e:
print e.read()
sys.exit(1)
+
+def get_entries(baseurl, start, end):
+ try:
+ params = urllib.urlencode({"start":start, "end":end})
+ result = urllib2.urlopen(baseurl + "ct/v1/get-entries?" + params).read()
+ return json.loads(result)
+ except urllib2.HTTPError, e:
+ print e.read()
+ sys.exit(1)
+
+def decode_certificate_chain(packed_certchain):
+ (unpacked_certchain, rest) = unpack_tls_array(packed_certchain, 3)
+ assert len(rest) == 0
+ certs = []
+ while len(unpacked_certchain):
+ (cert, rest) = unpack_tls_array(unpacked_certchain, 3)
+ certs.append(cert)
+ unpacked_certchain = rest
+ return certs