summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2015-01-28 13:42:06 +0100
committerMagnus Ahltorp <map@kth.se>2015-01-28 13:42:06 +0100
commit9bcbfd787e02d93c1dbe55931b262119501728b0 (patch)
treed3d56efadacec1d43243be0ab5041abfa2ab2d73
parentde464826a3d72079fe716668da1c4922e2cf3ffe (diff)
Move hardcoded merge parameters to command line
-rw-r--r--tools/certtools.py37
-rwxr-xr-xtools/merge.py28
-rwxr-xr-xtools/testcase1.py17
3 files changed, 49 insertions, 33 deletions
diff --git a/tools/certtools.py b/tools/certtools.py
index cbb4ff7..af94fb8 100644
--- a/tools/certtools.py
+++ b/tools/certtools.py
@@ -42,22 +42,31 @@ def get_cert_info(s):
result[key] = value
return result
-def get_certs_from_file(certfile):
- certs = []
- cert = ""
- incert = False
- for line in open(certfile):
+def get_pemlike(filename, marker):
+ entries = []
+ entry = ""
+ inentry = False
+
+ for line in open(filename):
line = line.strip()
- if line == "-----BEGIN CERTIFICATE-----":
- cert = ""
- incert = True
- elif line == "-----END CERTIFICATE-----":
- certs.append(base64.decodestring(cert))
- incert = False
- elif incert:
- cert += line
- return certs
+ if line == "-----BEGIN " + marker + "-----":
+ entry = ""
+ inentry = True
+ elif line == "-----END " + marker + "-----":
+ entries.append(base64.decodestring(entry))
+ inentry = False
+ elif inentry:
+ entry += line
+ return entries
+
+def get_certs_from_file(certfile):
+ return get_pemlike(certfile, "CERTIFICATE")
+
+def get_eckey_from_file(keyfile):
+ keys = get_pemlike(keyfile, "EC PRIVATE KEY")
+ assert len(keys) == 1
+ return keys[0]
def get_root_cert(issuer):
accepted_certs = \
diff --git a/tools/merge.py b/tools/merge.py
index 1cc75ef..2b83f54 100755
--- a/tools/merge.py
+++ b/tools/merge.py
@@ -4,20 +4,29 @@
# Copyright (c) 2014, NORDUnet A/S.
# See LICENSE for licensing information.
+import argparse
import json
import base64
import urllib
import urllib2
import sys
import time
-from certtools import build_merkle_tree, create_sth_signature, check_sth_signature
+from certtools import build_merkle_tree, create_sth_signature, check_sth_signature, get_eckey_from_file
-ctbaseurl = "https://127.0.0.1:8080/"
-frontendnodes = ["https://127.0.0.1:8082/"]
-storagenodes = ["https://127.0.0.1:8081/"]
+parser = argparse.ArgumentParser(description="")
+parser.add_argument("--baseurl", metavar="url", help="Base URL for CT server", required=True)
+parser.add_argument("--frontend", action="append", metavar="url", help="Base URL for frontend server", required=True)
+parser.add_argument("--storage", action="append", metavar="url", help="Base URL for storage server", required=True)
+parser.add_argument("--mergedb", metavar="dir", help="Merge database directory", required=True)
+parser.add_argument("--keyfile", metavar="keyfile", help="File containing log key", required=True)
+args = parser.parse_args()
-chainsdir = "../rel/mergedb/chains"
-logorderfile = "../rel/mergedb/logorder"
+ctbaseurl = args.baseurl
+frontendnodes = args.frontend
+storagenodes = args.storage
+
+chainsdir = args.mergedb + "/chains"
+logorderfile = args.mergedb + "/logorder"
def parselogrow(row):
return base64.b16decode(row)
@@ -165,12 +174,7 @@ tree = build_merkle_tree(logorder)
tree_size = len(logorder)
root_hash = tree[-1][0]
timestamp = int(time.time() * 1000)
-privatekey = base64.decodestring(
- "MHcCAQEEIMM/FjZ4FSzfENTTwGpTve6CP+IVr"
- "Y7p8OKV634uJI/foAoGCCqGSM49AwEHoUQDQg"
- "AE4qWq6afhBUi0OdcWUYhyJLNXTkGqQ9PMS5l"
- "qoCgkV2h1ZvpNjBH2u8UbgcOQwqDo66z6BWQJ"
- "GolozZYmNHE2kQ==")
+privatekey = get_eckey_from_file(args.keyfile)
tree_head_signature = create_sth_signature(tree_size, timestamp,
root_hash, privatekey)
diff --git a/tools/testcase1.py b/tools/testcase1.py
index 639cd69..415d475 100755
--- a/tools/testcase1.py
+++ b/tools/testcase1.py
@@ -120,16 +120,19 @@ def get_and_check_entry(timestamp, chain, leaf_index):
len(submittedcertchain),
len(submittedcertchain))
+def merge():
+ return subprocess.call(["./merge.py", "--baseurl", "https://127.0.0.1:8080/", "--frontend", "https://127.0.0.1:8082/", "--storage", "https://127.0.0.1:8081/", "--mergedb", "../rel/mergedb", "--keyfile", "../rel/test/eckey.pem"])
+
print_and_check_tree_size(0)
-mergeresult = subprocess.call(["./merge.py"])
+mergeresult = merge()
assert_equal(mergeresult, 0, "merge", quiet=True)
testgroup("cert1")
result1 = do_add_chain(cc1)
-mergeresult = subprocess.call(["./merge.py"])
+mergeresult = merge()
assert_equal(mergeresult, 0, "merge", quiet=True)
print_and_check_tree_size(1)
@@ -138,7 +141,7 @@ result2 = do_add_chain(cc1)
assert_equal(result2["timestamp"], result1["timestamp"], "timestamp")
-mergeresult = subprocess.call(["./merge.py"])
+mergeresult = merge()
assert_equal(mergeresult, 0, "merge", quiet=True)
print_and_check_tree_size(1)
@@ -152,7 +155,7 @@ testgroup("cert2")
result3 = do_add_chain(cc2)
-mergeresult = subprocess.call(["./merge.py"])
+mergeresult = merge()
assert_equal(mergeresult, 0, "merge", quiet=True)
print_and_check_tree_size(2)
@@ -164,7 +167,7 @@ testgroup("cert3")
result4 = do_add_chain(cc3)
-mergeresult = subprocess.call(["./merge.py"])
+mergeresult = merge()
assert_equal(mergeresult, 0, "merge", quiet=True)
print_and_check_tree_size(3)
@@ -177,7 +180,7 @@ testgroup("cert4")
result5 = do_add_chain(cc4)
-mergeresult = subprocess.call(["./merge.py"])
+mergeresult = merge()
assert_equal(mergeresult, 0, "merge", quiet=True)
print_and_check_tree_size(4)
@@ -191,7 +194,7 @@ testgroup("cert5")
result6 = do_add_chain(cc5)
-mergeresult = subprocess.call(["./merge.py"])
+mergeresult = merge()
assert_equal(mergeresult, 0, "merge", quiet=True)
print_and_check_tree_size(5)