Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade rustls and its family #37

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ readme = "README.md"
edition = "2018"

[features]
tls = ["tokio-rustls", "webpki-roots"]
tls = ["tokio-rustls", "webpki-roots", "rustls-pki-types"]

[dependencies]
tokio = { version = "1.0", features = ["rt", "net"] }
Expand All @@ -20,8 +20,9 @@ prost = "0.12"
derive_builder = "0.12"
getset = "0.1.1"
thiserror = "1"
tokio-rustls = { version = "0.24.0", optional = true }
webpki-roots = { version = "0.25", optional = true }
tokio-rustls = { version = "0.25.0", optional = true }
webpki-roots = { version = "0.26", optional = true }
rustls-pki-types = { version = "1.0", optional = true, features = ["alloc"] }

[build-dependencies]
prost-build = "0.12"
Expand Down
17 changes: 5 additions & 12 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use derive_builder::Builder;
use getset::Getters;
#[cfg(feature = "tls")]
use tokio_rustls::rustls::{ClientConfig, OwnedTrustAnchor, RootCertStore};
use tokio_rustls::rustls::{ClientConfig, RootCertStore};

/// Riemann connection options
#[derive(Builder, Clone, Getters)]
Expand All @@ -26,18 +26,11 @@ pub struct RiemannClientOptions {

#[cfg(feature = "tls")]
fn default_tls_config() -> Arc<ClientConfig> {
let mut root_cert_store = RootCertStore::empty();
root_cert_store.add_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.iter().map(|ta| {
OwnedTrustAnchor::from_subject_spki_name_constraints(
ta.subject,
ta.spki,
ta.name_constraints,
)
}));

let root_store = RootCertStore {
roots: webpki_roots::TLS_SERVER_ROOTS.iter().cloned().collect(),
};
let tls_config = ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_cert_store)
.with_root_certificates(root_store)
.with_no_client_auth();
Arc::new(tls_config)
}
Expand Down
7 changes: 4 additions & 3 deletions src/tls.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::convert::TryFrom;
use std::io;

use rustls_pki_types::ServerName;
use tokio::net::TcpStream;
use tokio_rustls::rustls::ServerName;
use tokio_rustls::{Connect, TlsConnector};

use crate::options::RiemannClientOptions;
Expand All @@ -18,7 +18,8 @@ pub(crate) fn setup_tls_client(
};
let connector = TlsConnector::from(tls_config);

let dns_name = ServerName::try_from(options.host().as_ref())
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "Invalid DnsName"))?;
let dns_name = ServerName::try_from(options.host().as_str())
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "Invalid DnsName"))?
.to_owned();
Ok(connector.connect(dns_name, socket))
}