diff options
author | Rob Austein <sra@hactrn.net> | 2007-09-14 21:27:19 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2007-09-14 21:27:19 +0000 |
commit | 8ec96ec42e7f977a238a01187106635ffe87ffe4 (patch) | |
tree | 24f02e33eea50cf19978d8b350000d598b51f810 | |
parent | abe75960b1c9adcd29cfdc1ff4cb2616d178f42e (diff) |
Cleanup
svn path=/scripts/http-server.py; revision=959
-rw-r--r-- | scripts/http-server.py | 2 | ||||
-rwxr-xr-x | scripts/irdb.py | 2 | ||||
-rw-r--r-- | scripts/rpki/https.py | 25 | ||||
-rwxr-xr-x | scripts/rpkid.py | 31 |
4 files changed, 34 insertions, 26 deletions
diff --git a/scripts/http-server.py b/scripts/http-server.py index dd7ec9a2..9ae9a43d 100644 --- a/scripts/http-server.py +++ b/scripts/http-server.py @@ -13,4 +13,4 @@ certChain.load_from_PEM(cfg.multiget(section, "https-cert")) def handler(query, path): return 200, "Path: %s\nQuery: %s" % (path, query) -rpki.https.server(privateKey=privateKey, certChain=certChain, handlers={"/" : handler}) +rpki.https.server(privateKey=privateKey, certChain=certChain, handlers=handler) diff --git a/scripts/irdb.py b/scripts/irdb.py index 88229415..5894ccc6 100755 --- a/scripts/irdb.py +++ b/scripts/irdb.py @@ -92,4 +92,4 @@ privateKey = rpki.x509.RSA_Keypair(PEM_file = cfg.get(section, "https-key")) certChain = rpki.x509.X509_chain() certChain.load_from_PEM(cfg.multiget(section, "https-cert")) -rpki.https.server(privateKey=privateKey, certChain=certChain, handlers={"/" : handler}) +rpki.https.server(privateKey=privateKey, certChain=certChain, handlers=handler) diff --git a/scripts/rpki/https.py b/scripts/rpki/https.py index 1ac5ff45..3abd5bb6 100644 --- a/scripts/rpki/https.py +++ b/scripts/rpki/https.py @@ -31,7 +31,9 @@ def client(msg, privateKey, certChain, x509TrustList, host="localhost", port=443 if response.status == httplib.OK: return response.read() else: - raise RuntimeError, response.read() + r = response.read() + print "ERROR: Got:", response.status, r + raise RuntimeError, (response.status, r) class requestHandler(BaseHTTPServer.BaseHTTPRequestHandler): """Derived type to supply POST handler.""" @@ -42,16 +44,18 @@ class requestHandler(BaseHTTPServer.BaseHTTPRequestHandler): """POST handler.""" assert self.headers["Content-Type"] == rpki_content_type query_string = self.rfile.read(int(self.headers["Content-Length"])) - rcode = None - try: - handler = self.rpki_handlers[self.path] - except KeyError: - rcode, rtext = 404, "" - if rcode is None: + handler = None + for s,h in self.rpki_handlers: + if self.path.startswith(s): + handler = h + break + if handler is None: + rcode, rtext = 404, "No handler found for URL " + self.path + else: try: rcode, rtext = handler(query=query_string, path=self.path) - except: - rcode, rtext = 500, "" + except Exception, edata: + rcode, rtext = 500, "Unhandled exception %s" % edata self.send_response(rcode) self.send_header("Content-Type", rpki_content_type) self.end_headers() @@ -82,6 +86,9 @@ class httpServer(tlslite.api.TLSSocketServerMixIn, BaseHTTPServer.HTTPServer): def server(handlers, privateKey, certChain, port=4433, host=""): """Run an HTTPS server and wait (forever) for connections.""" + if not isinstance(handlers, (tuple, list)): + handlers = (("/", handlers),) + class boundRequestHandler(requestHandler): rpki_handlers = handlers diff --git a/scripts/rpkid.py b/scripts/rpkid.py index fd0ab796..473bd65e 100755 --- a/scripts/rpkid.py +++ b/scripts/rpkid.py @@ -9,14 +9,11 @@ import rpki.https, tlslite.api, rpki.config, rpki.resource_set, MySQLdb, rpki.cm def left_right_handler(query, path): try: - q_xml = rpki.cms.decode(query, cms_ta) - print q_xml - q_elt = lxml.etree.fromstring(q_xml) + q_elt = lxml.etree.fromstring(rpki.cms.decode(query, cms_ta)) rng.assertValid(q_elt) saxer = rpki.left_right.sax_handler() lxml.sax.saxify(q_elt, saxer) q_msg = saxer.result - assert instanceof(q_msg, rpki.left_right.msg) r_msg = rpki.left_right.msg() for q_pdu in q_msg: @@ -28,8 +25,8 @@ def left_right_handler(query, path): r_elt = r_msg.toXML() rng.assertValid(r_elt) - r_xml = lxml.etree.tostring(r_elt, pretty_print=True, encoding="us-ascii", xml_declaration=True) - r_cms = rpki.cms.encode(r_xml, cfg.get(section, "cms-key"), cfg.multiget(section, "cms-cert")) + r_cms = rpki.cms.encode(lxml.etree.tostring(r_elt, pretty_print=True, encoding="us-ascii", xml_declaration=True), + cms_key, cms_certs) return 200, r_cms @@ -37,9 +34,11 @@ def left_right_handler(query, path): return 500, "Unhandled exception %s" % data def up_down_handler(query, path): + print "up-down handler called" raise NotImplementedError def cronjob_handler(query, path): + print "cronjob handler called" raise NotImplementedError cfg = rpki.config.parser("re.conf") @@ -51,15 +50,17 @@ db = MySQLdb.connect(user = cfg.get(section, "sql-username"), cur = db.cursor() -cms_ta = cfg.get(section, "cms-ta") +cms_ta_irdb = cfg.get(section, "cms-ta-irdb") +cms_ta_irbe = cfg.get(section, "cms-ta-irbe") +cms_key = cfg.get(section, "cms-key") +cms_certs = cfg.multiget(section, "cms-cert") -privateKey = rpki.x509.RSA_Keypair(PEM_file = cfg.get(section, "https-key")) +https_key = rpki.x509.RSA_Keypair(PEM_file = cfg.get(section, "https-key")) +https_certs = certChain = rpki.x509.X509_chain() -certChain = rpki.x509.X509_chain() -certChain.load_from_PEM(cfg.multiget(section, "https-cert")) +https_certs.load_from_PEM(cfg.multiget(section, "https-cert")) -rpki.https.server(privateKey=privateKey, - certChain=certChain, - handlers={"/left-right" : left_right_handler, - "/up-down" : up_down_handler, - "/cronjob" : cronjob_handler }) +rpki.https.server(privateKey=https_key, certChain=https_certs, + handlers=(("/left-right", left_right_handler), + ("/up-down", up_down_handler), + ("/cronjob", cronjob_handler))) |