diff options
-rwxr-xr-x | rpkid/irbe_cli.py | 34 | ||||
-rw-r--r-- | rpkid/rpki/exceptions.py | 3 | ||||
-rw-r--r-- | rpkid/rpki/https.py | 17 | ||||
-rw-r--r-- | rpkid/rpki/left_right.py | 34 | ||||
-rw-r--r-- | rpkid/rpki/log.py | 4 | ||||
-rw-r--r-- | rpkid/rpki/up_down.py | 2 | ||||
-rw-r--r-- | rpkid/rpki/xml_utils.py | 2 | ||||
-rw-r--r-- | rpkid/testbed.3.yaml | 12 | ||||
-rw-r--r-- | rpkid/testbed.py | 4 | ||||
-rw-r--r-- | rpkid/testpoke.py | 12 |
10 files changed, 71 insertions, 53 deletions
diff --git a/rpkid/irbe_cli.py b/rpkid/irbe_cli.py index af18d591..06c6c63a 100755 --- a/rpkid/irbe_cli.py +++ b/rpkid/irbe_cli.py @@ -46,11 +46,11 @@ class cmd_elt_mixin(object): def usage(cls): """Generate usage message for this PDU.""" args = " ".join("--" + x + "=" for x in cls.attributes + cls.elements if x not in cls.excludes) - opts = " ".join("--" + x for x in cls.booleans) - if args and opts: - return args + " " + opts + bools = " ".join("--" + x for x in cls.booleans) + if args and bools: + return args + " " + bools else: - return args or opts + return args or bools def client_getopt(self, argv): """Parse options for this class.""" @@ -224,15 +224,23 @@ def call_daemon(cms_class, client_key, client_cert, server_ta, url, q_msg): q_cms, q_xml = cms_class.wrap(q_msg, client_key, client_cert, pretty_print = True) if verbose: print q_xml - der = rpki.https.client(client_key = client_key, - client_cert = client_cert, - server_ta = server_ta, - url = url, - msg = q_cms) - r_msg, r_xml = cms_class.unwrap(der, server_ta, pretty_print = True) - print r_xml - for r_pdu in r_msg: - r_pdu.client_reply_decode() + + def done(der): + r_msg, r_xml = cms_class.unwrap(der, server_ta, pretty_print = True) + print r_xml + for r_pdu in r_msg: + r_pdu.client_reply_decode() + + def fail(e): + print "Failed: %s" % e + + rpki.https.client(client_key = client_key, + client_cert = client_cert, + server_ta = server_ta, + url = url, + msg = q_cms, + callback = done, + errback = fail) # Main program diff --git a/rpkid/rpki/exceptions.py b/rpkid/rpki/exceptions.py index f5aca3aa..d2ff92ec 100644 --- a/rpkid/rpki/exceptions.py +++ b/rpkid/rpki/exceptions.py @@ -148,3 +148,6 @@ class ForbiddenURI(RPKI_Exception): class HTTPSRetryFailure(RPKI_Exception): """HTTPS connection failed and request has already been retried.""" + +class BadPublicationReply(RPKI_Exception): + """Unexpected reply to publication query.""" diff --git a/rpkid/rpki/https.py b/rpkid/rpki/https.py index 82fa3a49..b3636118 100644 --- a/rpkid/rpki/https.py +++ b/rpkid/rpki/https.py @@ -35,7 +35,7 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -import sys, os, time, socket, asyncore, asynchat, traceback, urlparse +import time, socket, asyncore, asynchat, traceback, urlparse import rpki.async, rpki.sundial, rpki.x509, rpki.exceptions, rpki.log print "====== WARNING WARNING WARNING ======" @@ -76,7 +76,7 @@ class http_message(object): else: translate_underscore = False result = {} - for k,v in headers: + for k, v in headers: if translate_underscore: k = k.replace("_", "-") k = "-".join(s.capitalize() for s in k.split("-")) @@ -144,7 +144,7 @@ class http_request(http_message): if self.retried: raise rpki.exceptions.HTTPSRetryFailure else: - self.retried = True + self.retried = True def parse_first_line(self, cmd, path, version): self.parse_version(version) @@ -527,20 +527,13 @@ class http_queue(object): queues = {} -def client(msg, client_key, client_cert, server_ta, url, callback, errback = None): +def client(msg, client_key, client_cert, server_ta, url, callback, errback): """Open client HTTPS connection, send a message, wait for response. THIS VERSION DOES NOT DO TLS. THIS IS EXPERIMENTAL CODE. DO NOT USE IN PRODUCTION UNTIL TLS SUPPORT HAS BEEN ADDED. """ - if errback is not None: - pass - elif False: - raise RuntimeError, "rpki.https.client() call with no errback" - else: - def errback(e): raise e - u = urlparse.urlparse(url) if (u.scheme not in ("", "https") or @@ -579,6 +572,6 @@ def server(handlers, server_key, server_cert, port, host ="", client_ta = None, if not isinstance(handlers, (tuple, list)): handlers = (("/", handlers),) - listener = http_listener(port = port, handlers = handlers) + http_listener(port = port, handlers = handlers) rpki.async.event_loop() diff --git a/rpkid/rpki/left_right.py b/rpkid/rpki/left_right.py index 99786a29..784c8b7b 100644 --- a/rpkid/rpki/left_right.py +++ b/rpkid/rpki/left_right.py @@ -34,9 +34,9 @@ class left_right_namespace(object): class data_elt(rpki.xml_utils.data_elt, rpki.sql.sql_persistant, left_right_namespace): """Virtual class for top-level left-right protocol data elements.""" - def self(this): + def self(self): """Fetch self object to which this object links.""" - return self_elt.sql_fetch(this.gctx, this.self_id) + return self_elt.sql_fetch(self.gctx, self.self_id) def bsc(self): """Return BSC object to which this object links.""" @@ -161,6 +161,15 @@ class self_elt(data_elt): ca_map = dict((ca.parent_resource_class, ca) for ca in parent.cas()) def class_loop(class_iterator, rc): + + def class_update_failed(e): + rpki.log.warn("Couldn't update class, skipping: %s" % e) + class_iterator() + + def class_create_failed(e): + rpki.log.warn("Couldn't create class, skipping: %s" % e) + class_iterator() + if rc.class_name in ca_map: ca = ca_map[rc.class_name] del ca_map[rc.class_name] @@ -168,14 +177,6 @@ class self_elt(data_elt): else: rpki.rpki_engine.ca_obj.create(parent, rc, class_iterator, class_create_failed) - def class_update_failed(e): - rpki.log.warn("Couldn't update class, skipping: %s" % e) - class_iterator() - - def class_create_failed(e): - rpki.log.warn("Couldn't create class, skipping: %s" % e) - class_iterator() - def class_done(): for ca in ca_map.values(): ca.delete(parent) # CA not listed by parent @@ -572,9 +573,13 @@ class repository_elt(data_elt): bpki_ta_path = (self.gctx.bpki_ta, self.self().bpki_cert, self.self().bpki_glue, self.bpki_https_cert, self.bpki_https_glue) def done(r_cms): - r_msg = rpki.publication.cms_msg.unwrap(r_cms, bpki_ta_path) - assert len(r_msg) == 1 - callback(r_msg[0]) + try: + r_msg = rpki.publication.cms_msg.unwrap(r_cms, bpki_ta_path) + if len(r_msg) != 1 or isinstance(r_msg[0], rpki.publication.report_error_elt): + raise rpki.exceptions.BadPublicationReply, "Unexpected response from pubd: %s" % msg + callback() + except Exception, edata: + errback(edata) rpki.https.client( client_key = bsc.private_key_id, @@ -582,7 +587,8 @@ class repository_elt(data_elt): server_ta = bpki_ta_path, url = self.peer_contact_uri, msg = q_cms, - callback = done) + callback = done, + errback = errback) def publish(self, obj, uri, callback, errback): """Publish one object in the repository.""" diff --git a/rpkid/rpki/log.py b/rpkid/rpki/log.py index 46639673..c19db594 100644 --- a/rpkid/rpki/log.py +++ b/rpkid/rpki/log.py @@ -42,11 +42,11 @@ def init(ident = "rpki", flags = syslog.LOG_PID | syslog.LOG_PERROR, facility = tag = ident pid = os.getpid() -def set_trace(trace): +def set_trace(enable): """Enable or disable call tracing.""" global enable_trace - enable_trace = trace + enable_trace = enable class logger(object): """Closure for logging.""" diff --git a/rpkid/rpki/up_down.py b/rpkid/rpki/up_down.py index 5eeda02d..5b257a53 100644 --- a/rpkid/rpki/up_down.py +++ b/rpkid/rpki/up_down.py @@ -17,7 +17,7 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -import base64, lxml.etree, time, traceback +import base64, lxml.etree, traceback import rpki.resource_set, rpki.x509, rpki.exceptions import rpki.xml_utils, rpki.relaxng diff --git a/rpkid/rpki/xml_utils.py b/rpkid/rpki/xml_utils.py index 803429e7..1487cdd3 100644 --- a/rpkid/rpki/xml_utils.py +++ b/rpkid/rpki/xml_utils.py @@ -18,6 +18,7 @@ PERFORMANCE OF THIS SOFTWARE. """ import xml.sax, lxml.sax, lxml.etree, base64 +import rpki.exceptions class sax_handler(xml.sax.handler.ContentHandler): """SAX handler for RPKI protocols. @@ -35,6 +36,7 @@ class sax_handler(xml.sax.handler.ContentHandler): def __init__(self): """Initialize SAX handler.""" + xml.sax.handler.ContentHandler.__init__(self) self.text = "" self.stack = [] diff --git a/rpkid/testbed.3.yaml b/rpkid/testbed.3.yaml index 3b1a7cb4..16f22c92 100644 --- a/rpkid/testbed.3.yaml +++ b/rpkid/testbed.3.yaml @@ -34,8 +34,10 @@ kids: - asn: 666 ipv4: 10.3.0.0/23 --- -- shell find publication -type f -name '*.roa' -print -exec ../../utils/print_roa/print_roa {} \; -- shell find publication -type f -name '*.mnf' -print -exec ../../utils/print_manifest/print_manifest {} \; ---- -- shell find publication -type f -name '*.roa' -print -exec ../../utils/print_roa/print_roa {} \; -- shell find publication -type f -name '*.mnf' -print -exec ../../utils/print_manifest/print_manifest {} \; +#- shell find publication -type f -name '*.roa' -print -exec ../../utils/print_roa/print_roa {} \; +#- shell find publication -type f -name '*.mnf' -print -exec ../../utils/print_manifest/print_manifest {} \; +#--- +#- shell find publication -type f -name '*.roa' -print -exec ../../utils/print_roa/print_roa {} \; +#- shell find publication -type f -name '*.mnf' -print -exec ../../utils/print_manifest/print_manifest {} \; +#--- +- shell set -x; cd ../../rtr-origin && python rtr-origin.py --cronjob ../rpkid/testbed.dir/rcynic-data/authenticated && python rtr-origin.py --show diff --git a/rpkid/testbed.py b/rpkid/testbed.py index 16cee892..7ad20534 100644 --- a/rpkid/testbed.py +++ b/rpkid/testbed.py @@ -165,7 +165,7 @@ class main(object): # Connect to test directory, creating it if necessary try: os.chdir(testbed_dir) - except: + except OSError: os.makedirs(testbed_dir) os.chdir(testbed_dir) @@ -641,7 +641,7 @@ class allocation(object): try: rpki.log.info("Killing pid %d" % proc.pid) os.kill(proc.pid, signal.SIGTERM) - except: + except OSError: pass proc.wait() diff --git a/rpkid/testpoke.py b/rpkid/testpoke.py index f28dc9b2..f07135a6 100644 --- a/rpkid/testpoke.py +++ b/rpkid/testpoke.py @@ -103,18 +103,22 @@ def query_up_down(q_pdu): try: r_msg.payload.check_response() except Exception, edata: - if debug: - raise - print "Failed:", edata + fail(edata) rpki.async.exit_event_loop() + def fail(e): + if debug: + raise e + print "Failed:", e + rpki.https.client( server_ta = [https_ta] + https_ca_certs, client_key = https_key, client_cert = https_certs, msg = q_cms, url = yaml_data["posturl"], - callback = done) + callback = done, + errback = fail) def do_list(): query_up_down(rpki.up_down.list_pdu()) |