""" RPKI "publication" protocol. $Id$ Copyright (C) 2009 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ import base64, os, errno 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. """ xmlns = "http://www.hactrn.net/uris/rpki/publication-spec/" nsmap = { None : xmlns } class control_elt(rpki.xml_utils.data_elt, rpki.sql.sql_persistent, publication_namespace): """ 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. """ 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): """ 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. So we reuse a lot of the SQL machinery, but we nail config_id at 1, we don't expose it in the XML protocol, and we only support the get and set actions. """ attributes = ("action", "tag") element_name = "config" elements = ("bpki_crl",) sql_template = rpki.sql.template("config", "config_id", ("bpki_crl", rpki.x509.CRL)) 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. """ 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. """ return cls.sql_fetch(gctx, cls.wired_in_config_id) def serve_set(self, r_msg, cb, eb): """ Hand
# $Id$

import rpki.https, tlslite.api, rpki.config

cfg = rpki.config.parser("http-demo.conf")
section = "server"

privateKey = rpki.x509.RSA(PEM_file = cfg.get(section, "https-key"))

certChain = rpki.x509.X509_chain()
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)
x = gctx q_pdu.client = client q_pdu.serve_dispatch(r_msg, iterator, fail) except (rpki.async.ExitNow, SystemExit): raise except Exception, e: fail(e) def done(): cb(r_msg) rpki.async.iterator(self, loop, done) class sax_handler(rpki.xml_utils.sax_handler): """ 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. """ encoding = "us-ascii" schema = rpki.relaxng.publication saxify = sax_handler.saxify