aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2007-06-20 14:33:26 +0000
committerRob Austein <sra@hactrn.net>2007-06-20 14:33:26 +0000
commit6acbb9ce64bacf07cd6a0fd0a26aa16a3d32d6fa (patch)
tree6c367d5883671237067c0f65b8a50d697275c805
parent653bcec48132b7a73b8ac4dd59f99d4d8ff5eb68 (diff)
Checkpoint
svn path=/scripts/PLAN; revision=672
-rw-r--r--scripts/PLAN6
-rw-r--r--scripts/up-down-schema.rnc80
-rw-r--r--scripts/up-down-schema.rng272
-rwxr-xr-xscripts/xml-parse-test.pl31
4 files changed, 387 insertions, 2 deletions
diff --git a/scripts/PLAN b/scripts/PLAN
index 073317ef..13f9de93 100644
--- a/scripts/PLAN
+++ b/scripts/PLAN
@@ -18,6 +18,12 @@ Rough plan for initial prototype RE.
Log everything as we go and use Data::Dumper to log content of Perl
data structures.
+ APNIC is specifying schema in RNC (RelaxNG Compact) syntax, xmllint
+ wants RNG (RelaxNG XML) syntax, so use /usr/ports/textproc/trang to
+ convert:
+
+ $ trang foo.rnc foo.rng
+
3) Whack (2) into something that does this over minimal HTTP.
4) [to be continued...]
diff --git a/scripts/up-down-schema.rnc b/scripts/up-down-schema.rnc
new file mode 100644
index 00000000..41921b21
--- /dev/null
+++ b/scripts/up-down-schema.rnc
@@ -0,0 +1,80 @@
+# $Id$
+#
+# RelaxNG (Compact Syntax) Scheme for up-down protocol, extracted
+# from APNIC Wiki.
+#
+# libxml2 (including xmllint) only groks the XML syntax of RelaxNG,
+# so run this through a converter like /usr/ports/textproc/trang to get
+# XML syntax:
+#
+# $ trang up-down-schema.rnc up-down-schema.rng
+
+ default namespace = "http://www.apnic.net/specs/rescerts/up-down/"
+
+ grammar {
+ start = element message {
+ attribute version { xsd:positiveInteger { maxInclusive="1" } },
+ attribute sender { xsd:token { maxLength="1024" } },
+ attribute recipient { xsd:token { maxLength="1024" } },
+ attribute msg_ref { xsd:positiveInteger { maxInclusive="999999999999999" } },
+ payload
+ }
+
+ payload |= attribute type { "list" }, list_request
+ payload |= attribute type { "list_response"}, list_response
+ payload |= attribute type { "issue" }, issue_request
+ payload |= attribute type { "issue_response"}, issue_response
+ payload |= attribute type { "revoke" }, revoke_request
+ payload |= attribute type { "revoke_response"}, revoke_response
+ payload |= attribute type { "error_response"}, error_response
+
+ list_request = empty
+ list_response = class*
+
+ class = element class {
+ attribute class_name { xsd:token { maxLength="1024" } },
+ attribute cert_url { xsd:anyURI { maxLength="1024" } },
+ attribute cert_ski { xsd:token { maxLength="1024" } },
+ attribute resource_set_as { xsd:string { maxLength="512000" } },
+ attribute resource_set_ipv4 { xsd:string { maxLength="512000" } },
+ attribute resource_set_ipv6 { xsd:string { maxLength="512000" } },
+ attribute suggested_sia_head { xsd:string { maxLength="1024" } }?,
+ element certificate {
+ attribute cert_url { xsd:anyURI { maxLength="1024" } },
+ attribute cert_ski { xsd:token { maxLength="1024" } },
+ attribute cert_aki { xsd:token { maxLength="1024" } },
+ attribute cert_serial { xsd:positiveInteger },
+ attribute resource_set_as { xsd:string { maxLength="512000" } },
+ attribute resource_set_ipv4 { xsd:string { maxLength="512000" } },
+ attribute resource_set_ipv6 { xsd:string { maxLength="512000" } },
+ attribute req_resource_set_as { xsd:string { maxLength="512000" } }?,
+ attribute req_resource_set_ipv4 { xsd:string { maxLength="512000" } }?,
+ attribute req_resource_set_ipv6 { xsd:string { maxLength="512000" } }?,
+ attribute status { "undersize" | "match" | "oversize" },
+ xsd:base64Binary { maxLength="512000" }
+ }*,
+ element issuer { xsd:base64Binary { maxLength="512000" } }
+ }
+
+ issue_request = element request {
+ attribute class_name { xsd:token { maxLength="1024" } },
+ attribute req_resource_set_as { xsd:string { maxLength="512000" } }?,
+ attribute req_resource_set_ipv4 { xsd:string { maxLength="512000" } }?,
+ attribute req_resource_set_ipv6 { xsd:string { maxLength="512000" } }?,
+ xsd:base64Binary { maxLength="512000" }
+ }
+ issue_response = class
+
+ revoke_request = revocation
+ revoke_response = revocation
+
+ revocation = element key {
+ attribute class_name { xsd:token { maxLength="1024" } },
+ attribute ski { xsd:token { maxLength="1024" } }
+ }
+
+ error_response =
+ element status { xsd:positiveInteger { maxInclusive="999999999999999" } },
+ element last_msg_processed { xsd:positiveInteger { maxInclusive="999999999999999" } }?,
+ element description { attribute xml:lang { xsd:language }, xsd:string { maxLength="1024" } }?
+ }
diff --git a/scripts/up-down-schema.rng b/scripts/up-down-schema.rng
new file mode 100644
index 00000000..749d98e8
--- /dev/null
+++ b/scripts/up-down-schema.rng
@@ -0,0 +1,272 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<grammar ns="http://www.apnic.net/specs/rescerts/up-down/" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+ <start>
+ <element name="message">
+ <attribute name="version">
+ <data type="positiveInteger">
+ <param name="maxInclusive">1</param>
+ </data>
+ </attribute>
+ <attribute name="sender">
+ <data type="token">
+ <param name="maxLength">1024</param>
+ </data>
+ </attribute>
+ <attribute name="recipient">
+ <data type="token">
+ <param name="maxLength">1024</param>
+ </data>
+ </attribute>
+ <attribute name="msg_ref">
+ <data type="positiveInteger">
+ <param name="maxInclusive">999999999999999</param>
+ </data>
+ </attribute>
+ <ref name="payload"/>
+ </element>
+ </start>
+ <define name="payload" combine="choice">
+ <attribute name="type">
+ <value>list</value>
+ </attribute>
+ <ref name="list_request"/>
+ </define>
+ <define name="payload" combine="choice">
+ <attribute name="type">
+ <value>list_response</value>
+ </attribute>
+ <ref name="list_response"/>
+ </define>
+ <define name="payload" combine="choice">
+ <attribute name="type">
+ <value>issue</value>
+ </attribute>
+ <ref name="issue_request"/>
+ </define>
+ <define name="payload" combine="choice">
+ <attribute name="type">
+ <value>issue_response</value>
+ </attribute>
+ <ref name="issue_response"/>
+ </define>
+ <define name="payload" combine="choice">
+ <attribute name="type">
+ <value>revoke</value>
+ </attribute>
+ <ref name="revoke_request"/>
+ </define>
+ <define name="payload" combine="choice">
+ <attribute name="type">
+ <value>revoke_response</value>
+ </attribute>
+ <ref name="revoke_response"/>
+ </define>
+ <define name="payload" combine="choice">
+ <attribute name="type">
+ <value>error_response</value>
+ </attribute>
+ <ref name="error_response"/>
+ </define>
+ <define name="list_request">
+ <empty/>
+ </define>
+ <define name="list_response">
+ <zeroOrMore>
+ <ref name="class"/>
+ </zeroOrMore>
+ </define>
+ <define name="class">
+ <element name="class">
+ <attribute name="class_name">
+ <data type="token">
+ <param name="maxLength">1024</param>
+ </data>
+ </attribute>
+ <attribute name="cert_url">
+ <data type="anyURI">
+ <param name="maxLength">1024</param>
+ </data>
+ </attribute>
+ <attribute name="cert_ski">
+ <data type="token">
+ <param name="maxLength">1024</param>
+ </data>
+ </attribute>
+ <attribute name="resource_set_as">
+ <data type="string">
+ <param name="maxLength">512000</param>
+ </data>
+ </attribute>
+ <attribute name="resource_set_ipv4">
+ <data type="string">
+ <param name="maxLength">512000</param>
+ </data>
+ </attribute>
+ <attribute name="resource_set_ipv6">
+ <data type="string">
+ <param name="maxLength">512000</param>
+ </data>
+ </attribute>
+ <optional>
+ <attribute name="suggested_sia_head">
+ <data type="string">
+ <param name="maxLength">1024</param>
+ </data>
+ </attribute>
+ </optional>
+ <zeroOrMore>
+ <element name="certificate">
+ <attribute name="cert_url">
+ <data type="anyURI">
+ <param name="maxLength">1024</param>
+ </data>
+ </attribute>
+ <attribute name="cert_ski">
+ <data type="token">
+ <param name="maxLength">1024</param>
+ </data>
+ </attribute>
+ <attribute name="cert_aki">
+ <data type="token">
+ <param name="maxLength">1024</param>
+ </data>
+ </attribute>
+ <attribute name="cert_serial">
+ <data type="positiveInteger"/>
+ </attribute>
+ <attribute name="resource_set_as">
+ <data type="string">
+ <param name="maxLength">512000</param>
+ </data>
+ </attribute>
+ <attribute name="resource_set_ipv4">
+ <data type="string">
+ <param name="maxLength">512000</param>
+ </data>
+ </attribute>
+ <attribute name="resource_set_ipv6">
+ <data type="string">
+ <param name="maxLength">512000</param>
+ </data>
+ </attribute>
+ <optional>
+ <attribute name="req_resource_set_as">
+ <data type="string">
+ <param name="maxLength">512000</param>
+ </data>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="req_resource_set_ipv4">
+ <data type="string">
+ <param name="maxLength">512000</param>
+ </data>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="req_resource_set_ipv6">
+ <data type="string">
+ <param name="maxLength">512000</param>
+ </data>
+ </attribute>
+ </optional>
+ <attribute name="status">
+ <choice>
+ <value>undersize</value>
+ <value>match</value>
+ <value>oversize</value>
+ </choice>
+ </attribute>
+ <data type="base64Binary">
+ <param name="maxLength">512000</param>
+ </data>
+ </element>
+ </zeroOrMore>
+ <element name="issuer">
+ <data type="base64Binary">
+ <param name="maxLength">512000</param>
+ </data>
+ </element>
+ </element>
+ </define>
+ <define name="issue_request">
+ <element name="request">
+ <attribute name="class_name">
+ <data type="token">
+ <param name="maxLength">1024</param>
+ </data>
+ </attribute>
+ <optional>
+ <attribute name="req_resource_set_as">
+ <data type="string">
+ <param name="maxLength">512000</param>
+ </data>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="req_resource_set_ipv4">
+ <data type="string">
+ <param name="maxLength">512000</param>
+ </data>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="req_resource_set_ipv6">
+ <data type="string">
+ <param name="maxLength">512000</param>
+ </data>
+ </attribute>
+ </optional>
+ <data type="base64Binary">
+ <param name="maxLength">512000</param>
+ </data>
+ </element>
+ </define>
+ <define name="issue_response">
+ <ref name="class"/>
+ </define>
+ <define name="revoke_request">
+ <ref name="revocation"/>
+ </define>
+ <define name="revoke_response">
+ <ref name="revocation"/>
+ </define>
+ <define name="revocation">
+ <element name="key">
+ <attribute name="class_name">
+ <data type="token">
+ <param name="maxLength">1024</param>
+ </data>
+ </attribute>
+ <attribute name="ski">
+ <data type="token">
+ <param name="maxLength">1024</param>
+ </data>
+ </attribute>
+ </element>
+ </define>
+ <define name="error_response">
+ <element name="status">
+ <data type="positiveInteger">
+ <param name="maxInclusive">999999999999999</param>
+ </data>
+ </element>
+ <optional>
+ <element name="last_msg_processed">
+ <data type="positiveInteger">
+ <param name="maxInclusive">999999999999999</param>
+ </data>
+ </element>
+ </optional>
+ <optional>
+ <element name="description">
+ <attribute name="xml:lang">
+ <data type="language"/>
+ </attribute>
+ <data type="string">
+ <param name="maxLength">1024</param>
+ </data>
+ </element>
+ </optional>
+ </define>
+</grammar>
diff --git a/scripts/xml-parse-test.pl b/scripts/xml-parse-test.pl
index 4811177a..0a7256b0 100755
--- a/scripts/xml-parse-test.pl
+++ b/scripts/xml-parse-test.pl
@@ -9,6 +9,25 @@ use strict;
use XML::Simple;
use Data::Dumper;
use IPC::Open2;
+use Getopt::Long;
+
+my %opt;
+
+if (0) {
+ my $usage = "Use The Source, Luke";
+ die($usage)
+ unless GetOptions(\%opt, qw(encode! decode! schema=s key=s cert=s dir=s))
+ and $opt{encode} + $opt{decode} == 1;
+ die($usage)
+ if $opt{encode} and !$opt{cert} || !$opt{key};
+ die($usage)
+ if $opt{decode} and !$opt{schema} || !$opt{dir};
+} else {
+ $opt{dir} = "biz-certs";
+ $opt{cert} = "biz-certs/Alice-EE.cer";
+ $opt{key} = "biz-certs/Alice-EE.key";
+ $opt{schema} = "up-down-schema.rng";
+}
sub run2 {
my $arg = shift;
@@ -46,6 +65,13 @@ sub decode {
return join('', @res);
}
+sub relaxng {
+ my $xml = shift;
+ my $schema = shift;
+ my @res = run2($xml, qw(xmllint --relaxng), $schema, q(-));
+ return join('', @res);
+}
+
my $xs = XML::Simple->new(KeepRoot => 1,
ForceArray => [qw(list_class)],
KeyAttr => [qw(header)],
@@ -131,11 +157,12 @@ my @xml = ('
for my $xml (@xml) {
print("1: ", $xml, "\n");
print("2: ", Dumper($xs->XMLin($xml)), "\n");
- my $cms = encode($xml, "biz-certs/Alice-EE.cer", "biz-certs/Alice-EE.key");
+ my $cms = encode($xml, $opt{cert}, $opt{key});
print("3: ", $cms, "\n");
- $xml = decode($cms, "biz-certs");
+ $xml = decode($cms, $opt{dir});
print("4: ", $xml, "\n");
print("5: ", Dumper($xs->XMLin($xml)), "\n");
+ print("6: ", relaxng($xml, $opt{schema}), "\n");
# my $x = $xs->XMLin($xml);
# my $t = $xs->XMLout($x);