diff options
author | Rob Austein <sra@hactrn.net> | 2007-11-01 03:59:06 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2007-11-01 03:59:06 +0000 |
commit | 12feb50d0494ebbf33cd18b4c8974eebf2e20158 (patch) | |
tree | 1a31e3375a1d71448b23253bf48336e4cc8c4941 /scripts | |
parent | dab64de7378853c3ab33dc7c14fd332228467541 (diff) |
More dumb bugs
svn path=/scripts/rpki/cms.py; revision=1224
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/rpki/cms.py | 4 | ||||
-rw-r--r-- | scripts/rpki/left_right.py | 6 | ||||
-rw-r--r-- | scripts/rpki/up_down.py | 4 | ||||
-rwxr-xr-x | scripts/testroot.py | 26 |
4 files changed, 27 insertions, 13 deletions
diff --git a/scripts/rpki/cms.py b/scripts/rpki/cms.py index 999e3197..6a061c67 100644 --- a/scripts/rpki/cms.py +++ b/scripts/rpki/cms.py @@ -86,7 +86,7 @@ def xml_verify(elt, ta): """Composite routine to verify CMS-wrapped XML.""" return lxml.etree.fromstring(verify(elt, ta)) -def xml_sign(elt, key, certs): +def xml_sign(elt, key, certs, encoding = "us-ascii"): """Composite routine to sign CMS-wrapped XML.""" - return sign(lxml.etree.tostring(elt, pretty_print=True, encoding="us-ascii", xml_declaration=True), + return sign(lxml.etree.tostring(elt, pretty_print = True, encoding = encoding, xml_declaration = True), key, certs) diff --git a/scripts/rpki/left_right.py b/scripts/rpki/left_right.py index 2be222bd..a5d1fe87 100644 --- a/scripts/rpki/left_right.py +++ b/scripts/rpki/left_right.py @@ -261,7 +261,7 @@ class self_elt(data_elt): r_pdu = rpki.up_down.list_pdu.query(gctx, parent) ca_map = dict((ca.parent_resource_class, ca) for ca in rpki.sql.ca_obj.sql_fetch_where(gctx, "parent_id = %s" % parent.parent_id)) - for rc in r_pdu.payload: + for rc in r_pdu.payload.classes: if rc.class_name in ca_map: ca = ca_map[rc.class_name] del ca_map[rc.class_name] @@ -417,7 +417,7 @@ class parent_elt(data_elt): q_msg = rpki.up_down.message_pdu.make_query(q_pdu) q_elt = q_msg.toXML() rpki.relaxng.up_down.assertValid(q_elt) - q_cms = rpki.cms.xml_sign(q_elt, bsc.private_key_id, bsc.signing_cert) + q_cms = rpki.cms.xml_sign(q_elt, bsc.private_key_id, bsc.signing_cert, encoding = "UTF-8") r_cms = rpki.https.client(x509TrustList = rpki.x509.X509_chain(self.https_ta), privateKey = gctx.https_key, certChain = gctx.https_certs, @@ -488,7 +488,7 @@ class child_elt(data_elt): # r_elt = r_msg.toXML() rpki.relaxng.up_down.assertValid(r_elt) - return rpki.cms.xml_sign(r_elt, bsc.private_key_id, bsc.signing_cert) + return rpki.cms.xml_sign(r_elt, bsc.private_key_id, bsc.signing_cert, encoding = "UTF-8") class repository_elt(data_elt): """<repository/> element.""" diff --git a/scripts/rpki/up_down.py b/scripts/rpki/up_down.py index 82203603..edb70657 100644 --- a/scripts/rpki/up_down.py +++ b/scripts/rpki/up_down.py @@ -458,7 +458,7 @@ class message_pdu(base_elt): def __str__(self): """Convert a message PDU to a string.""" - lxml.etree.tostring(self.toXML(), pretty_print=True, encoding="UTF-8") + lxml.etree.tostring(self.toXML(), pretty_print = True, encoding = "UTF-8") def serve_top_level(self, gctx, child): """Serve one message request PDU.""" @@ -466,6 +466,7 @@ class message_pdu(base_elt): r_msg.sender = self.recipient r_msg.recipient = self.sender self.payload.serve_pdu(gctx, self, r_msg, child) + r_msg.type = self.type2name[type(r_msg.payload)] return r_msg def serve_error(self, exception): @@ -474,6 +475,7 @@ class message_pdu(base_elt): r_msg.sender = self.recipient r_msg.recipient = self.sender r_msg.payload = error_response_pdu(exception) + r_msg.type = self.type2name[type(r_msg.payload)] return r_msg @classmethod diff --git a/scripts/testroot.py b/scripts/testroot.py index 0cfb2862..a3b644d0 100755 --- a/scripts/testroot.py +++ b/scripts/testroot.py @@ -10,7 +10,7 @@ Usage: python testroot.py [ { -c | --config } configfile ] [ { -h | --help } ] Default configuration file is testroot.conf, override with --config option. """ -import traceback, os, time, getopt, sys +import traceback, os, time, getopt, sys, lxml import rpki.resource_set, rpki.up_down, rpki.left_right, rpki.x509 import rpki.https, rpki.config, rpki.cms, rpki.exceptions, rpki.relaxng @@ -34,14 +34,13 @@ def compose_response(r_msg): rc.class_name = root_name rc.cert_url = rpki.up_down.multi_uri(root_cert) rc.resource_set_as, rc.resource_set_ipv4, rc.resource_set_ipv6 = rpki_issuer.get_3779resources() + rc.issuer = rpki_issuer r_msg.payload.classes.append(rc) rpki_subject = get_subject_cert() if rpki_subject is not None: rc.certs.append(rpki.up_down.certificate_elt()) rc.certs[0].cert_url = rpki.up_down.multi_uri(root_base + rpki_subject.gSKI() + ".cer") rc.certs[0].cert = rpki_subject - rc.issuer = rpki_issuer - print rc, rc.certs, rc.certs[0], rc.issuer class list_pdu(rpki.up_down.list_pdu): def serve_pdu(self, xxx1, q_msg, r_msg, xxx2): @@ -66,7 +65,14 @@ class revoke_pdu(rpki.up_down.revoke_pdu): raise rpki.exceptions.NotImplementedYet class message_pdu(rpki.up_down.message_pdu): - name2type = { "list" : list_pdu, "issue" : issue_pdu, "revoke" : revoke_pdu } + name2type = { + "list" : list_pdu, + "list_response" : rpki.up_down.list_response_pdu, + "issue" : issue_pdu, + "issue_response" : rpki.up_down.issue_response_pdu, + "revoke" : revoke_pdu, + "revoke_response" : rpki.up_down.revoke_response_pdu, + "error_response" : rpki.up_down.error_response_pdu } type2name = dict((v,k) for k,v in name2type.items()) class sax_handler(rpki.sax_utils.handler): @@ -84,15 +90,21 @@ def up_down_handler(query, path): try: r_msg = q_msg.serve_top_level(None, None) r_elt = r_msg.toXML() - rpki.relaxng.up_down.assertValid(r_elt) - return 200, rpki.cms.xml_sign(r_elt, cms_key, cms_certs) + try: + rpki.relaxng.up_down.assertValid(r_elt) + except lxml.etree.DocumentInvalid: + print + print lxml.etree.tostring(r_elt, pretty_print = True, encoding ="utf-8", xml_declaration = True) + print + raise + return 200, rpki.cms.xml_sign(r_elt, cms_key, cms_certs, encoding = "utf-8") except Exception, data: traceback.print_exc() try: r_msg = q_msg.serve_error(data) r_elt = r_msg.toXML() rpki.relaxng.up_down.assertValid(r_elt) - return 200, rpki.cms.xml_sign(r_elt, cms_key, cms_certs) + return 200, rpki.cms.xml_sign(r_elt, cms_key, cms_certs, encoding = "utf-8") except Exception, data: traceback.print_exc() return 500, "Could not process PDU: %s" % data |