Skip to content

Commit 3f05131

Browse files
authored
Merge pull request #639 from swimos/dependabot/cargo/tokio-rustls-0.26
Update tokio-rustls requirement from 0.23 to 0.26
2 parents cba25e2 + 9411153 commit 3f05131

File tree

8 files changed

+67
-36
lines changed

8 files changed

+67
-36
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ jobs:
2424
with:
2525
toolchain: ${{ env.latest_version }}
2626
- uses: Swatinem/rust-cache@v2
27+
- name: Install NASM for aws-lc-rs on Windows
28+
if: runner.os == 'Windows'
29+
uses: ilammy/setup-nasm@v1
30+
31+
- name: Install ninja-build tool for aws-lc-fips-sys on Windows
32+
if: runner.os == 'Windows'
33+
uses: seanmiddleditch/gha-setup-ninja@v5
34+
35+
- name: Install golang for aws-lc-fips-sys on macos
36+
if: runner.os == 'MacOS'
37+
uses: actions/setup-go@v5
38+
with:
39+
go-version: "1.22.2"
40+
2741
- run: cargo test --all-features --workspace --lib --tests --profile "ci"
2842

2943
# Check step to ensure that all targets are valid as the test step doesn't run them.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ flate2 = "1.0.22"
9595
bitflags = "2.5"
9696
rocksdb = "0.22"
9797
integer-encoding = "4.0.0"
98-
rustls = "0.20"
98+
rustls = "0.23.10"
9999
webpki = "0.22"
100-
webpki-roots = "0.22"
101-
tokio-rustls = "0.23"
102-
rustls-pemfile = "1.0.0"
100+
webpki-roots = "0.26.3"
101+
tokio-rustls = "0.26"
102+
rustls-pemfile = "2.1.2"
103103
trust-dns-resolver = "0.23.2"
104104
clap = "4.1"
105105
crossbeam-queue = { version = "0.3" }

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use rustls::crypto::CryptoProvider;
16+
use std::sync::Arc;
17+
1518
/// Supported certificate formats for TLS connections.
1619
pub enum CertFormat {
1720
Pem,
@@ -60,9 +63,11 @@ impl PrivateKey {
6063
Self::new(CertFormat::Pem, body)
6164
}
6265
}
63-
/// Combined TLS configuration (both server and client)/
66+
/// Combined TLS configuration (both server and client).
6467
pub struct TlsConfig {
68+
/// Configuration parameters for a TLS client.
6569
pub client: ClientConfig,
70+
/// Configuration parameters for a TLS server.
6671
pub server: ServerConfig,
6772
}
6873

@@ -74,17 +79,26 @@ impl TlsConfig {
7479

7580
/// Configuration parameters for a TLS server.
7681
pub struct ServerConfig {
82+
/// A chain of TLS certificates (starting with the server certificate and ending with the CA).
7783
pub chain: CertChain,
84+
/// An unvalidated private key for a server.
7885
pub key: PrivateKey,
86+
/// Whether to enable a [`rustls::KeyLog`] implementation that opens a file whose name is given by the
87+
/// `SSLKEYLOGFILE` environment variable, and writes keys into it. While this may be enabled,
88+
/// if `SSLKEYLOGFILE` is not set, it will do nothing.
7989
pub enable_log_file: bool,
90+
/// Process-wide [`CryptoProvider`] that must already have been installed as the default
91+
/// provider.
92+
pub provider: Arc<CryptoProvider>,
8093
}
8194

8295
impl ServerConfig {
83-
pub fn new(chain: CertChain, key: PrivateKey) -> Self {
96+
pub fn new(chain: CertChain, key: PrivateKey, provider: Arc<CryptoProvider>) -> Self {
8497
ServerConfig {
8598
chain,
8699
key,
87100
enable_log_file: false,
101+
provider,
88102
}
89103
}
90104
}

runtime/swimos_remote/src/tls/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub enum TlsError {
2525
InvalidPrivateKey,
2626
/// Certificate validation failed.
2727
#[error("Invalid certificate: {0}")]
28-
BadCertificate(#[from] webpki::Error),
28+
BadCertificate(#[from] rustls::Error),
2929
/// The provided host name was invalid.
3030
#[error("Invalid DNS host name.")]
3131
BadHostName,

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
use std::{net::SocketAddr, sync::Arc};
1616

1717
use futures::{future::BoxFuture, FutureExt};
18-
use rustls::{OwnedTrustAnchor, RootCertStore, ServerName};
18+
use rustls::pki_types::ServerName;
19+
use rustls::RootCertStore;
1920

2021
use crate::dns::{BoxDnsResolver, DnsResolver, Resolver};
2122
use crate::net::{ClientConnections, ConnectionError, ConnectionResult, Scheme};
@@ -49,25 +50,16 @@ impl RustlsClientNetworking {
4950
} = config;
5051
let mut root_store = RootCertStore::empty();
5152
if use_webpki_roots {
52-
root_store.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(
53-
|ta| {
54-
OwnedTrustAnchor::from_subject_spki_name_constraints(
55-
ta.subject,
56-
ta.spki,
57-
ta.name_constraints,
58-
)
59-
},
60-
));
53+
root_store.extend(webpki_roots::TLS_SERVER_ROOTS.iter().cloned())
6154
}
6255

6356
for cert in custom_roots {
6457
for c in super::load_cert_file(cert)? {
65-
root_store.add(&c)?;
58+
root_store.add(c)?;
6659
}
6760
}
6861

6962
let config = rustls::ClientConfig::builder()
70-
.with_safe_defaults()
7163
.with_root_certificates(root_store)
7264
.with_no_client_auth();
7365

@@ -93,10 +85,10 @@ impl ClientConnections for RustlsClientNetworking {
9385
.boxed(),
9486
Scheme::Wss => {
9587
let domain = if let Some(host_name) = host {
96-
ServerName::try_from(host_name)
88+
ServerName::try_from(host_name.to_string())
9789
.map_err(|err| ConnectionError::BadParameter(err.to_string()))
9890
} else {
99-
Ok(ServerName::IpAddress(addr.ip()))
91+
Ok(ServerName::IpAddress(addr.ip().into()))
10092
};
10193
async move {
10294
let stream = TcpStream::connect(addr).await?;

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub use client::RustlsClientNetworking;
2626
use futures::future::Either;
2727
use futures::TryFutureExt;
2828
use futures::{future::BoxFuture, FutureExt};
29+
use rustls::pki_types::CertificateDer;
2930
pub use server::{RustlsListener, RustlsServerNetworking};
3031

3132
use crate::tls::{
@@ -36,16 +37,17 @@ use crate::tls::{
3637

3738
use self::server::MaybeRustTlsListener;
3839

39-
fn load_cert_file(file: CertificateFile) -> Result<Vec<rustls::Certificate>, TlsError> {
40+
fn load_cert_file(file: CertificateFile) -> Result<Vec<CertificateDer<'static>>, TlsError> {
4041
let CertificateFile { format, body } = file;
41-
let certs = match format {
42+
match format {
4243
CertFormat::Pem => {
4344
let mut body_ref = body.as_ref();
44-
rustls_pemfile::certs(&mut body_ref).map_err(TlsError::InvalidPem)?
45+
rustls_pemfile::certs(&mut body_ref)
46+
.map(|r| r.map_err(TlsError::InvalidPem))
47+
.collect()
4548
}
46-
CertFormat::Der => vec![body],
47-
};
48-
Ok(certs.into_iter().map(rustls::Certificate).collect())
49+
CertFormat::Der => Ok(vec![CertificateDer::from(body)]),
50+
}
4951
}
5052

5153
/// Combined implementation of [`ClientConnections`] and [`ServerConnections`] that wraps

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use futures::{
2222
stream::{unfold, BoxStream, FuturesUnordered},
2323
Future, FutureExt, Stream, StreamExt, TryStreamExt,
2424
};
25+
use rustls::pki_types::PrivateKeyDer;
2526
use rustls::KeyLogFile;
2627
use rustls_pemfile::Item;
2728
use tokio::net::{TcpListener, TcpStream};
@@ -73,6 +74,7 @@ impl TryFrom<ServerConfig> for RustlsServerNetworking {
7374
chain: CertChain(certs),
7475
key,
7576
enable_log_file,
77+
provider,
7678
} = config;
7779

7880
let mut chain = vec![];
@@ -85,19 +87,19 @@ impl TryFrom<ServerConfig> for RustlsServerNetworking {
8587
CertFormat::Pem => {
8688
let mut body_ref = body.as_ref();
8789
match rustls_pemfile::read_one(&mut body_ref).map_err(TlsError::InvalidPem)? {
88-
Some(Item::ECKey(body) | Item::PKCS8Key(body) | Item::RSAKey(body)) => {
89-
rustls::PrivateKey(body)
90-
}
91-
_ => {
92-
return Err(TlsError::InvalidPrivateKey);
93-
}
90+
Some(Item::Sec1Key(body)) => PrivateKeyDer::from(body),
91+
Some(Item::Pkcs8Key(body)) => PrivateKeyDer::from(body),
92+
Some(Item::Pkcs1Key(body)) => PrivateKeyDer::from(body),
93+
_ => return Err(TlsError::InvalidPrivateKey),
9494
}
9595
}
96-
CertFormat::Der => rustls::PrivateKey(body),
96+
CertFormat::Der => {
97+
PrivateKeyDer::try_from(body).map_err(|_| TlsError::InvalidPrivateKey)?
98+
}
9799
};
98100

99-
let mut config = rustls::ServerConfig::builder()
100-
.with_safe_defaults()
101+
let mut config = rustls::ServerConfig::builder_with_provider(provider)
102+
.with_safe_default_protocol_versions()?
101103
.with_no_client_auth()
102104
.with_single_cert(chain, server_key)
103105
.expect("Invalid certs or private key.");

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,18 @@ fn make_server_config() -> ServerConfig {
4646
CertificateFile::der(ca_cert),
4747
]);
4848

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+
4955
let key = PrivateKey::der(server_key);
5056
ServerConfig {
5157
chain,
5258
key,
5359
enable_log_file: false,
60+
provider: Arc::new(provider),
5461
}
5562
}
5663

0 commit comments

Comments
 (0)