1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! TLS for the sockets reqwest does not open (websockets, IMAP).
//!
//! rustls on aws-lc-rs, checked by the OS trust store through the same
//! platform verifier reqwest uses, so a socket trusts exactly what the
//! daemon's HTTPS client trusts. The provider is named here because the build
//! links both rustls backends (aws-lc-rs and ring), and rustls's
//! `ClientConfig::builder()` panics when it has to choose between them.
use std::sync::Arc;
pub use rustls::ClientConfig;
use rustls_platform_verifier::BuilderVerifierExt;
/// A client config for one connection.
pub fn client_config() -> Result<Arc<ClientConfig>, rustls::Error> {
let provider = Arc::new(rustls::crypto::aws_lc_rs::default_provider());
let config = ClientConfig::builder_with_provider(provider)
.with_safe_default_protocol_versions()?
.with_platform_verifier()?
.with_no_client_auth();
Ok(Arc::new(config))
}
#[cfg(test)]
mod tests {
#[test]
fn builds_without_a_process_default_provider() {
assert!(super::client_config().is_ok());
}
/// The first key share offered is the post-quantum hybrid, so recorded
/// traffic is not exposed to a future quantum computer (rustls's
/// `prefer-post-quantum` feature; without it X25519 goes first).
#[test]
fn offers_the_post_quantum_hybrid_first() {
let provider = rustls::crypto::aws_lc_rs::default_provider();
assert_eq!(
provider.kx_groups.first().map(|group| group.name()),
Some(rustls::NamedGroup::X25519MLKEM768)
);
}
}