diff options
author | Rob Austein <sra@hactrn.net> | 2009-06-16 19:35:50 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2009-06-16 19:35:50 +0000 |
commit | 3b76341bb8e1cf3a75f945515755ed190f725468 (patch) | |
tree | fb3b66d9fadafa948951b83f78dde82cd47e33b3 | |
parent | 2346523cf23f3238a573d3a28877ba996f51b8ce (diff) |
Checkpoint
svn path=/myrpki/myrpki.conf; revision=2528
-rw-r--r-- | myrpki/myrpki.conf | 2 | ||||
-rw-r--r-- | myrpki/myrpki.py | 38 | ||||
-rw-r--r-- | myrpki/myrpki.rnc | 6 |
3 files changed, 33 insertions, 13 deletions
diff --git a/myrpki/myrpki.conf b/myrpki/myrpki.conf index bee18eeb..d35f4f1a 100644 --- a/myrpki/myrpki.conf +++ b/myrpki/myrpki.conf @@ -17,6 +17,8 @@ bpki_ca_key = bpki-ca-key.pem bpki_ee_certificate = bpki-ee-cert.pem bpki_ee_pkcs10 = bpki-ee-pkcs10.pem +output-filename = myrpki.xml + [req] default_bits = 2048 default_md = sha256 diff --git a/myrpki/myrpki.py b/myrpki/myrpki.py index 60c2280b..0b381002 100644 --- a/myrpki/myrpki.py +++ b/myrpki/myrpki.py @@ -23,7 +23,7 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -import subprocess, csv, sys, os, ConfigParser +import subprocess, csv, re, os, ConfigParser from xml.etree.ElementTree import Element, SubElement, ElementTree @@ -43,6 +43,10 @@ bpki_ca_cert_file = cfg.get(myrpki_section, "bpki_ca_certificate") bpki_ca_key_file = cfg.get(myrpki_section, "bpki_ca_key") bpki_ee_cert_file = cfg.get(myrpki_section, "bpki_ee_certificate") bpki_ee_req_file = cfg.get(myrpki_section, "bpki_ee_pkcs10") +output_filename = cfg.get(myrpki_section, "output-filename") + +v4regexp = re.compile("^[-0-9./]+$", re.I) +v6regexp = re.compile("^[-0-9:/]+$", re.I) class comma_set(set): @@ -53,15 +57,22 @@ class roa_request(object): def __init__(self, asn): self.asn = asn - self.prefixes = comma_set() + self.v4 = comma_set() + self.v6 = comma_set() def add(self, prefix): - self.prefixes.add(prefix) + if v4regexp.match(prefix): + self.v4.add(prefix) + elif v6regexp.match(prefix): + self.v6.add(prefix) + else: + raise RuntimeError, 'Bad prefix syntax: "%s"' % prefix def xml(self, e): return SubElement(e, "roa_request", asn = self.asn, - prefixes = str(self.prefixes)) + v4 = str(self.v4), + v6 = str(self.v6)) class roa_requests(dict): @@ -79,12 +90,18 @@ class child(object): def __init__(self, handle): self.handle = handle self.asns = comma_set() - self.prefixes = comma_set() + self.v4 = comma_set() + self.v6 = comma_set() self.validity = None def add(self, prefix = None, asn = None, validity = None): if prefix is not None: - self.prefixes.add(prefix) + if v4regexp.match(prefix): + self.v4.add(prefix) + elif v6regexp.match(prefix): + self.v6.add(prefix) + else: + raise RuntimeError, 'Bad prefix syntax: "%s"' % prefix if asn is not None: self.asns.add(asn) if validity is not None: @@ -95,7 +112,8 @@ class child(object): handle = self.handle, valid_until = self.validity, asns = str(self.asns), - prefixes = str(self.prefixes)) + v4 = str(self.v4), + v6 = str(self.v6)) class children(dict): @@ -173,7 +191,5 @@ kids.xml(e) bpki_ca(e) bpki_ee(e) -if True: - ElementTree(e).write(sys.stdout) -else: - print tostring(e) +ElementTree(e).write(output_filename + ".tmp") +os.rename(output_filename + ".tmp", output_filename) diff --git a/myrpki/myrpki.rnc b/myrpki/myrpki.rnc index e82db37f..845daa8f 100644 --- a/myrpki/myrpki.rnc +++ b/myrpki/myrpki.rnc @@ -25,14 +25,16 @@ start = element myrpki { roa_request = element roa_request { attribute asn { xsd:positiveInteger }, - attribute prefixes { ipv4_list } + attribute v4 { ipv4_list }, + attribute v6 { ipv6_list } } child = element child { attribute handle { object_handle }, attribute valid_until { xsd:dateTime { pattern=".*Z" } }, attribute asns { asn_list }?, - attribute prefixes { ipv4_list }? + attribute v4 { ipv4_list }?, + attribute v6 { ipv6_list }? } bpki_ca_certificate = element bpki_ca_certificate { base64 } |