aboutsummaryrefslogtreecommitdiff
path: root/scripts/rpki/https.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2007-10-04 04:07:37 +0000
committerRob Austein <sra@hactrn.net>2007-10-04 04:07:37 +0000
commit5dd67f0e3c36d440c985879530c41e054e7d14ed (patch)
treec2cc9e61930223787cfe4cbc23dd05b97bbd98b5 /scripts/rpki/https.py
parent2ae55cb29667344e43ef58737680421d06d90e65 (diff)
URL handling
svn path=/scripts/http-client.py; revision=1089
Diffstat (limited to 'scripts/rpki/https.py')
-rw-r--r--scripts/rpki/https.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/scripts/rpki/https.py b/scripts/rpki/https.py
index 18a3c738..aa91d26a 100644
--- a/scripts/rpki/https.py
+++ b/scripts/rpki/https.py
@@ -7,11 +7,12 @@ subversion repository; generalizing it would not be hard, but the more
general version should use SQL anyway.
"""
-import httplib, BaseHTTPServer, tlslite.api, glob, rpki.x509, traceback, rpki.exceptions
+import httplib, BaseHTTPServer, tlslite.api, glob, traceback, urlparse
+import rpki.x509, rpki.exceptions
rpki_content_type = "application/x-rpki"
-def client(msg, privateKey, certChain, x509TrustList, host="localhost", port=4433, url="/"):
+def client(msg, privateKey, certChain, x509TrustList, url):
"""Open client HTTPS connection, send a message, wait for response.
This function wraps most of what one needs to do to send a message
@@ -20,13 +21,22 @@ def client(msg, privateKey, certChain, x509TrustList, host="localhost", port=443
but doesn't appear to handle subjectAltName extensions (sigh).
"""
- httpc = tlslite.api.HTTPTLSConnection(host=host,
- port=port,
- privateKey=privateKey.get_tlslite(),
- certChain=certChain.tlslite_certChain(),
- x509TrustList=x509TrustList.tlslite_trustList())
+ u = urlparse.urlparse(url)
+
+ assert u.scheme in ("", "https") and \
+ u.username is None and \
+ u.password is None and \
+ u.params == "" and \
+ u.query == "" and \
+ u.fragment == ""
+
+ httpc = tlslite.api.HTTPTLSConnection(host = u.hostname or "localhost",
+ port = u.port or 443,
+ privateKey = privateKey.get_tlslite(),
+ certChain = certChain.tlslite_certChain(),
+ x509TrustList = x509TrustList.tlslite_trustList())
httpc.connect()
- httpc.request("POST", url, msg, {"Content-Type" : rpki_content_type})
+ httpc.request("POST", u.path, msg, {"Content-Type" : rpki_content_type})
response = httpc.getresponse()
if response.status == httplib.OK:
return response.read()