Removed things that are now in rpki-rs

This commit is contained in:
Tim Bruijnzeels
2018-09-21 17:01:23 +02:00
parent 51945d9d8e
commit 757e4069e2
6 changed files with 15 additions and 308 deletions
+5 -8
View File
@@ -4,14 +4,11 @@ version = "0.1.0"
authors = ["Tim Bruijnzeels <tim@nlnetlabs.nl>", "Martin Hoffmann <martin@nlnetlabs.nl>"]
[dependencies]
base64 = "^0.9"
hyper = "0.12"
rpki = { git="https://github.com/NLnetLabs/rpki-rs.git" }
base64 = "^0.9"
bytes = "^0.4"
hyper = "0.12"
futures = "0.1"
failure = "^0.1"
xml-rs = "0.8.0"
[features]
# Panic when a parsing error occurs. This feature is intended for
# development use exclusively and MUST NOT be enabled in release builds.
extra-debug = []
xml-rs = "0.8.0"
+3 -2
View File
@@ -1,7 +1,8 @@
extern crate rpki;
extern crate base64;
extern crate bytes;
extern crate core;
#[macro_use] extern crate failure;
extern crate xml;
pub mod oob;
pub mod xml_support;
mod provisioning;
-119
View File
@@ -1,119 +0,0 @@
//
// Support for the RFC8183 out-of-band setup requests and responses
// used to exchange identity and configuration between CAs and their
// parent CA and/or RPKI Publication Servers.
//
use std::io;
use std::path::Path;
use base64;
use xml_support::{XmlReader, XmlReaderErr};
use xml_support::AttributesError;
use base64::DecodeError;
/// Type representing a <publisher_request/>
///
/// For more info see: https://tools.ietf.org/html/rfc8183#section-5.2.3
#[derive(Debug)]
pub struct PublisherRequest {
tag: Option<String>,
publisher_handle: String,
encoded_cert: Vec<u8>,
}
impl PublisherRequest {
pub fn open<P: AsRef<Path>>(path: P)
-> Result<Self, PublisherRequestError> {
let mut r = XmlReader::open(path)?;
r.start_document()?;
let att = r.expect_element("publisher_request")?;
match att.get_opt("version") {
Some(version) => {
if version != "1".to_string() {
return Err(PublisherRequestError::InvalidVersion)
}
},
_ => return Err(PublisherRequestError::InvalidVersion)
}
let tag = att.get_opt("tag");
let publisher_handle = att.get_req("publisher_handle")?;
r.expect_element("publisher_bpki_ta")?;
let base64_cert = r.expect_characters()?;
let encoded_cert = base64::decode_config(&base64_cert, base64::MIME)?;
r.expect_close("publisher_bpki_ta")?;
r.expect_close("publisher_request")?;
r.end_document()?;
Ok(PublisherRequest{tag, publisher_handle, encoded_cert})
}
}
#[derive(Debug, Fail)]
pub enum PublisherRequestError {
#[fail(display = "Invalid XML for Publisher Request")]
InvalidXml,
#[fail(display = "Invalid version for Publisher Request")]
InvalidVersion,
#[fail(display = "Could not parse XML file: {}", _0)]
FileError(io::Error),
#[fail(display = "Invalid XML file: {}", _0)]
XmlReadError(XmlReaderErr),
#[fail(display = "Invalid XML file: {}", _0)]
XmlAttributesError(AttributesError),
#[fail(display = "Invalid base64: {}", _0)]
Base64Error(DecodeError)
}
impl From<io::Error> for PublisherRequestError {
fn from(e: io::Error) -> PublisherRequestError{
PublisherRequestError::FileError(e)
}
}
impl From<XmlReaderErr> for PublisherRequestError {
fn from(e: XmlReaderErr) -> PublisherRequestError{
PublisherRequestError::XmlReadError(e)
}
}
impl From<AttributesError> for PublisherRequestError {
fn from(e: AttributesError) -> PublisherRequestError{
PublisherRequestError::XmlAttributesError(e)
}
}
impl From<DecodeError> for PublisherRequestError {
fn from(e: DecodeError) -> PublisherRequestError {
PublisherRequestError::Base64Error(e)
}
}
#[cfg(test)]
mod tests {
use super::*;
# [test]
fn test_parse_publisher_request() {
let pr = PublisherRequest::open("test/publisher_request.xml").unwrap();
assert_eq!("Bob", pr.publisher_handle);
assert_eq!(Some("A0001".to_string()), pr.tag);
}
}
+7
View File
@@ -0,0 +1,7 @@
use rpki::remote::idcert::IdCert;
/// This type defines Client CAs that are allowed to publish.
pub struct Client {
id: IdCert
}
-154
View File
@@ -1,154 +0,0 @@
// Some convenience stuff for handling the RPKI xml structures
use std::{fs, io};
use std::path::Path;
use xml::EventReader;
use xml::ParserConfig;
use xml::reader::XmlEvent;
use xml::attribute::OwnedAttribute;
/// Wrapper for convenient XML parsing
///
/// This type only exposes things we need for the RPKI XML structures.
pub struct XmlReader<R: io::Read> {
reader: EventReader<R>
}
impl <R: io::Read> XmlReader<R> {
pub fn create(source: R) -> Result<Self, io::Error> {
let mut config = ParserConfig::new();
config.trim_whitespace = true;
config.ignore_comments = true;
let reader = config.create_reader(source);
Ok(XmlReader{reader})
}
pub fn start_document(&mut self) -> Result<bool, XmlReaderErr> {
match self.reader.next() {
Ok(XmlEvent::StartDocument {..}) => { Ok(true)},
_ => return Err(XmlReaderErr::ExpectedStartDocument)
}
}
pub fn expect_element(
&mut self,
exp: &str) -> Result<Attributes, XmlReaderErr> {
match self.reader.next() {
Ok(XmlEvent::StartElement { name, attributes, ..}) => {
if name.local_name == exp {
Ok(Attributes{attributes})
} else {
Err(XmlReaderErr::ExpectedStart(exp.to_string()))
}
},
_ => return Err(XmlReaderErr::ExpectedStart(exp.to_string()))
}
}
pub fn expect_close(&mut self, exp: &str) -> Result<bool, XmlReaderErr> {
match self.reader.next() {
Ok(XmlEvent::EndElement { name, ..}) => {
if name.local_name == exp {
Ok(true)
} else {
Err(XmlReaderErr::ExpectedClose(exp.to_string()))
}
}
_ => Err(XmlReaderErr::ExpectedClose(exp.to_string()))
}
}
pub fn expect_characters(&mut self) -> Result<String, XmlReaderErr> {
match self.reader.next() {
Ok(XmlEvent::Characters(chars)) => { Ok(chars) }
_ => return Err(XmlReaderErr::ExpectedCharacters)
}
}
pub fn end_document(&mut self) -> Result<bool, XmlReaderErr> {
match self.reader.next() {
Ok(XmlEvent::EndDocument) => Ok(true),
_ => Err(XmlReaderErr::ExpectedEnd)
}
}
}
impl XmlReader<fs::File> {
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, io::Error> {
Self::create(fs::File::open(path)?)
}
}
#[derive(Debug, Fail)]
pub enum XmlReaderErr {
#[fail(display = "Expected Start of Document")]
ExpectedStartDocument,
#[fail(display = "Expected Start Element with name: {}", _0)]
ExpectedStart(String),
#[fail(display = "Expected Characters Element")]
ExpectedCharacters,
#[fail(display = "Expected Close Element with name: {}", _0)]
ExpectedClose(String),
#[fail(display = "Expected End of Document")]
ExpectedEnd
}
/// Wrapper for XML tag attributes
pub struct Attributes {
attributes: Vec<OwnedAttribute>
}
impl Attributes {
pub fn get_opt(&self, name: &str) -> Option<String> {
self.attributes.iter()
.find(|a| a.name.local_name == name)
.map(|a| a.value.to_string())
}
pub fn get_req(&self, name: &str) -> Result<String, AttributesError> {
self.get_opt(name)
.ok_or(AttributesError::MissingAttribute(name.to_string()))
}
}
#[derive(Debug, Fail)]
pub enum AttributesError {
#[fail(display = "Required attribute missing: {}", _0)]
MissingAttribute(String),
}
#[cfg(test)]
mod tests {
use super::*;
# [test]
fn test_parse_publisher_request() {
let mut r = XmlReader::open("test/publisher_request.xml").unwrap();
r.start_document().unwrap();
let att = r.expect_element("publisher_request").unwrap();
assert_eq!(Some("1".to_string()), att.get_opt("version"));
assert_eq!(Some("A0001".to_string()), att.get_opt("tag"));
assert_eq!(Some("Bob".to_string()), att.get_opt("publisher_handle"));
let ta_att = r.expect_element("publisher_bpki_ta").unwrap();
assert_eq!(0, ta_att.attributes.len());
let chars = r.expect_characters().unwrap();
assert!(chars.starts_with("MIIDIDCCAg"));
r.expect_close("publisher_bpki_ta").unwrap();
r.expect_close("publisher_request").unwrap();
r.end_document().unwrap();
}
}
-25
View File
@@ -1,25 +0,0 @@
<publisher_request
xmlns="http://www.hactrn.net/uris/rpki/rpki-setup/"
version="1"
tag="A0001"
publisher_handle="Bob">
<publisher_bpki_ta>
MIIDIDCCAgigAwIBAgIBATANBgkqhkiG9w0BAQsFADApMScwJQYDVQQDEx5Cb2Ig
QlBLSSBSZXNvdXJjZSBUcnVzdCBBbmNob3IwHhcNMTEwNzAxMDQwNzIzWhcNMTIw
NjMwMDQwNzIzWjApMScwJQYDVQQDEx5Cb2IgQlBLSSBSZXNvdXJjZSBUcnVzdCBB
bmNob3IwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDEk1f7cVzHu3r/
fJ5gkBxnWMNJ1CP0kPtfP8oFOEVVH1lX0MHuFKhdKA4W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