aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-03-29 22:22:09 +0000
committerRob Austein <sra@hactrn.net>2016-03-29 22:22:09 +0000
commitfa535af8d439db2e20b34c6e80b2ee86f4255f53 (patch)
treeeb3d9b18478bbeaa81546669cef86f0878254f36
parentd6e5a0df28362130b4d30a747f9957f51f502750 (diff)
rpkic needs to do uid swapping around XML reads too.
rpki.irdb.zookeeper.etree_read(), the functions that call it, and the functions that call them, could all use a bit of refactoring. At this point pretty much ever caller is jumping through some hoop or another due to the way the code has evolved, and most of it could be simpler. svn path=/branches/tk705/; revision=6338
-rw-r--r--rpki/irdb/zookeeper.py20
-rw-r--r--rpki/rpkic.py20
2 files changed, 31 insertions, 9 deletions
diff --git a/rpki/irdb/zookeeper.py b/rpki/irdb/zookeeper.py
index 9d40263c..bca56926 100644
--- a/rpki/irdb/zookeeper.py
+++ b/rpki/irdb/zookeeper.py
@@ -150,15 +150,27 @@ class PEM_writer(object):
def etree_read(filename_or_etree_wrapper, schema = rpki.relaxng.oob_setup):
"""
Read an etree from a file, verifying then stripping XML namespace
- cruft. As a convenience, we also accept an etree_wrapper object in
- place of a filename, in which case we deepcopy the etree directly
- from the etree_wrapper and there's no need for a file.
+ cruft.
+
+ As a convenience, we also accept an etree_wrapper object in place
+ of a filename, in which case we deepcopy the etree directly from
+ the etree_wrapper and there's no need for a file.
+
+ As a further convenience, we also accept an Element object,
+ in which case we just validate and return it.
+
+ This function's behavior has changed over time, and the code which
+ calls it is overdue for refactoring, but the relevant code in
+ rpki.gui.app.views is a bit complex, so that yak will have to take
+ a number and wait for its shave, today we have a bug to fix.
"""
if isinstance(filename_or_etree_wrapper, etree_wrapper):
e = copy.deepcopy(filename_or_etree_wrapper.etree)
- else:
+ elif isinstance(filename_or_etree_wrapper, (str, unicode)):
e = ElementTree(file = filename_or_etree_wrapper).getroot()
+ else:
+ e = filename_or_etree_wrapper
schema.assertValid(e)
return e
diff --git a/rpki/rpkic.py b/rpki/rpkic.py
index 199a685d..51a4d6d2 100644
--- a/rpki/rpkic.py
+++ b/rpki/rpkic.py
@@ -64,6 +64,16 @@ class swap_uids(object):
return False
+def read_xml_swapped_uids(filename):
+ """
+ Read an XML file with UIDs swapped.
+ """
+
+ from lxml.etree import ElementTree
+
+ with swap_uids():
+ return ElementTree(file = filename).getroot()
+
class main(Cmd):
prompt = "rpkic> "
@@ -368,7 +378,7 @@ class main(Cmd):
up-down protocol service URI.
"""
- r, child_handle = self.zoo.configure_child(args.child_xml, args.child_handle, args.valid_until)
+ r, child_handle = self.zoo.configure_child(read_xml_swapped_uids(args.child_xml), args.child_handle, args.valid_until)
with swap_uids():
r.save("%s.%s.parent-response.xml" % (self.zoo.handle, child_handle), sys.stdout)
self.zoo.synchronize_ca()
@@ -415,7 +425,7 @@ class main(Cmd):
synchronize here, run the synchronize command yourself.
"""
- r, parent_handle = self.zoo.configure_parent(args.parent_xml, args.parent_handle)
+ r, parent_handle = self.zoo.configure_parent(read_xml_swapped_uids(args.parent_xml), args.parent_handle)
with swap_uids():
r.save("%s.%s.repository-request.xml" % (self.zoo.handle, parent_handle), sys.stdout)
@@ -486,7 +496,7 @@ class main(Cmd):
message containing the repository's BPKI data and service URI.
"""
- r, client_handle = self.zoo.configure_publication_client(args.client_xml, args.sia_base, args.flat)
+ r, client_handle = self.zoo.configure_publication_client(read_xml_swapped_uids(args.client_xml), args.sia_base, args.flat)
with swap_uids():
r.save("%s.repository-response.xml" % client_handle.replace("/", "."), sys.stdout)
try:
@@ -527,7 +537,7 @@ class main(Cmd):
corresponding parent data in our local database.
"""
- self.zoo.configure_repository(args.repository_xml, args.parent_handle)
+ self.zoo.configure_repository(read_xml_swapped_uids(args.repository_xml), args.parent_handle)
self.zoo.synchronize_ca()
@@ -773,7 +783,7 @@ class main(Cmd):
Load router certificate request(s) into IRDB from XML file.
"""
- self.zoo.add_router_certificate_request(args.router_certificate_request_xml, args.valid_until)
+ self.zoo.add_router_certificate_request(read_xml_swapped_uids(args.router_certificate_request_xml), args.valid_until)
if self.autosync:
self.zoo.run_rpkid_now()