diff options
Diffstat (limited to 'scripts/rpki/https.py')
-rw-r--r-- | scripts/rpki/https.py | 26 |
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() |