diff --git a/src/connection/builder.rs b/src/connection/builder.rs index 84170f6..ca7b760 100644 --- a/src/connection/builder.rs +++ b/src/connection/builder.rs @@ -1,20 +1,23 @@ -use super::verifier::Verifier; -use crate::prelude::CertificateStore; -use std::net::TcpStream; +use super::{Verifier, FingerPrintStore}; +use rustls::ServerConfig; +use std::{net::TcpStream, sync::Arc}; #[derive(Debug)] -pub struct Builder { +pub struct Builder { pub stream: Option, pub verifier: Option>, } -impl Default for Builder { +impl Default for Builder { fn default() -> Self { - Self { stream: None, verifier: None } + Self { + stream: None, + verifier: None, + } } } -impl Builder { +impl Builder { pub fn new() -> Self { Self::default() } @@ -29,7 +32,12 @@ impl Builder { self } - pub fn build(self) -> super::Connection { + pub fn build(self) -> Result { + let cfg = ServerConfig::builder() + .with_safe_default_cipher_suites() + .with_safe_default_kx_groups() + .with_safe_default_protocol_versions()? + .with_client_cert_verifier(Arc::new(self.verifier.unwrap())); todo!() } } diff --git a/src/connection/error.rs b/src/connection/error.rs index 8b13789..8680f09 100644 --- a/src/connection/error.rs +++ b/src/connection/error.rs @@ -1 +1,2 @@ - +#[derive(Debug)] +pub struct Error; diff --git a/src/connection/mod.rs b/src/connection/mod.rs index 7b6fecc..ea8b4f0 100644 --- a/src/connection/mod.rs +++ b/src/connection/mod.rs @@ -2,10 +2,11 @@ pub mod builder; pub mod error; pub mod verifier; +pub use self::{builder::Builder, error::Error, verifier::{FingerPrintStore, Verifier}}; + #[derive(Debug)] pub struct Connection { pub inner: rustls::ServerConnection, } -impl Connection { -} +impl Connection {} diff --git a/src/connection/verifier.rs b/src/connection/verifier.rs index e16c01a..c98bbc8 100644 --- a/src/connection/verifier.rs +++ b/src/connection/verifier.rs @@ -1,7 +1,30 @@ -use crate::prelude::CertificateStore; +use rustls::server::ClientCertVerifier; + +use crate::{prelude::CertificateStore, mailuser::Mailuser}; use std::sync::Mutex; #[derive(Debug)] -pub struct Verifier { +pub struct Verifier { pub store: Mutex, } + +pub trait FingerPrintStore: Send + Sync { + fn get_mailuser(&self, fingerprint: &str) -> Option; + fn insert_mailuser(&mut self, fingerprint: &str, user: &str) -> Option; + fn contains_mailuser(&self, fingerprint: &str) -> bool; +} + +impl ClientCertVerifier for Verifier { + fn client_auth_root_subjects(&self) -> &[rustls::DistinguishedName] { + todo!() + } + + fn verify_client_cert( + &self, + end_entity: &rustls::Certificate, + intermediates: &[rustls::Certificate], + now: std::time::SystemTime, + ) -> Result { + todo!() + } +} diff --git a/src/mailstore/mod.rs b/src/mailstore/mod.rs index eafe519..976217f 100644 --- a/src/mailstore/mod.rs +++ b/src/mailstore/mod.rs @@ -86,9 +86,7 @@ impl MailStore for Domain { } fn has_mailuser(&self, mailuser: &str) -> bool { - self.users() - .iter() - .any(|x| x.username == mailuser) + self.users().iter().any(|x| x.username == mailuser) } fn get_folder(&self, user: &str, folder: &str) -> Option { diff --git a/src/message/link.rs b/src/message/link.rs index 2ee0e92..10df54f 100644 --- a/src/message/link.rs +++ b/src/message/link.rs @@ -27,9 +27,15 @@ impl FromStr for Link { return Err(super::Error::MalformedLink); }; if let Some((url, display)) = s.split_once(char::is_whitespace) { - Ok(Self { url: url.to_string(), display: Some(display.to_string()) }) + Ok(Self { + url: url.to_string(), + display: Some(display.to_string()), + }) } else { - Ok(Self { url: s.to_string(), display: None }) + Ok(Self { + url: s.to_string(), + display: None, + }) } } }