Skip to content

Commit

Permalink
Add MutualTlsUser request guard
Browse files Browse the repository at this point in the history
  • Loading branch information
akuanti committed Jun 25, 2018
1 parent df77594 commit 3a2bd4b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub mod uri;
#[cfg(feature = "tls")]
pub mod tls;

#[cfg(feature = "tls")]
pub mod mtls;

#[macro_use]
mod docify;
#[macro_use]
Expand Down
13 changes: 13 additions & 0 deletions core/http/src/mtls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use tls::Certificate;

#[derive(Debug)]
pub struct MutualTlsUser {
peer_certs: Vec<Certificate>,
}

impl MutualTlsUser {
/// Get the common name
pub fn name(&self) -> String {
unimplemented!();
}
}
15 changes: 15 additions & 0 deletions core/lib/src/request/from_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use outcome::Outcome::*;

use http::{Status, ContentType, Accept, Method, Cookies};
use http::uri::Uri;
#[cfg(feature = "tls")]
use http::mtls::MutualTlsUser;

/// Type alias for the `Outcome` of a `FromRequest` conversion.
pub type Outcome<S, E> = outcome::Outcome<S, (Status, E), ()>;
Expand Down Expand Up @@ -312,3 +314,16 @@ impl<'a, 'r, T: FromRequest<'a, 'r>> FromRequest<'a, 'r> for Option<T> {
}
}

#[cfg(feature = "tls")]
impl <'a, 'r> FromRequest<'a, 'r> for MutualTlsUser {
type Error = ();

fn from_request(request: &'a Request<'r>) -> Outcome<Self, Self::Error> {
match request.get_peer_certificates() {
Some(certs) => Success(MutualTlsUser {
peer_certs: certs
}),
None => Forward(())
}
}
}

0 comments on commit 3a2bd4b

Please sign in to comment.