From 435330b4153fff545a063efe8e5d2617abb0b1ef Mon Sep 17 00:00:00 2001 From: Emi Tatsuo Date: Fri, 20 Nov 2020 09:40:57 -0500 Subject: [PATCH 1/4] Made Request::document a bit more generic Also how did I not know about the Borrow trait until now??? --- src/types/body.rs | 8 +++++--- src/types/response.rs | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/types/body.rs b/src/types/body.rs index d2da102..a7481c3 100644 --- a/src/types/body.rs +++ b/src/types/body.rs @@ -2,6 +2,8 @@ use tokio::io::AsyncRead; #[cfg(feature="serve_dir")] use tokio::fs::File; +use std::borrow::Borrow; + use crate::types::Document; pub enum Body { @@ -9,9 +11,9 @@ pub enum Body { Reader(Box), } -impl From for Body { - fn from(document: Document) -> Self { - Self::from(document.to_string()) +impl> From for Body { + fn from(document: D) -> Self { + Self::from(document.borrow().to_string()) } } diff --git a/src/types/response.rs b/src/types/response.rs index 991d511..ce1b5b6 100644 --- a/src/types/response.rs +++ b/src/types/response.rs @@ -1,4 +1,5 @@ use std::convert::TryInto; +use std::borrow::Borrow; use anyhow::*; use uriparse::URIReference; @@ -19,7 +20,7 @@ impl Response { } } - pub fn document(document: Document) -> Self { + pub fn document(document: impl Borrow) -> Self { Self::success_with_body(&GEMINI_MIME, document) } From 3296d00ec3530a05c81c1ebc95d642037b3ded16 Mon Sep 17 00:00:00 2001 From: Emi Tatsuo Date: Fri, 20 Nov 2020 09:51:37 -0500 Subject: [PATCH 2/4] Add From> to Response This allows users to call &mut Document.into() in order to create a response, so that you can do it right in the middle of one of those builder call chain thingies --- examples/document.rs | 10 ++++------ src/types/response.rs | 6 ++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/document.rs b/examples/document.rs index 8ff6bbb..e2e685b 100644 --- a/examples/document.rs +++ b/examples/document.rs @@ -18,9 +18,7 @@ async fn main() -> Result<()> { fn handle_request(_request: Request) -> BoxFuture<'static, Result> { async move { - let mut document = Document::new(); - - document + let response = Document::new() .add_preformatted(include_str!("northstar_logo.txt")) .add_blank_line() .add_link("https://docs.rs/northstar", "Documentation") @@ -43,9 +41,9 @@ fn handle_request(_request: Request) -> BoxFuture<'static, Result> { .add_preformatted_with_alt("sh", concat!( "mkdir cert && cd cert\n", "openssl req -x509 -nodes -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365", - )); - - Ok(Response::document(document)) + )) + .into(); + Ok(response) } .boxed() } diff --git a/src/types/response.rs b/src/types/response.rs index ce1b5b6..dceec4e 100644 --- a/src/types/response.rs +++ b/src/types/response.rs @@ -95,3 +95,9 @@ impl Response { self.body.take() } } + +impl> From for Response { + fn from(doc: D) -> Self { + Self::document(doc) + } +} From 20181cce96f39663d8453dbb65f4be5a94040121 Mon Sep 17 00:00:00 2001 From: Emi Tatsuo Date: Fri, 20 Nov 2020 09:58:43 -0500 Subject: [PATCH 3/4] Updated changelog --- CHANGELOG.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47c5d1b..472fd82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,15 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - `document` API for creating Gemini documents -- preliminary timeout API, incl a special case for complex MIMEs by [@Alch-Emi](https://github.com/Alch-Emi) -- `Response::success_with_body` by [@Alch-Emi](https://github.com/Alch-Emi) +- preliminary timeout API, incl a special case for complex MIMEs by [@Alch-Emi] +- `Response::success_with_body` by [@Alch-Emi] - `redirect_temporary_lossy` for `Response` and `ResponseHeader` - `bad_request_lossy` for `Response` and `ResponseHeader` - support for a lot more mime-types in `guess_mime_from_path`, backed by the `mime_guess` crate -- customizable TLS cert & key paths by [@Alch-Emi](https://github.com/Alch-Emi) -- `server_dir` default feature for serve_dir utils [@Alch-Emi](https://github.com/Alch-Emi) +- customizable TLS cert & key paths by [@Alch-Emi] +- `server_dir` default feature for serve_dir utils [@Alch-Emi] +- Docments can be converted into responses with std::convert::Into [@Alch-Emi] ### Improved -- build time and size by [@Alch-Emi](https://github.com/Alch-Emi) +- build time and size by [@Alch-Emi] ## [0.3.0] - 2020-11-14 ### Added @@ -34,4 +35,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.2.0] - 2020-11-14 ### Added -- Access to client certificates by [@Alch-Emi](https://github.com/Alch-Emi) +- Access to client certificates by [@Alch-Emi] + +[@Alch-Emi]: https://github.com/Alch-Emi From 4d0b0521d67e7e692d7757de2a712ebad540d289 Mon Sep 17 00:00:00 2001 From: Ben Aaron Goldberg Date: Sat, 21 Nov 2020 23:45:05 -0500 Subject: [PATCH 4/4] Include a workaround for a bug with rustls & webpki --- src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b8e00d6..a014a8a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,7 @@ use tokio::{ }; use tokio::net::TcpListener; use rustls::ClientCertVerifier; +use rustls::internal::msgs::handshake::DigitallySignedStruct; use tokio_rustls::{rustls, TlsAcceptor}; use rustls::*; use anyhow::*; @@ -434,6 +435,8 @@ impl ClientCertVerifier for AllowAnonOrSelfsignedClient { Some(false) } + // the below methods are a hack until webpki doesn't break with certain certs + fn verify_client_cert( &self, _: &[Certificate], @@ -441,6 +444,24 @@ impl ClientCertVerifier for AllowAnonOrSelfsignedClient { ) -> Result { Ok(ClientCertVerified::assertion()) } + + fn verify_tls12_signature( + &self, + _message: &[u8], + _cert: &Certificate, + _dss: &DigitallySignedStruct, + ) -> Result { + Ok(HandshakeSignatureValid::assertion()) + } + + fn verify_tls13_signature( + &self, + _message: &[u8], + _cert: &Certificate, + _dss: &DigitallySignedStruct, + ) -> Result { + Ok(HandshakeSignatureValid::assertion()) + } } #[cfg(test)]