Skip to content

Commit

Permalink
update to latest tls
Browse files Browse the repository at this point in the history
  • Loading branch information
hlbarber committed Dec 28, 2023
1 parent 54f64a8 commit fee0463
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 35 deletions.
33 changes: 17 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "tracing-gelf"
version = "0.7.1"
authors = ["Harry Barber <[email protected]>"]
edition = "2018"
edition = "2021"
license = "MIT"
homepage = "https://github.com/hlb8122/tracing-gelf"
repository = "https://github.com/hlb8122/tracing-gelf"
Expand All @@ -17,22 +17,23 @@ exclude = ["/.travis.yml"]
travis-ci = { repository = "hlb8122/tracing-gelf" }

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

[dependencies]
bytes = "1"
hostname = "0.3"
serde_json = "1"
futures-channel = "0.3"
futures-util = { version = "0.3", features = ["sink"] }
thiserror = "1"
tokio = { version = "1", features = ["io-util", "net", "time"] }
tokio-rustls = { version = "0.23", optional = true }
tracing-core = "0.1.24"
tokio-util = { version = "0.7", features = ["codec", "net"] }
tracing-futures = "0.2"
tracing-subscriber = "0.3"
bytes = "1.5.0"
futures-channel = "0.3.30"
futures-util = { version = "0.3.30", features = ["sink"] }
hostname = "0.3.1"
rustls-pki-types = { version = "1.1.0", optional = true }
serde_json = "1.0.108"
thiserror = "1.0.52"
tokio = { version = "1.35.1", features = ["io-util", "net", "time"] }
tokio-rustls = { version = "0.25.0", optional = true }
tokio-util = { version = "0.7.10", features = ["codec", "net"] }
tracing-core = "0.1.32"
tracing-futures = "0.2.5"
tracing-subscriber = "0.3.18"

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"] }
tracing = "0.1"
tokio = { version = "1.35.1", features = ["macros", "rt", "rt-multi-thread"] }
tracing = "0.1.40"
7 changes: 3 additions & 4 deletions src/connection/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl TcpConnection {
/// A TLS connection to Graylog.
#[cfg(feature = "rustls-tls")]
pub struct TlsConnection {
pub(crate) server_name: tokio_rustls::rustls::ServerName,
pub(crate) server_name: rustls_pki_types::ServerName<'static>,
pub(crate) client_config: std::sync::Arc<tokio_rustls::rustls::ClientConfig>,
}

Expand All @@ -66,9 +66,8 @@ impl TlsConnection {
{
let wrapper = move |tcp_stream| {
let server_name = self.server_name.clone();
let config = tokio_rustls::TlsConnector::from(self.client_config.clone());

config.connect(server_name, tcp_stream)
tokio_rustls::TlsConnector::from(self.client_config.clone())
.connect(server_name, tcp_stream)
};
handle_tcp(addr, wrapper, receiver).await
}
Expand Down
21 changes: 6 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms)]
#![warn(missing_debug_implementations, missing_docs)]

//! Provides a [`tracing`] [`Layer`] for Graylog structured logging.
//!
Expand Down Expand Up @@ -114,11 +114,6 @@ pub enum BuilderError {
/// Global dispatcher failed.
#[error("global dispatcher failed to initialize")]
Global(#[source] SetGlobalDefaultError),

/// DNS name error.
#[cfg(feature = "rustls-tls")]
#[error("invalid DNS name")]
Dns(#[source] tokio_rustls::rustls::client::InvalidDnsNameError),
}

/// A builder for [`Logger`].
Expand Down Expand Up @@ -276,17 +271,13 @@ impl Builder {
pub fn connect_tls<A>(
self,
addr: A,
domain_name: &str,
server_name: rustls_pki_types::ServerName<'static>,
client_config: std::sync::Arc<tokio_rustls::rustls::ClientConfig>,
) -> Result<(Logger, ConnectionHandle<A, TlsConnection>), BuilderError>
where
A: ToSocketAddrs,
A: Send + Sync + 'static,
{
use std::convert::TryFrom;
let server_name =
tokio_rustls::rustls::ServerName::try_from(domain_name).map_err(BuilderError::Dns)?;

self.connect(
addr,
TlsConnection {
Expand Down Expand Up @@ -348,7 +339,7 @@ impl Builder {
pub fn init_tls_with_subscriber<A, S>(
self,
addr: A,
domain_name: &str,
server_name: rustls_pki_types::ServerName<'static>,
client_config: std::sync::Arc<tokio_rustls::rustls::ClientConfig>,
subscriber: S,
) -> Result<ConnectionHandle<A, TlsConnection>, BuilderError>
Expand All @@ -357,7 +348,7 @@ impl Builder {
S: Subscriber + for<'a> LookupSpan<'a>,
S: Send + Sync + 'static,
{
let (logger, bg_task) = self.connect_tls(addr, domain_name, client_config)?;
let (logger, bg_task) = self.connect_tls(addr, server_name, client_config)?;

// If a subscriber was set then use it as the inner subscriber.
let subscriber = Layer::with_subscriber(logger, subscriber);
Expand All @@ -383,14 +374,14 @@ impl Builder {
pub fn init_tls<A>(
self,
addr: A,
domain_name: &str,
server_name: rustls_pki_types::ServerName<'static>,
client_config: std::sync::Arc<tokio_rustls::rustls::ClientConfig>,
) -> Result<ConnectionHandle<A, TlsConnection>, BuilderError>
where
A: ToSocketAddrs,
A: Send + Sync + 'static,
{
self.init_tls_with_subscriber(addr, domain_name, client_config, Registry::default())
self.init_tls_with_subscriber(addr, server_name, client_config, Registry::default())
}

/// Initialize UDP logging and returns its [`ConnectionHandle`].
Expand Down

0 comments on commit fee0463

Please sign in to comment.