1 parent
a238ff5e23
commit
93762fe9ef
65 files changed
+5420
-2792
No files matched your search
@@ -23,11 +23,13 @@ pub struct AccountSession {
|
||||
pub imap_host: String,
|
||||
pub imap_port: u16,
|
||||
pub imap_tls: bool,
|
||||
pub imap_tls_verify: bool,
|
||||
pub smtp_host: String,
|
||||
#[allow(dead_code)]
|
||||
pub smtp_port: u16,
|
||||
#[allow(dead_code)]
|
||||
pub smtp_tls: bool,
|
||||
pub smtp_tls_verify: bool,
|
||||
pub last_accessed: Instant,
|
||||
pub timeout_override: Option<Duration>,
|
||||
pub created_at_unix: u64,
|
||||
@@ -49,6 +51,7 @@ pub struct SessionStore {
|
||||
account_to_session: Arc<DashMap<AccountId, SessionId>>,
|
||||
account_to_browser: Arc<DashMap<AccountId, BrowserId>>,
|
||||
timeout: Duration,
|
||||
tls_verify_override: Option<bool>,
|
||||
}
|
||||
|
||||
impl SessionStore {
|
||||
@@ -60,15 +63,28 @@ impl SessionStore {
|
||||
}
|
||||
|
||||
pub fn new(timeout: Duration) -> Self {
|
||||
Self::new_with_tls_verify(timeout, None)
|
||||
}
|
||||
|
||||
pub fn new_with_tls_verify(timeout: Duration, tls_verify_override: Option<bool>) -> Self {
|
||||
Self {
|
||||
sessions: Arc::new(DashMap::new()),
|
||||
browsers: Arc::new(DashMap::new()),
|
||||
account_to_session: Arc::new(DashMap::new()),
|
||||
account_to_browser: Arc::new(DashMap::new()),
|
||||
timeout,
|
||||
tls_verify_override,
|
||||
}
|
||||
}
|
||||
|
||||
fn tls_verify_for_host(&self, host: &str) -> bool {
|
||||
if let Some(value) = self.tls_verify_override {
|
||||
return value;
|
||||
}
|
||||
let normalized = host.trim().trim_matches(|ch| ch == '[' || ch == ']').to_ascii_lowercase();
|
||||
!matches!(normalized.as_str(), "localhost" | "127.0.0.1" | "::1")
|
||||
}
|
||||
|
||||
pub fn generate_token() -> SessionId {
|
||||
let mut bytes = [0u8; 32];
|
||||
rand::rng().fill_bytes(&mut bytes);
|
||||
@@ -126,6 +142,8 @@ impl SessionStore {
|
||||
let account_id = Self::generate_id();
|
||||
|
||||
let now_unix = Self::unix_now();
|
||||
let imap_tls_verify = self.tls_verify_for_host(&imap_host);
|
||||
let smtp_tls_verify = self.tls_verify_for_host(&smtp_host);
|
||||
let session = AccountSession {
|
||||
account_id: account_id.clone(),
|
||||
email,
|
||||
@@ -134,9 +152,11 @@ impl SessionStore {
|
||||
imap_host,
|
||||
imap_port,
|
||||
imap_tls,
|
||||
imap_tls_verify,
|
||||
smtp_host,
|
||||
smtp_port,
|
||||
smtp_tls,
|
||||
smtp_tls_verify,
|
||||
last_accessed: Instant::now(),
|
||||
timeout_override,
|
||||
created_at_unix: now_unix,
|
||||
@@ -333,9 +353,11 @@ impl SessionStore {
|
||||
imap_host: String::new(),
|
||||
imap_port: 993,
|
||||
imap_tls: true,
|
||||
imap_tls_verify: true,
|
||||
smtp_host: String::new(),
|
||||
smtp_port: 587,
|
||||
smtp_tls: true,
|
||||
smtp_tls_verify: true,
|
||||
last_accessed: Instant::now(),
|
||||
timeout_override,
|
||||
created_at_unix: now_unix,
|
||||
@@ -505,9 +527,11 @@ mod tests {
|
||||
imap_host: "imap.test.com".to_string(),
|
||||
imap_port: 993,
|
||||
imap_tls: true,
|
||||
imap_tls_verify: true,
|
||||
smtp_host: "smtp.test.com".to_string(),
|
||||
smtp_port: 587,
|
||||
smtp_tls: true,
|
||||
smtp_tls_verify: true,
|
||||
last_accessed: Instant::now(),
|
||||
timeout_override: None,
|
||||
created_at_unix: SessionStore::unix_now(),
|
||||
|
||||
Reference in new issue
Block a user