Skip to content

Commit c99b83f

Browse files
committed
Adds missing client-side crypto provider init
1 parent 0a4851e commit c99b83f

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

runtime/swimos_remote/src/tls/config/mod.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ pub struct ServerConfig {
8787
/// `SSLKEYLOGFILE` environment variable, and writes keys into it. While this may be enabled,
8888
/// if `SSLKEYLOGFILE` is not set, it will do nothing.
8989
pub enable_log_file: bool,
90-
/// Process-wide [`CryptoProvider`] that must already have been installed as the default
91-
/// provider.
90+
/// [`CryptoProvider`] to use when building the [`rustls::ServerConfig`].
9291
pub provider: Arc<CryptoProvider>,
9392
}
9493

@@ -107,22 +106,15 @@ impl ServerConfig {
107106
pub struct ClientConfig {
108107
pub use_webpki_roots: bool,
109108
pub custom_roots: Vec<CertificateFile>,
109+
pub provider: Arc<CryptoProvider>,
110110
}
111111

112112
impl ClientConfig {
113-
pub fn new(custom_roots: Vec<CertificateFile>) -> Self {
113+
pub fn new(custom_roots: Vec<CertificateFile>, provider: Arc<CryptoProvider>) -> Self {
114114
ClientConfig {
115115
use_webpki_roots: true,
116116
custom_roots,
117-
}
118-
}
119-
}
120-
121-
impl Default for ClientConfig {
122-
fn default() -> Self {
123-
Self {
124-
use_webpki_roots: true,
125-
custom_roots: vec![],
117+
provider,
126118
}
127119
}
128120
}

runtime/swimos_remote/src/tls/net/client.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl RustlsClientNetworking {
4747
let ClientConfig {
4848
use_webpki_roots,
4949
custom_roots,
50+
provider,
5051
} = config;
5152
let mut root_store = RootCertStore::empty();
5253
if use_webpki_roots {
@@ -59,7 +60,8 @@ impl RustlsClientNetworking {
5960
}
6061
}
6162

62-
let config = rustls::ClientConfig::builder()
63+
let config = rustls::ClientConfig::builder_with_provider(provider)
64+
.with_safe_default_protocol_versions()?
6365
.with_root_certificates(root_store)
6466
.with_no_client_auth();
6567

runtime/swimos_remote/src/tls/net/tests.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::{net::SocketAddr, path::PathBuf, sync::Arc, time::Duration};
1717
use crate::dns::Resolver;
1818
use crate::net::{ClientConnections, ConnectionError, Listener, ListenerError, Scheme};
1919
use futures::{future::join, StreamExt};
20+
use rustls::crypto::aws_lc_rs;
2021

2122
use crate::tls::{
2223
CertChain, CertificateFile, ClientConfig, PrivateKey, RustlsClientNetworking,
@@ -46,18 +47,12 @@ fn make_server_config() -> ServerConfig {
4647
CertificateFile::der(ca_cert),
4748
]);
4849

49-
let provider = rustls::crypto::aws_lc_rs::default_provider();
50-
provider
51-
.clone()
52-
.install_default()
53-
.expect("Crypto Provider has already been initialised elsewhere.");
54-
5550
let key = PrivateKey::der(server_key);
5651
ServerConfig {
5752
chain,
5853
key,
5954
enable_log_file: false,
60-
provider: Arc::new(provider),
55+
provider: Arc::new(aws_lc_rs::default_provider()),
6156
}
6257
}
6358

@@ -67,6 +62,7 @@ fn make_client_config() -> ClientConfig {
6762
ClientConfig {
6863
use_webpki_roots: true,
6964
custom_roots: vec![CertificateFile::der(ca_cert)],
65+
provider: Arc::new(aws_lc_rs::default_provider()),
7066
}
7167
}
7268

server/swimos_server_app/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ swimos_runtime = { path = "../../runtime/swimos_runtime" }
1717
swimos_messages = { path = "../../runtime/swimos_messages" }
1818
swimos_http = { path = "../../runtime/swimos_http" }
1919
swimos_introspection = { path = "../swimos_introspection" }
20-
swimos_remote = { path = "../../runtime/swimos_remote", features = ["tls"]}
20+
swimos_remote = { path = "../../runtime/swimos_remote", features = ["tls"] }
2121
bytes = { workspace = true }
2222
tokio = { workspace = true, features = ["rt"] }
2323
tokio-util = { workspace = true, features = ["codec"] }
@@ -30,11 +30,12 @@ uuid = { workspace = true }
3030
thiserror = { workspace = true }
3131
rand = { workspace = true }
3232
url = { workspace = true }
33-
swimos_rocks_store = { path = "../../runtime/swimos_rocks_store", optional = true}
33+
swimos_rocks_store = { path = "../../runtime/swimos_rocks_store", optional = true }
3434
parking_lot = { workspace = true }
3535
hyper = { workspace = true, features = ["server", "runtime", "tcp", "http1", "backports"] }
3636
pin-project = { workspace = true }
3737
percent-encoding = { workspace = true }
38+
rustls = { workspace = true }
3839

3940
[dev-dependencies]
4041
swimos_recon = { path = "../../api/formats/swimos_recon" }

server/swimos_server_app/src/server/builder/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use ratchet::{
2121
deflate::{DeflateConfig, DeflateExtProvider},
2222
NoExtProvider, WebSocketStream,
2323
};
24+
use rustls::crypto::aws_lc_rs;
2425
use swimos_api::{
2526
agent::Agent,
2627
error::StoreError,
@@ -188,8 +189,11 @@ impl ServerBuilder {
188189
let networking = RustlsNetworking::new_tls(client, server);
189190
Ok(with_store(bind_to, routes, networking, config)?)
190191
} else {
191-
let client =
192-
RustlsClientNetworking::try_from_config(resolver.clone(), ClientConfig::default())?;
192+
let provider = Arc::new(aws_lc_rs::default_provider());
193+
let client = RustlsClientNetworking::try_from_config(
194+
resolver.clone(),
195+
ClientConfig::new(Default::default(), provider),
196+
)?;
193197
let server = TokioPlainTextNetworking::new(resolver);
194198
let networking = RustlsNetworking::new_plain_text(client, server);
195199
Ok(with_store(bind_to, routes, networking, config)?)

0 commit comments

Comments
 (0)