summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2015-08-24 22:17:57 +0200
committerMagnus Ahltorp <map@kth.se>2015-08-24 22:17:57 +0200
commit1f9ef5eea31658dfbea1aee1a713cf8f6a3084ae (patch)
tree7032dc6a62ac2cbf7d1322f96c55a4f0d8ef0629 /tools
parent74dd0360bda561bdd88ec85d9bb07398bf404261 (diff)
Added utility sendsth and testssendsth
Diffstat (limited to 'tools')
-rwxr-xr-xtools/sendsth.py58
1 files changed, 58 insertions, 0 deletions
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)