summaryrefslogtreecommitdiff
path: root/tools/certtools.py
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2015-03-03 14:03:05 +0100
committerMagnus Ahltorp <map@kth.se>2015-03-03 14:03:05 +0100
commit4e1bcab3f91f975a19710a4350bbee0e9af5168e (patch)
treea67ee6399504554fb601f9b664ad127ec01aac7f /tools/certtools.py
parent06987aac6ea50e40915a59c0d3d52c84ae7e5498 (diff)
Move http_request to certtools
Diffstat (limited to 'tools/certtools.py')
-rw-r--r--tools/certtools.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/certtools.py b/tools/certtools.py
index 2fb1492..ad90e5c 100644
--- a/tools/certtools.py
+++ b/tools/certtools.py
@@ -6,6 +6,7 @@ import json
import base64
import urllib
import urllib2
+import urlparse
import struct
import sys
import hashlib
@@ -182,6 +183,23 @@ def check_signature(baseurl, signature, data):
vk.verify(unpacked_signature, data, hashfunc=hashlib.sha256,
sigdecode=ecdsa.util.sigdecode_der)
+def http_request(url, data=None, key=None):
+ req = urllib2.Request(url, data)
+ (keyname, keyfile) = key
+ privatekey = get_eckey_from_file(keyfile)
+ sk = ecdsa.SigningKey.from_der(privatekey)
+ parsed_url = urlparse.urlparse(url)
+ if data == None:
+ data = parsed_url.query
+ method = "GET"
+ else:
+ method = "POST"
+ signature = sk.sign("%s\0%s\0%s" % (method, parsed_url.path, data), hashfunc=hashlib.sha256,
+ sigencode=ecdsa.util.sigencode_der)
+ req.add_header('X-Catlfish-Auth', base64.b64encode(signature) + ";key=" + keyname)
+ result = urllib2.urlopen(req).read()
+ return result
+
def create_signature(privatekey, data):
sk = ecdsa.SigningKey.from_der(privatekey)
unpacked_signature = sk.sign(data, hashfunc=hashlib.sha256,