diff options
author | Magnus Ahltorp <map@kth.se> | 2015-03-16 10:06:42 +0100 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2015-03-16 10:06:42 +0100 |
commit | 4c72a1d2cecbb427a240e868277b7e039008c43e (patch) | |
tree | b33f83b8373196970cd95b5b9c764ec57d031d3c /tools/certtools.py | |
parent | e2404caabb5ce3f7dca21cdedddbf744f47e6c3e (diff) |
Add submission of precerts
Diffstat (limited to 'tools/certtools.py')
-rw-r--r-- | tools/certtools.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/certtools.py b/tools/certtools.py index 222497f..c6f6ee6 100644 --- a/tools/certtools.py +++ b/tools/certtools.py @@ -60,6 +60,10 @@ def get_certs_from_string(s): f = cStringIO.StringIO(s) return get_pemlike_from_file(f, "CERTIFICATE") +def get_precerts_from_string(s): + f = cStringIO.StringIO(s) + return get_pemlike_from_file(f, "PRECERTIFICATE") + def get_eckey_from_file(keyfile): keys = get_pemlike(keyfile, "EC PRIVATE KEY") assert len(keys) == 1 @@ -137,6 +141,24 @@ def add_chain(baseurl, submission): print "========================" raise e +def add_prechain(baseurl, submission): + try: + result = urllib2.urlopen(baseurl + "ct/v1/add-pre-chain", + json.dumps(submission)).read() + return json.loads(result) + except urllib2.HTTPError, e: + print "ERROR", e.code,":", e.read() + if e.code == 400: + return None + sys.exit(1) + except ValueError, e: + print "==== FAILED REQUEST ====" + print submission + print "======= RESPONSE =======" + print result + print "========================" + raise e + def get_entries(baseurl, start, end): try: params = urllib.urlencode({"start":start, "end":end}) @@ -586,5 +608,6 @@ def verify_consistency_proof(consistency_proof, first, second, oldhash_input): def verify_inclusion_proof(inclusion_proof, index, treesize, leafhash): chain = zip([(index, 0)] + nodes_for_index(index, treesize), [leafhash] + inclusion_proof) + assert len(nodes_for_index(index, treesize)) == len(inclusion_proof) (_, hash) = reduce(lambda e1, e2: combine_two_hashes(e1, e2, treesize), chain) return hash |