aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpotpourri/rrdp-test-tool57
-rw-r--r--rpki/pubd.py5
2 files changed, 59 insertions, 3 deletions
diff --git a/potpourri/rrdp-test-tool b/potpourri/rrdp-test-tool
new file mode 100755
index 00000000..0fe548b7
--- /dev/null
+++ b/potpourri/rrdp-test-tool
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+# $Id$
+#
+# Copyright (C) 2013 Dragon Research Labs ("DRL")
+#
+# 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 DRL DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS. IN NO EVENT SHALL DRL 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.
+
+"""
+Test tool for prototype RRDP implementation. Eventually some of this
+code will likely be refactored into more user-friendly form, but for
+the moment this just does whatever insane thing I need to do this week
+for testing.
+"""
+
+import rpki.relaxng
+import lxml.etree
+import argparse
+import os
+
+parser = argparse.ArgumentParser(description = __doc__)
+parser.add_argument("rrdp_snapshot",
+ help = "RRDP snapshot file")
+parser.add_argument("rcynic_tree", nargs = "?", default = "unauthenticated",
+ help = "directory tree in which to write extracted RPKI objects")
+args = parser.parse_args()
+
+xml = lxml.etree.ElementTree(file = args.rrdp_snapshot).getroot()
+rpki.relaxng.rrdp.assertValid(xml)
+assert xml.tag == rpki.relaxng.rrdp.xmlns + "snapshot"
+
+if not os.path.isdir(args.rcynic_tree):
+ os.makedirs(args.rcynic_tree)
+
+print "Unpacking version %s session %s serial %s" % (
+ xml.get("version"), xml.get("session_id"), xml.get("serial"))
+
+for elt in xml:
+ assert elt.tag == rpki.relaxng.rrdp.xmlns + "publish"
+ uri = elt.get("uri")
+ print " ", uri
+ assert uri.startswith("rsync://")
+ fn = os.path.join(args.rcynic_tree, uri[len("rsync://"):])
+ dn = os.path.dirname(fn)
+ if not os.path.isdir(dn):
+ os.makedirs(dn)
+ with open(fn, "wb") as f:
+ f.write(elt.text.decode("base64"))
diff --git a/rpki/pubd.py b/rpki/pubd.py
index 96a2bb72..1849a0dd 100644
--- a/rpki/pubd.py
+++ b/rpki/pubd.py
@@ -46,10 +46,9 @@ from lxml.etree import Element, SubElement, tostring as ElementToString
logger = logging.getLogger(__name__)
-# Temporary, these should come from the schema or something
-rrdp_xmlns = "{http://www.ripe.net/rpki/rrdp}"
+rrdp_xmlns = rpki.relaxng.rrdp.xmlns
+rrdp_nsmap = rpki.relaxng.rrdp.nsmap
rrdp_version = "1"
-rrdp_nsmap = { None : rrdp_xmlns[1:-1] }
def DERSubElement(elt, name, der, attrib = None, **kwargs):