diff options
-rw-r--r-- | Makefile | 3 | ||||
-rwxr-xr-x | tools/sendsth.py | 58 |
2 files changed, 61 insertions, 0 deletions
@@ -79,6 +79,9 @@ tests-run: @diff -r -x nursery -x verifiedsize catlfish/tests/mergedb catlfish/tests/mergedb-secondary || (echo "Merge databases not matching" ; false) @(cd $(INSTDIR) && python ../tools/check-sth.py --publickey=tests/keys/logkey.pem --cafile tests/httpsca/demoCA/cacert.pem https://localhost:8080/) || (echo "Check failed" ; false) @(cd $(INSTDIR) && python ../tools/fetchallcerts.py $(BASEURL) --publickey=tests/keys/logkey.pem --cafile tests/httpsca/demoCA/cacert.pem) || (echo "Verification failed" ; false) + @(cd $(INSTDIR) && mv tests/machine/machine-1/db/sth tests/machine/machine-1/db/sth-foo) + @(cd $(INSTDIR) && python ../tools/sendsth.py --sthfile=tests/machine/machine-1/db/sth-foo --config ../test/catlfish-test.cfg --localconfig ../test/catlfish-test-local-merge.cfg --frontendnode frontend-1) || (echo "Send STH failed" ; false) + @(cd $(INSTDIR) && python ../tools/fetchallcerts.py $(BASEURL) --publickey=tests/keys/logkey.pem --cafile tests/httpsca/demoCA/cacert.pem) || (echo "Verification failed" ; false) @(cd $(INSTDIR) && rm -f submittedcerts) @(cd $(INSTDIR) && python ../tools/storagegc.py --config ../test/catlfish-test.cfg --localconfig ../test/catlfish-test-local-1.cfg) || (echo "GC failed" ; false) @(cd $(INSTDIR) && python ../tools/submitcert.py --parallel=1 --store ../tools/testcerts/cert1.txt --check-sct --sct-file=submittedcerts $(BASEURL) --publickey=tests/keys/logkey.pem --cafile tests/httpsca/demoCA/cacert.pem) || (echo "Submission failed" ; false) diff --git a/tools/sendsth.py b/tools/sendsth.py new file mode 100755 index 0000000..8583bd7 --- /dev/null +++ b/tools/sendsth.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2014, NORDUnet A/S. +# See LICENSE for licensing information. + +import argparse +import json +import urllib2 +import sys +import yaml +from certtools import http_request, create_ssl_context + +parser = argparse.ArgumentParser(description="") +parser.add_argument('--config', help="System configuration", required=True) +parser.add_argument('--localconfig', help="Local configuration", required=True) +parser.add_argument('--frontendnode', help="Destination node", required=True) +parser.add_argument('--sthfile', help="File containing STH", required=True) +args = parser.parse_args() + +config = yaml.load(open(args.config)) +localconfig = yaml.load(open(args.localconfig)) + +frontendnodes = config["frontendnodes"] +frontendnode = [node for node in frontendnodes if node["name"] == args.frontendnode][0] +paths = localconfig["paths"] + +create_ssl_context(cafile=paths["https_cacertfile"]) + +own_key = (localconfig["nodename"], "%s/%s-private.pem" % (paths["privatekeys"], localconfig["nodename"])) + +hashed_dir = True + +def sendsth(node, baseurl, submission): + try: + result = http_request(baseurl + "plop/v1/frontend/sendsth", + json.dumps(submission), key=own_key, verifynode=node, publickeydir=paths["publickeys"]) + return json.loads(result) + except urllib2.HTTPError, e: + print >>sys.stderr, "ERROR: sendsth", e.read() + sys.exit(1) + except ValueError, e: + print >>sys.stderr, "==== FAILED REQUEST ====" + print >>sys.stderr, submission + print >>sys.stderr, "======= RESPONSE =======" + print >>sys.stderr, result + print >>sys.stderr, "========================" + sys.stderr.flush() + raise e + +sth = json.load(open(args.sthfile)) + +nodeaddress = "https://%s/" % frontendnode["address"] +nodename = frontendnode["name"] +sendsthresult = sendsth(nodename, nodeaddress, sth) +if sendsthresult["result"] != "ok": + print >>sys.stderr, "send sth:", sendsthresult + sys.exit(1) |