Skip to content

Commit ff9887c

Browse files
: rust: rusttls/tokio-rustls 0.26.2 migration path
Differential Revision: D79044665
1 parent e305336 commit ff9887c

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

hyperactor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ serde_yaml = "0.9.25"
5454
signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
5555
thiserror = "2.0.12"
5656
tokio = { version = "1.46.1", features = ["full", "test-util", "tracing"] }
57-
tokio-rustls = { git = "https://github.com/shayne-fletcher/tokio-rustls", rev = "62b6a48e4c14a05c193508b9d98a0be6b0cb4baa", features = ["dangerous_configuration"] }
57+
tokio-rustls = "0.26.2"
5858
tokio-stream = { version = "0.1.17", features = ["fs", "io-util", "net", "signal", "sync", "time"] }
5959
tokio-util = { version = "0.7.15", features = ["full"] }
6060
tracing = { version = "0.1.41", features = ["attributes", "valuable"] }

hyperactor/src/channel/net.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,14 +1630,13 @@ pub(crate) mod meta {
16301630

16311631
use anyhow::Context;
16321632
use anyhow::Result;
1633-
use rustls::RootCertStore;
1633+
use tokio_rustls::rustls::RootCertStore;
16341634
use tokio::net::TcpListener;
16351635
use tokio::net::TcpStream;
16361636
use tokio_rustls::TlsAcceptor;
16371637
use tokio_rustls::TlsConnector;
16381638
use tokio_rustls::client::TlsStream;
1639-
use tokio_rustls::rustls::Certificate;
1640-
use tokio_rustls::rustls::PrivateKey;
1639+
use tokio_rustls::rustls::pki_types::{CertificateDer, PrivateKeyDer, ServerName};
16411640

16421641
use super::*;
16431642
use crate::RemoteMessage;
@@ -1674,7 +1673,7 @@ pub(crate) mod meta {
16741673
let trust_anchors = ca_certs.iter().filter_map(|cert| {
16751674
webpki::TrustAnchor::try_from_cert_der(&cert[..])
16761675
.map(|ta| {
1677-
rustls::OwnedTrustAnchor::from_subject_spki_name_constraints(
1676+
tokio_rustls::rustls::OwnedTrustAnchor::from_subject_spki_name_constraints(
16781677
ta.subject,
16791678
ta.spki,
16801679
ta.name_constraints,
@@ -1693,7 +1692,7 @@ pub(crate) mod meta {
16931692
File::open(server_cert_path).context("failed to open {server_cert_path}")?,
16941693
))?
16951694
.into_iter()
1696-
.map(Certificate)
1695+
.map(CertificateDer::from)
16971696
.collect();
16981697
// certs are good here
16991698
let server_key_path = DEFAULT_SERVER_PEM_PATH;
@@ -1712,22 +1711,22 @@ pub(crate) mod meta {
17121711
};
17131712
};
17141713

1715-
let config = rustls::ServerConfig::builder().with_safe_defaults();
1714+
let config = tokio_rustls::rustls::ServerConfig::builder().with_safe_defaults();
17161715

17171716
let config = if enforce_client_tls {
1718-
let client_cert_verifier = Arc::new(rustls::server::AllowAnyAuthenticatedClient::new(
1717+
let client_cert_verifier = Arc::new(tokio_rustls::rustls::server::AllowAnyAuthenticatedClient::new(
17191718
root_cert_store()?,
17201719
));
17211720
config.with_client_cert_verifier(client_cert_verifier)
17221721
} else {
17231722
config.with_no_client_auth()
17241723
}
1725-
.with_single_cert(certs, PrivateKey(key))?;
1724+
.with_single_cert(certs, PrivateKeyDer::from(key))?;
17261725

17271726
Ok(TlsAcceptor::from(Arc::new(config)))
17281727
}
17291728

1730-
fn load_client_pem() -> Result<Option<(Vec<rustls::Certificate>, rustls::PrivateKey)>> {
1729+
fn load_client_pem() -> Result<Option<(Vec<CertificateDer<'static>>, PrivateKeyDer<'static>)>> {
17311730
let Some(cert_path) = std::env::var_os(THRIFT_TLS_CL_CERT_PATH_ENV) else {
17321731
return Ok(None);
17331732
};
@@ -1738,7 +1737,7 @@ pub(crate) mod meta {
17381737
File::open(cert_path).context("failed to open {cert_path}")?,
17391738
))?
17401739
.into_iter()
1741-
.map(rustls::Certificate)
1740+
.map(CertificateDer::from)
17421741
.collect();
17431742
let mut key_reader =
17441743
BufReader::new(File::open(key_path).context("failed to open {key_path}")?);
@@ -1752,13 +1751,13 @@ pub(crate) mod meta {
17521751
};
17531752
};
17541753
// Certs are verified to be good here.
1755-
Ok(Some((certs, rustls::PrivateKey(key))))
1754+
Ok(Some((certs, PrivateKeyDer::from(key))))
17561755
}
17571756

17581757
/// Creates a TLS connector by looking for necessary certs and keys in a Meta server environment.
17591758
fn tls_connector() -> Result<TlsConnector> {
17601759
// TODO (T208180540): try to simplify the logic here.
1761-
let config = rustls::ClientConfig::builder()
1760+
let config = tokio_rustls::rustls::ClientConfig::builder()
17621761
.with_safe_defaults()
17631762
.with_root_certificates(root_cert_store()?);
17641763
let result = load_client_pem()?;
@@ -1772,9 +1771,9 @@ pub(crate) mod meta {
17721771
Ok(TlsConnector::from(Arc::new(config)))
17731772
}
17741773

1775-
fn tls_connector_config(peer_host_name: &str) -> Result<(TlsConnector, rustls::ServerName)> {
1774+
fn tls_connector_config(peer_host_name: &str) -> Result<(TlsConnector, ServerName<'static>)> {
17761775
let connector = tls_connector()?;
1777-
let server_name = rustls::ServerName::try_from(peer_host_name)?;
1776+
let server_name = ServerName::try_from(peer_host_name.to_string())?;
17781777
Ok((connector, server_name))
17791778
}
17801779

0 commit comments

Comments
 (0)