summaryrefslogtreecommitdiff
path: root/tools/certtools.py
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2015-04-10 15:42:03 +0200
committerMagnus Ahltorp <map@kth.se>2015-04-10 15:44:26 +0200
commit6402eeefc18c47b7dceea5e0dda0b8aeec6719bd (patch)
tree56b0e91fabdc01c17fe37a44f77b707060171a30 /tools/certtools.py
parent263862c06abd93d39d98fd40007f80b5fe57f030 (diff)
Verify SSL certificates and hostnames in python codesslverify
Closes CATLFISH-34
Diffstat (limited to 'tools/certtools.py')
-rw-r--r--tools/certtools.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/tools/certtools.py b/tools/certtools.py
index 498a2e0..405aabd 100644
--- a/tools/certtools.py
+++ b/tools/certtools.py
@@ -88,12 +88,24 @@ def get_root_cert(issuer):
return root_cert
-def urlopen(url, data=None):
+class sslparameters:
+ sslcontext = None
+
+def create_ssl_context(cafile=None):
try:
- opener = urllib2.build_opener(urllib2.HTTPSHandler(context=ssl.SSLContext(ssl.PROTOCOL_TLSv1)))
+ sslparameters.sslcontext = ssl.create_default_context(cafile=cafile)
except AttributeError:
+ sslparameters.sslcontext = None
+
+def get_opener():
+ try:
+ opener = urllib2.build_opener(urllib2.HTTPSHandler(context=sslparameters.sslcontext))
+ except TypeError:
opener = urllib2.build_opener(urllib2.HTTPSHandler())
- return opener.open(url, data)
+ return opener
+
+def urlopen(url, data=None):
+ return get_opener().open(url, data)
def get_sth(baseurl):
result = urlopen(baseurl + "ct/v1/get-sth").read()
@@ -238,10 +250,7 @@ def check_auth_header(authheader, expected_key, publickeydir, data, path):
return True
def http_request(url, data=None, key=None, verifynode=None, publickeydir="."):
- try:
- opener = urllib2.build_opener(urllib2.HTTPSHandler(context=ssl.SSLContext(ssl.PROTOCOL_TLSv1)))
- except AttributeError:
- opener = urllib2.build_opener(urllib2.HTTPSHandler())
+ opener = get_opener()
(keyname, keyfile) = key
privatekey = get_eckey_from_file(keyfile)