""" Convert {parents,children,pubclients}.csv into new XML formats. $Id$ Copyright (C) 2010 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. """ import subprocess, csv, re, os, getopt, sys, rpki.config, base64, myrpki import rpki.sundial from lxml.etree import Element, SubElement, ElementTree cfg_file = "myrpki.conf" opts, argv = getopt.getopt(sys.argv[1:], "c:h:?", ["config=", "help"]) for o, a in opts: if o in ("-h", "--help", "-?"): print __doc__ sys.exit(0) elif o in ("-c", "--config"): cfg_file = a if argv: raise RuntimeError, "Unexpected arguments %r" % (argv,) cfg = rpki.config.parser(cfg_file, "myrpki") entitydb = myrpki.EntityDB(cfg) handle = cfg.get("handle") bpki_resources_directory = cfg.get("bpki_resources_directory") bpki_servers_directory = cfg.get("bpki_servers_directory") repository_bpki_certificate = cfg.get("repository_bpki_certificate") repository_handle = cfg.get("repository_handle") pubd_server_host = cfg.get("pubd_server_host") pubd_server_port = cfg.get("pubd_server_port") rpkid_server_host = cfg.get("rpkid_server_host") rpkid_server_port = cfg.get("rpkid_server_port") bpki_resources_pemfile = bpki_resources_directory + "/ca.cer" bpki_servers_pemfile = bpki_servers_directory + "/ca.cer" if os.path.exists("children.csv"): for child_handle, valid_until, child_resource_pemfile in myrpki.csv_open("children.csv"): e = Element("parent", valid_until = valid_until, service_uri = "https://%s:%s/left-right/%s/%s" % (rpkid_server_host, rpkid_server_port, handle, child_handle), child_handle = child_handle, parent_handle = handle) myrpki.PEMElement(e, "bpki_resource_ta", bpki_resources_pemfile) myrpki.PEMElement(e, "bpki_server_ta", bpki_servers_pemfile) myrpki.PEMElement(e, "bpki_child_ta", child_resource_pemfile) myrpki.etree_write(e, entitydb("children", "%s.xml" % child_handle)) if os.path.exists("parents.csv"): for parent_handle, parent_service_uri, parent_cms_pemfile, parent_https_pemfile, parent_myhandle, parent_sia_base in myrpki.csv_open("parents.csv"): e = Element("parent", valid_until = str(rpki.sundial.now() + rpki.sundial.timedelta(days = 365)), service_uri = parent_service_uri, child_handle = parent_myhandle, parent_handle = parent_handle) myrpki.PEMElement(e, "bpki_resource_ta", parent_cms_pemfile) myrpki.PEMElement(e, "bpki_server_ta", parent_https_pemfile) myrpki.PEMElement(e, "bpki_child_ta", bpki_resources_pemfile) myrpki.etree_write(e, entitydb("parents", "%s.xml" % parent_handle)) client_handle = "/".join(parent_sia_base.rstrip("/").split("/")[3:]) assert client_handle.startswith(repository_handle) e = Element("repository", parent_handle = parent_handle, client_handle = client_handle, service_uri = "https://%s:%s/client/%s" % (pubd_server_host, pubd_server_port, client_handle), sia_base = parent_sia_base, repository_handle = client_handle.split("/")[0], type = "confirmed") myrpki.PEMElement(e, "bpki_server_ta", repository_bpki_certificate) myrpki.PEMElement(e, "bpki_client_ta", bpki_resources_pemfile) SubElement(e, "contact_info").text = "Automatically generated by convert-csv.py" myrpki.etree_write(e, entitydb("repositories", "%s.xml" % parent_handle)) if os.path.exists("pubclients.csv"): for client_handle, client_resource_pemfile, client_sia_base in myrpki.csv_open("pubclients.csv"): parent_handle = client_handle.split("/")[-1] e = Element("repository", parent_handle = parent_handle, client_handle = client_handle, service_uri = "https://%s:%s/client/%s" % (pubd_server_host, pubd_server_port, client_handle), sia_base = client_sia_base, repository_handle = client_handle.split("/")[0], type = "confirmed") myrpki.PEMElement(e, "bpki_server_ta", bpki_servers_pemfile) myrpki.PEMElement(e, "bpki_client_ta", client_resource_pemfile) SubElement(e, "contact_info").text = "Automatically generated by convert-csv.py" myrpki.etree_write(e, entitydb("repositories", "%s.xml" % client_handle.replace("/", ".")))