summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2016-11-22 15:57:55 +0100
committerMagnus Ahltorp <map@kth.se>2016-11-22 15:57:55 +0100
commitccfe7c55a5d1658c0f98aac2c45e76444dcd0bc2 (patch)
tree61909de054a29b062a3aef77d440c5c85e163696
parente2ee49ed76b9d25bd3d395965817f50fe77325d2 (diff)
Add session capability to unauth web requests
-rw-r--r--tools/certtools.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/tools/certtools.py b/tools/certtools.py
index 1523c97..0009d5d 100644
--- a/tools/certtools.py
+++ b/tools/certtools.py
@@ -108,13 +108,16 @@ def urlget(url, params=None):
pass
return requests.get(url, verify=sslparameters.cafile, params=params)
-def urlpost(url, data):
+def urlpost(url, data, session=None):
with warnings.catch_warnings():
try:
warnings.filterwarnings("ignore", category=requests.packages.urllib3.exceptions.SubjectAltNameWarning)
except AttributeError:
pass
- return requests.post(url, data=data, verify=sslparameters.cafile)
+ if session:
+ return session.post(url, data=data, verify=sslparameters.cafile)
+ else:
+ return requests.post(url, data=data, verify=sslparameters.cafile)
def get_sth(baseurl):
result = urlget(baseurl + "ct/v1/get-sth")
@@ -157,9 +160,9 @@ def unpack_tls_array(packed_data, length_len):
rest_data = packed_data[length_len+length:]
return (unpacked_data, rest_data)
-def add_chain(baseurl, submission):
+def add_chain(baseurl, submission, session=None):
try:
- result = urlpost(baseurl + "ct/v1/add-chain", json.dumps(submission))
+ result = urlpost(baseurl + "ct/v1/add-chain", json.dumps(submission), session=session)
if result.status_code == requests.codes.ok:
return result.json()
else:
@@ -175,10 +178,10 @@ def add_chain(baseurl, submission):
print "========================"
raise e
-def add_prechain(baseurl, submission):
+def add_prechain(baseurl, submission, session=None):
try:
result = urlpost(baseurl + "ct/v1/add-pre-chain",
- json.dumps(submission))
+ json.dumps(submission), session=session)
if result.status_code == requests.codes.ok:
return result.json()