Skip to content

Commit 849a873

Browse files
committed
feat: only try to configure non-strict TLS checks if explicitly set
Trying non-strict TLS checks is not necessary for most servers with proper TLS setup, but doubles the time needed to fail configuration when the server is not responding, e.g. when all connection attempts time out. There is also a risk of accidentally configuring non-strict TLS checks in a rare case that strict TLS check configuration spuriously failed, e.g. on a bad network. If the server has a known broken TLS setup, it can still be added to the provider database or configured with non-strict TLS check manually. User can also configure another email provider, such as chatmail servers, instead of using the server with invalid TLS hostname. This change does not affect exising setups.
1 parent b5c0372 commit 849a873

File tree

2 files changed

+22
-54
lines changed

2 files changed

+22
-54
lines changed

src/configure/server_params.rs

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,11 @@ impl ServerParams {
137137
}
138138

139139
fn expand_strict_tls(self) -> Vec<ServerParams> {
140-
if self.strict_tls.is_none() {
141-
vec![
142-
Self {
143-
strict_tls: Some(true), // Strict.
144-
..self.clone()
145-
},
146-
Self {
147-
strict_tls: None, // Automatic.
148-
..self
149-
},
150-
]
151-
} else {
152-
vec![self]
153-
}
140+
vec![Self {
141+
// Strict if not set by the user or provider database.
142+
strict_tls: Some(self.strict_tls.unwrap_or(true)),
143+
..self
144+
}]
154145
}
155146
}
156147

@@ -162,31 +153,10 @@ pub(crate) fn expand_param_vector(
162153
domain: &str,
163154
) -> Vec<ServerParams> {
164155
v.into_iter()
165-
.map(|params| {
166-
if params.socket == Socket::Plain {
167-
ServerParams {
168-
// Avoid expanding plaintext configuration into configuration with and without
169-
// `strict_tls` if `strict_tls` is set to `None` as `strict_tls` is not used for
170-
// plaintext connections. Always setting it to "enabled", just in case.
171-
strict_tls: Some(true),
172-
..params
173-
}
174-
} else {
175-
params
176-
}
177-
})
178156
// The order of expansion is important.
179157
//
180158
// Ports are expanded the last, so they are changed the first. Username is only changed if
181159
// default value (address with domain) didn't work for all available hosts and ports.
182-
//
183-
// Strict TLS must be expanded first, so we try all configurations with strict TLS first
184-
// and only then try again without strict TLS. Otherwise we may lock to wrong hostname
185-
// without strict TLS when another hostname with strict TLS is available. For example, if
186-
// both smtp.example.net and mail.example.net are running an SMTP server, but both use a
187-
// certificate that is only valid for mail.example.net, we want to skip smtp.example.net
188-
// and use mail.example.net with strict TLS instead of using smtp.example.net without
189-
// strict TLS.
190160
.flat_map(|params| params.expand_strict_tls().into_iter())
191161
.flat_map(|params| params.expand_usernames(addr).into_iter())
192162
.flat_map(|params| params.expand_hostnames(domain).into_iter())
@@ -257,22 +227,6 @@ mod tests {
257227
username: "foobar".to_string(),
258228
strict_tls: Some(true)
259229
},
260-
ServerParams {
261-
protocol: Protocol::Smtp,
262-
hostname: "example.net".to_string(),
263-
port: 123,
264-
socket: Socket::Ssl,
265-
username: "foobar".to_string(),
266-
strict_tls: None,
267-
},
268-
ServerParams {
269-
protocol: Protocol::Smtp,
270-
hostname: "example.net".to_string(),
271-
port: 123,
272-
socket: Socket::Starttls,
273-
username: "foobar".to_string(),
274-
strict_tls: None
275-
}
276230
],
277231
);
278232

@@ -284,7 +238,7 @@ mod tests {
284238
port: 123,
285239
socket: Socket::Plain,
286240
username: "foobar".to_string(),
287-
strict_tls: None,
241+
strict_tls: Some(true),
288242
}],
289243
"foobar@example.net",
290244
"example.net",

src/login_param.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,22 @@ use crate::socks::Socks5Config;
1414
#[repr(u32)]
1515
#[strum(serialize_all = "snake_case")]
1616
pub enum CertificateChecks {
17-
/// Same as AcceptInvalidCertificates unless overridden by
18-
/// `strict_tls` setting in provider database.
17+
/// Same as AcceptInvalidCertificates if stored in the database
18+
/// as `configured_{imap,smtp}_certificate_checks`.
19+
///
20+
/// Previous Delta Chat versions stored this in `configured_*`
21+
/// if Automatic configuration
22+
/// was selected, configuration with strict TLS checks failed
23+
/// and configuration without strict TLS checks succeeded.
24+
///
25+
/// Currently Delta Chat stores only
26+
/// `Strict` or `AcceptInvalidCertificates` variants
27+
/// in `configured_*` settings.
28+
///
29+
/// `Automatic` in `{imap,smtp}_certificate_checks`
30+
/// means that provider database setting should be taken.
31+
/// If there is no provider database setting for certificate checks,
32+
/// `Automatic` is the same as `Strict`.
1933
Automatic = 0,
2034

2135
Strict = 1,

0 commit comments

Comments
 (0)