From 4549cd57b14f089d094ea1bf1569cfd7aa6fb03e Mon Sep 17 00:00:00 2001 From: Tim Bruijnzeels Date: Tue, 8 Jan 2019 15:30:03 +0100 Subject: [PATCH] Restructuring modules --- src/client/pubc.rs | 7 +- src/daemon/api/auth.rs | 7 +- src/daemon/api/data.rs | 2 +- src/daemon/http/server.rs | 8 +- src/daemon/mod.rs | 2 + .../publishers.rs} | 109 +++++++++++++++++- src/{publishing => daemon}/pubserver.rs | 9 +- src/daemon/responder.rs | 5 +- src/lib.rs | 1 - src/publishing/info.rs | 108 ----------------- src/publishing/mod.rs | 4 - src/publishing/publisher.rs | 105 ----------------- src/remote/id.rs | 106 +++++++++++++++++ 13 files changed, 229 insertions(+), 244 deletions(-) rename src/{publishing/publisher_store.rs => daemon/publishers.rs} (87%) rename src/{publishing => daemon}/pubserver.rs (98%) delete mode 100644 src/publishing/info.rs delete mode 100644 src/publishing/mod.rs delete mode 100644 src/publishing/publisher.rs diff --git a/src/client/pubc.rs b/src/client/pubc.rs index fb233333..bc323f85 100644 --- a/src/client/pubc.rs +++ b/src/client/pubc.rs @@ -15,9 +15,8 @@ use rpki::x509::ValidationError; use toml; use crate::file; use crate::file::{CurrentFile, RecursorError}; -use crate::publishing::info::{MyRepoInfo, ParentInfo}; use crate::remote::builder::{IdCertBuilder, SignedMessageBuilder}; -use crate::remote::id::MyIdentity; +use crate::remote::id::{MyIdentity, MyRepoInfo, ParentInfo}; use crate::remote::oob::{PublisherRequest, RepositoryResponse}; use crate::remote::publication::pubmsg::{Message, MessageError, ReplyMessage}; use crate::remote::publication::reply::{ErrorReply, ListReply}; @@ -610,8 +609,8 @@ impl From for Error { mod tests { use super::*; use test; - use publishing::pubserver::PubServer; - use daemon::api::auth::Authorizer; + use crate::daemon::api::auth::Authorizer; + use crate::daemon::pubserver::PubServer; fn test_server(work_dir: &PathBuf, xml_dir: &PathBuf) -> PubServer { // Start up a server diff --git a/src/daemon/api/auth.rs b/src/daemon/api/auth.rs index 7ac54948..83942937 100644 --- a/src/daemon/api/auth.rs +++ b/src/daemon/api/auth.rs @@ -1,11 +1,10 @@ //! Authorization for the API -use std::sync::Arc; -use std::sync::{RwLock, RwLockReadGuard}; +use std::sync::{Arc, RwLock, RwLockReadGuard}; use actix_web::{HttpResponse, HttpRequest, Result}; -use actix_web::middleware::{Middleware, Started}; -use crate::publishing::pubserver::PubServer; use actix_web::http::HeaderMap; +use actix_web::middleware::{Middleware, Started}; +use crate::daemon::pubserver::PubServer; pub struct CheckAuthorisation; diff --git a/src/daemon/api/data.rs b/src/daemon/api/data.rs index 3e1207a3..aa0a6c5d 100644 --- a/src/daemon/api/data.rs +++ b/src/daemon/api/data.rs @@ -1,8 +1,8 @@ //! Support for the Json API use std::sync::Arc; +use crate::daemon::publishers::Publisher; use crate::ext_serde; -use crate::publishing::publisher::Publisher; use crate::rpki::uri; //------------ Link ---------------------------------------------------------- diff --git a/src/daemon/http/server.rs b/src/daemon/http/server.rs index 6f220d3b..3c3a40e8 100644 --- a/src/daemon/http/server.rs +++ b/src/daemon/http/server.rs @@ -16,9 +16,9 @@ use crate::daemon::api::auth::{Authorizer, CheckAuthorisation}; use crate::daemon::api::data::{PublisherDetails, PublisherList}; use crate::daemon::config::Config; use crate::daemon::http::ssl; -use crate::publishing::publisher_store; -use crate::publishing::pubserver; -use crate::publishing::pubserver::PubServer; +use crate::daemon::publishers; +use crate::daemon::pubserver; +use crate::daemon::pubserver::PubServer; use crate::remote::sigmsg::SignedMessage; const NOT_FOUND: &'static [u8] = include_bytes!("../../../static/html/404.html"); @@ -236,7 +236,7 @@ impl PubServerApp { .body(res.encode_vec()) }, Err(pubserver::Error::PublisherStoreError - (publisher_store::Error::UnknownPublisher(_))) => { + (publishers::Error::UnknownPublisher(_))) => { Self::p404(req) }, Err(e) => { diff --git a/src/daemon/mod.rs b/src/daemon/mod.rs index 74b03c6e..462235f3 100644 --- a/src/daemon/mod.rs +++ b/src/daemon/mod.rs @@ -1,4 +1,6 @@ pub mod api; pub mod http; pub mod config; +pub mod pubserver; +pub mod publishers; pub mod responder; diff --git a/src/publishing/publisher_store.rs b/src/daemon/publishers.rs similarity index 87% rename from src/publishing/publisher_store.rs rename to src/daemon/publishers.rs index 24cfadea..caa461f5 100644 --- a/src/publishing/publisher_store.rs +++ b/src/daemon/publishers.rs @@ -1,4 +1,5 @@ -//! Responsible for storing and retrieving Publisher information. +//! Types for tracking configured publishers. + use std::collections::HashMap; use std::fs; use std::fs::File; @@ -7,12 +8,112 @@ use std::io::BufReader; use std::path::PathBuf; use std::sync::Arc; use rpki::uri; +use crate::ext_serde; use crate::remote::id::IdCert; use crate::remote::oob::{PublisherRequest, PublisherRequestError}; -use crate::publishing::publisher::Publisher; use crate::storage::keystore::{self, Info, Key, KeyStore}; use crate::storage::caching_ks::CachingDiskKeyStore; +//------------ Publisher ----------------------------------------------------- + +/// This type defines Publisher CAs that are allowed to publish. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Publisher { + // The optional tag in the request. None maps to empty string. + tag: String, + + name: String, + + #[serde( + deserialize_with = "ext_serde::de_rsync_uri", + serialize_with = "ext_serde::ser_rsync_uri")] + base_uri: uri::Rsync, + + #[serde( + deserialize_with = "ext_serde::de_http_uri", + serialize_with = "ext_serde::ser_http_uri")] + service_uri: uri::Http, + + #[serde( + deserialize_with = "ext_serde::de_id_cert", + serialize_with = "ext_serde::ser_id_cert")] + id_cert: IdCert +} + +impl Publisher { + pub fn new( + tag: Option, + name: String, + base_uri: uri::Rsync, + service_uri: uri::Http, + id_cert: IdCert + ) -> Self { + + let tag = match tag { + None => "".to_string(), + Some(t) => t + }; + + Publisher { + tag, + name, + base_uri, + service_uri, + id_cert + } + } + + /// Returns a new Publisher that is the same as this Publisher, except + /// that it has an updated IdCert + pub fn with_new_id_cert(&self, id_cert: IdCert) -> Self { + Publisher { + tag: self.tag.clone(), + name: self.name.clone(), + base_uri: self.base_uri.clone(), + service_uri: self.service_uri.clone(), + id_cert + } + } +} + +impl Publisher { + pub fn tag(&self) -> Option { + let tag = &self.tag; + if tag.is_empty() { + None + } else { + Some(tag.clone()) + } + } + + pub fn name(&self) -> &String { + &self.name + } + + pub fn base_uri(&self) -> &uri::Rsync { + &self.base_uri + } + + pub fn service_uri(&self) -> &uri::Http { + &self.service_uri + } + + pub fn id_cert(&self) -> &IdCert { + &self.id_cert + } +} + +impl PartialEq for Publisher { + fn eq(&self, other: &Publisher) -> bool { + self.name == other.name && + self.base_uri == other.base_uri && + self.service_uri == other.service_uri && + self.id_cert.to_bytes() == other.id_cert.to_bytes() + } +} + +impl Eq for Publisher {} + //------------ PublisherList ------------------------------------------------- @@ -303,7 +404,7 @@ pub enum Error { IoError(io::Error), #[fail(display = - "The '/' in publisher_handle ({}) is not supported - because we \ + "The '/' in publisher_handle ({}) is not supported - because we \ are deriving the base directory for a publisher from this. This \ behaviour may be updated in future.", _0)] ForwardSlashInHandle(String), @@ -558,5 +659,5 @@ mod tests { ).is_err()); }) } - } + diff --git a/src/publishing/pubserver.rs b/src/daemon/pubserver.rs similarity index 98% rename from src/publishing/pubserver.rs rename to src/daemon/pubserver.rs index 2c02c62e..262cc778 100644 --- a/src/publishing/pubserver.rs +++ b/src/daemon/pubserver.rs @@ -8,8 +8,7 @@ use rpki::uri; use rpki::x509::ValidationError; use crate::daemon::api::auth::Authorizer; use crate::daemon::responder::{self, Responder}; -use crate::publishing::publisher::Publisher; -use crate::publishing::publisher_store::{self, PublisherStore}; +use crate::daemon::publishers::{self, Publisher, PublisherStore}; use crate::repo::file_store; use crate::repo::repository::{self, Repository}; use crate::repo::rrdp; @@ -248,7 +247,7 @@ pub enum Error { ResponderError(responder::Error), #[fail(display="{}", _0)] - PublisherStoreError(publisher_store::Error), + PublisherStoreError(publishers::Error), #[fail(display="{}", _0)] RepositoryError(repository::Error), @@ -266,8 +265,8 @@ impl From for Error { } } -impl From for Error { - fn from(e: publisher_store::Error) -> Self { +impl From for Error { + fn from(e: publishers::Error) -> Self { Error::PublisherStoreError(e) } } diff --git a/src/daemon/responder.rs b/src/daemon/responder.rs index 8016c230..c691504d 100644 --- a/src/daemon/responder.rs +++ b/src/daemon/responder.rs @@ -7,7 +7,7 @@ use bcder::encode::Values; use rpki::signing::PublicKeyAlgorithm; use rpki::signing::signer::{Signer, CreateKeyError, KeyUseError}; use rpki::uri; -use crate::publishing::publisher::Publisher; +use crate::daemon::publishers::Publisher; use crate::remote::id::MyIdentity; use crate::remote::oob::RepositoryResponse; use crate::remote::publication::pubmsg::Message; @@ -43,9 +43,6 @@ pub struct Responder { // key value store for server specific stuff store: CachingDiskKeyStore, - - // TODO: Store in keystore? - // The URI that publishers need to access to publish (see config) service_uri: uri::Http, diff --git a/src/lib.rs b/src/lib.rs index 4a4ba04b..effc3340 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,7 +28,6 @@ extern crate untrusted; pub mod client; pub mod daemon; -pub mod publishing; pub mod remote; pub mod repo; pub mod signing; diff --git a/src/publishing/info.rs b/src/publishing/info.rs deleted file mode 100644 index 22ebbf69..00000000 --- a/src/publishing/info.rs +++ /dev/null @@ -1,108 +0,0 @@ -use ext_serde; -use rpki::uri; -use crate::remote::id::IdCert; - - -//------------ ParentInfo ---------------------------------------------------- - -/// This type stores details about a parent publication server: in -/// particular, its identity and where it may be contacted. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct ParentInfo { - publisher_handle: String, - - #[serde( - deserialize_with = "ext_serde::de_id_cert", - serialize_with = "ext_serde::ser_id_cert")] - id_cert: IdCert, - - #[serde( - deserialize_with = "ext_serde::de_http_uri", - serialize_with = "ext_serde::ser_http_uri")] - service_uri: uri::Http, -} - -impl ParentInfo { - pub fn new( - publisher_handle: String, - id_cert: IdCert, - service_uri: uri::Http, - ) -> Self { - ParentInfo { - publisher_handle, - id_cert, - service_uri, - } - } - - /// The Identity Certificate used by the parent. - pub fn id_cert(&self) -> &IdCert { - &self.id_cert - } - - /// The service URI where the client should send requests. - pub fn service_uri(&self) -> &uri::Http { - &self.service_uri - } - - /// The name the publication server prefers to go by - pub fn publisher_handle(&self) -> &String { - &self.publisher_handle - } -} - -impl PartialEq for ParentInfo { - fn eq(&self, other: &ParentInfo) -> bool { - self.id_cert.to_bytes() == other.id_cert.to_bytes() && - self.service_uri == other.service_uri && - self.publisher_handle == other.publisher_handle - } -} - -impl Eq for ParentInfo {} - - -//------------ MyRepoInfo ---------------------------------------------------- - -/// This type stores details about the repository URIs available to a -/// publisher. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct MyRepoInfo { - #[serde( - deserialize_with = "ext_serde::de_rsync_uri", - serialize_with = "ext_serde::ser_rsync_uri")] - sia_base: uri::Rsync, - - #[serde( - deserialize_with = "ext_serde::de_http_uri", - serialize_with = "ext_serde::ser_http_uri")] - notify_sia: uri::Http -} - -impl MyRepoInfo { - pub fn new( - sia_base: uri::Rsync, - notify_sia: uri::Http - ) -> Self { - MyRepoInfo { sia_base, notify_sia } - } - - /// The base rsync directory under which the publisher may publish. - // XXX TODO: Read whether standards allow sub-dirs - pub fn sia_base(&self) -> &uri::Rsync { - &self.sia_base - } - - pub fn notify_sia(&self) -> &uri::Http { - &self.notify_sia - } -} - -impl PartialEq for MyRepoInfo { - fn eq(&self, other: &MyRepoInfo) -> bool { - self.sia_base == other.sia_base && - self.notify_sia == other.notify_sia - } -} - -impl Eq for MyRepoInfo {} diff --git a/src/publishing/mod.rs b/src/publishing/mod.rs deleted file mode 100644 index f427fada..00000000 --- a/src/publishing/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod info; -pub mod publisher; -pub mod publisher_store; -pub mod pubserver; \ No newline at end of file diff --git a/src/publishing/publisher.rs b/src/publishing/publisher.rs deleted file mode 100644 index 6a25206c..00000000 --- a/src/publishing/publisher.rs +++ /dev/null @@ -1,105 +0,0 @@ -//! Responsible for storing and retrieving Publisher information. -use ext_serde; -use rpki::uri; -use crate::remote::id::IdCert; - - -//------------ Publisher ----------------------------------------------------- - -/// This type defines Publisher CAs that are allowed to publish. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct Publisher { - // The optional tag in the request. None maps to empty string. - tag: String, - - name: String, - - #[serde( - deserialize_with = "ext_serde::de_rsync_uri", - serialize_with = "ext_serde::ser_rsync_uri")] - base_uri: uri::Rsync, - - #[serde( - deserialize_with = "ext_serde::de_http_uri", - serialize_with = "ext_serde::ser_http_uri")] - service_uri: uri::Http, - - #[serde( - deserialize_with = "ext_serde::de_id_cert", - serialize_with = "ext_serde::ser_id_cert")] - id_cert: IdCert -} - -impl Publisher { - pub fn new( - tag: Option, - name: String, - base_uri: uri::Rsync, - service_uri: uri::Http, - id_cert: IdCert - ) -> Self { - - let tag = match tag { - None => "".to_string(), - Some(t) => t - }; - - Publisher { - tag, - name, - base_uri, - service_uri, - id_cert - } - } - - /// Returns a new Publisher that is the same as this Publisher, except - /// that it has an updated IdCert - pub fn with_new_id_cert(&self, id_cert: IdCert) -> Self { - Publisher { - tag: self.tag.clone(), - name: self.name.clone(), - base_uri: self.base_uri.clone(), - service_uri: self.service_uri.clone(), - id_cert - } - } -} - -impl Publisher { - pub fn tag(&self) -> Option { - let tag = &self.tag; - if tag.is_empty() { - None - } else { - Some(tag.clone()) - } - } - - pub fn name(&self) -> &String { - &self.name - } - - pub fn base_uri(&self) -> &uri::Rsync { - &self.base_uri - } - - pub fn service_uri(&self) -> &uri::Http { - &self.service_uri - } - - pub fn id_cert(&self) -> &IdCert { - &self.id_cert - } -} - -impl PartialEq for Publisher { - fn eq(&self, other: &Publisher) -> bool { - self.name == other.name && - self.base_uri == other.base_uri && - self.service_uri == other.service_uri && - self.id_cert.to_bytes() == other.id_cert.to_bytes() - } -} - -impl Eq for Publisher {} diff --git a/src/remote/id.rs b/src/remote/id.rs index 86c2e424..fb04e488 100644 --- a/src/remote/id.rs +++ b/src/remote/id.rs @@ -7,6 +7,7 @@ use rpki::cert::{SubjectPublicKeyInfo, Validity}; use rpki::cert::ext::{AuthorityKeyIdentifier, BasicCa, SubjectKeyIdentifier}; use rpki::signing::SignatureAlgorithm; use rpki::signing::signer::KeyId; +use rpki::uri; use rpki::x509::{Name, SignedData, Time, ValidationError}; use crate::ext_serde; @@ -67,6 +68,111 @@ impl PartialEq for MyIdentity { impl Eq for MyIdentity {} +//------------ ParentInfo ---------------------------------------------------- + +/// This type stores details about a parent publication server: in +/// particular, its identity and where it may be contacted. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ParentInfo { + publisher_handle: String, + + #[serde( + deserialize_with = "ext_serde::de_id_cert", + serialize_with = "ext_serde::ser_id_cert")] + id_cert: IdCert, + + #[serde( + deserialize_with = "ext_serde::de_http_uri", + serialize_with = "ext_serde::ser_http_uri")] + service_uri: uri::Http, +} + +impl ParentInfo { + pub fn new( + publisher_handle: String, + id_cert: IdCert, + service_uri: uri::Http, + ) -> Self { + ParentInfo { + publisher_handle, + id_cert, + service_uri, + } + } + + /// The Identity Certificate used by the parent. + pub fn id_cert(&self) -> &IdCert { + &self.id_cert + } + + /// The service URI where the client should send requests. + pub fn service_uri(&self) -> &uri::Http { + &self.service_uri + } + + /// The name the publication server prefers to go by + pub fn publisher_handle(&self) -> &String { + &self.publisher_handle + } +} + +impl PartialEq for ParentInfo { + fn eq(&self, other: &ParentInfo) -> bool { + self.id_cert.to_bytes() == other.id_cert.to_bytes() && + self.service_uri == other.service_uri && + self.publisher_handle == other.publisher_handle + } +} + +impl Eq for ParentInfo {} + + +//------------ MyRepoInfo ---------------------------------------------------- + +/// This type stores details about the repository URIs available to a +/// publisher. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct MyRepoInfo { + #[serde( + deserialize_with = "ext_serde::de_rsync_uri", + serialize_with = "ext_serde::ser_rsync_uri")] + sia_base: uri::Rsync, + + #[serde( + deserialize_with = "ext_serde::de_http_uri", + serialize_with = "ext_serde::ser_http_uri")] + notify_sia: uri::Http +} + +impl MyRepoInfo { + pub fn new( + sia_base: uri::Rsync, + notify_sia: uri::Http + ) -> Self { + MyRepoInfo { sia_base, notify_sia } + } + + /// The base rsync directory under which the publisher may publish. + // XXX TODO: Read whether standards allow sub-dirs + pub fn sia_base(&self) -> &uri::Rsync { + &self.sia_base + } + + pub fn notify_sia(&self) -> &uri::Http { + &self.notify_sia + } +} + +impl PartialEq for MyRepoInfo { + fn eq(&self, other: &MyRepoInfo) -> bool { + self.sia_base == other.sia_base && + self.notify_sia == other.notify_sia + } +} + +impl Eq for MyRepoInfo {} + + //------------ IdCert -------------------------------------------------------- /// An Identity Certificate.