diff options
Diffstat (limited to 'rpkid/rpki/publication.py')
-rw-r--r-- | rpkid/rpki/publication.py | 116 |
1 files changed, 83 insertions, 33 deletions
diff --git a/rpkid/rpki/publication.py b/rpkid/rpki/publication.py index b43fa60c..ad4ce866 100644 --- a/rpkid/rpki/publication.py +++ b/rpkid/rpki/publication.py @@ -1,4 +1,5 @@ -"""RPKI "publication" protocol. +""" +RPKI "publication" protocol. $Id$ @@ -22,24 +23,30 @@ import rpki.resource_set, rpki.x509, rpki.sql, rpki.exceptions, rpki.xml_utils import rpki.https, rpki.up_down, rpki.relaxng, rpki.sundial, rpki.log, rpki.roa class publication_namespace(object): - """XML namespace parameters for publication protocol.""" + """ + XML namespace parameters for publication protocol. + """ xmlns = "http://www.hactrn.net/uris/rpki/publication-spec/" nsmap = { None : xmlns } class control_elt(rpki.xml_utils.data_elt, rpki.sql.sql_persistant, publication_namespace): - """Virtual class for control channel objects.""" + """ + Virtual class for control channel objects. + """ def serve_dispatch(self, r_msg, cb, eb): - """Action dispatch handler. This needs special handling because - we need to make sure that this PDU arrived via the control channel. + """ + Action dispatch handler. This needs special handling because we + need to make sure that this PDU arrived via the control channel. """ if self.client is not None: raise rpki.exceptions.BadQuery, "Control query received on client channel" rpki.xml_utils.data_elt.serve_dispatch(self, r_msg, cb, eb) class config_elt(control_elt): - """<config/> element. This is a little weird because there should + """ + <config/> element. This is a little weird because there should never be more than one row in the SQL config table, but we have to put the BPKI CRL somewhere and SQL is the least bad place available. @@ -57,21 +64,24 @@ class config_elt(control_elt): wired_in_config_id = 1 def startElement(self, stack, name, attrs): - """StartElement() handler for config object. This requires - special handling because of the weird way we treat config_id. + """ + StartElement() handler for config object. This requires special + handling because of the weird way we treat config_id. """ control_elt.startElement(self, stack, name, attrs) self.config_id = self.wired_in_config_id @classmethod def fetch(cls, gctx): - """Fetch the config object from SQL. This requires special - handling because of the weird way we treat config_id. + """ + Fetch the config object from SQL. This requires special handling + because of the weird way we treat config_id. """ return cls.sql_fetch(gctx, cls.wired_in_config_id) def serve_set(self, r_msg, cb, eb): - """Handle a set action. This requires special handling because + """ + Handle a set action. This requires special handling because config doesn't support the create method. """ if self.sql_fetch(self.gctx, self.config_id) is None: @@ -80,7 +90,8 @@ class config_elt(control_elt): control_elt.serve_set(self, r_msg, cb, eb) def serve_fetch_one(self): - """Find the config object on which a get or set method should + """ + Find the config object on which a get or set method should operate. """ r = self.sql_fetch(self.gctx, self.config_id) @@ -89,7 +100,9 @@ class config_elt(control_elt): return r class client_elt(control_elt): - """<client/> element.""" + """ + <client/> element. + """ element_name = "client" attributes = ("action", "tag", "client_id", "base_uri") @@ -104,7 +117,8 @@ class client_elt(control_elt): clear_https_ta_cache = False def endElement(self, stack, name, text): - """Handle subelements of <client/> element. These require special + """ + Handle subelements of <client/> element. These require special handling because modifying them invalidates the HTTPS trust anchor cache. """ @@ -113,14 +127,17 @@ class client_elt(control_elt): self.clear_https_ta_cache = True def serve_post_save_hook(self, q_pdu, r_pdu, cb, eb): - """Extra server actions for client_elt.""" + """ + Extra server actions for client_elt. + """ if self.clear_https_ta_cache: self.gctx.clear_https_ta_cache() self.clear_https_ta_cache = False cb() def serve_fetch_one(self): - """Find the client object on which a get, set, or destroy method + """ + Find the client object on which a get, set, or destroy method should operate. """ r = self.sql_fetch(self.gctx, self.client_id) @@ -137,7 +154,8 @@ class client_elt(control_elt): raise rpki.exceptions.ForbiddenURI class publication_object_elt(rpki.xml_utils.base_elt, publication_namespace): - """Virtual class for publishable objects. These have very similar + """ + Virtual class for publishable objects. These have very similar syntax, differences lie in underlying datatype and methods. XML methods are a little different from the pattern used for objects that support the create/set/get/list/destroy actions, but @@ -149,21 +167,27 @@ class publication_object_elt(rpki.xml_utils.base_elt, publication_namespace): payload = None def endElement(self, stack, name, text): - """Handle a publishable element element.""" + """ + Handle a publishable element element. + """ assert name == self.element_name, "Unexpected name %s, stack %s" % (name, stack) if text: self.payload = self.payload_type(Base64 = text) stack.pop() def toXML(self): - """Generate XML element for publishable object.""" + """ + Generate XML element for publishable object. + """ elt = self.make_elt() if self.payload: elt.text = base64.b64encode(self.payload.get_DER()) return elt def serve_dispatch(self, r_msg, cb, eb): - """Action dispatch handler.""" + """ + Action dispatch handler. + """ if self.client is None: raise rpki.exceptions.BadQuery, "Client query received on control channel" dispatch = { "publish" : self.serve_publish, @@ -180,7 +204,9 @@ class publication_object_elt(rpki.xml_utils.base_elt, publication_namespace): cb() def serve_publish(self): - """Publish an object.""" + """ + Publish an object. + """ rpki.log.info("Publishing %s as %s" % (repr(self.payload), repr(self.uri))) filename = self.uri_to_filename() dirname = os.path.dirname(filename) @@ -191,12 +217,16 @@ class publication_object_elt(rpki.xml_utils.base_elt, publication_namespace): f.close() def serve_withdraw(self): - """Withdraw an object.""" + """ + Withdraw an object. + """ rpki.log.info("Withdrawing %s" % repr(self.uri)) os.remove(self.uri_to_filename()) def uri_to_filename(self): - """Convert a URI to a local filename.""" + """ + Convert a URI to a local filename. + """ if not self.uri.startswith("rsync://"): raise rpki.exceptions.BadURISyntax filename = self.gctx.publication_base + self.uri[len("rsync://"):] @@ -205,25 +235,33 @@ class publication_object_elt(rpki.xml_utils.base_elt, publication_namespace): return filename class certificate_elt(publication_object_elt): - """<certificate/> element.""" + """ + <certificate/> element. + """ element_name = "certificate" payload_type = rpki.x509.X509 class crl_elt(publication_object_elt): - """<crl/> element.""" + """ + <crl/> element. + """ element_name = "crl" payload_type = rpki.x509.CRL class manifest_elt(publication_object_elt): - """<manifest/> element.""" + """ + <manifest/> element. + """ element_name = "manifest" payload_type = rpki.x509.SignedManifest class roa_elt(publication_object_elt): - """<roa/> element.""" + """ + <roa/> element. + """ element_name = "roa" payload_type = rpki.x509.ROA @@ -234,20 +272,26 @@ class roa_elt(publication_object_elt): obj2elt = dict((e.payload_type, e) for e in (certificate_elt, crl_elt, manifest_elt, roa_elt)) class report_error_elt(rpki.xml_utils.base_elt, publication_namespace): - """<report_error/> element.""" + """ + <report_error/> element. + """ element_name = "report_error" attributes = ("tag", "error_code") @classmethod def from_exception(cls, exc): - """Generate a <report_error/> element from an exception.""" + """ + Generate a <report_error/> element from an exception. + """ self = cls() self.error_code = exc.__class__.__name__ return self class msg(rpki.xml_utils.msg, publication_namespace): - """Publication PDU.""" + """ + Publication PDU. + """ ## @var version # Protocol version @@ -259,7 +303,9 @@ class msg(rpki.xml_utils.msg, publication_namespace): for x in (config_elt, client_elt, certificate_elt, crl_elt, manifest_elt, roa_elt, report_error_elt)) def serve_top_level(self, gctx, client, cb): - """Serve one msg PDU.""" + """ + Serve one msg PDU. + """ if self.type != "query": raise rpki.exceptions.BadQuery, "Message type is not query" r_msg = self.__class__() @@ -287,14 +333,18 @@ class msg(rpki.xml_utils.msg, publication_namespace): rpki.async.iterator(self, loop, done) class sax_handler(rpki.xml_utils.sax_handler): - """SAX handler for publication protocol.""" + """ + SAX handler for publication protocol. + """ pdu = msg name = "msg" version = "1" class cms_msg(rpki.x509.XML_CMS_object): - """Class to hold a CMS-signed publication PDU.""" + """ + Class to hold a CMS-signed publication PDU. + """ encoding = "us-ascii" schema = rpki.relaxng.publication |