feature-gate direct TLS mode to make rustls/aws-lc-rs optional

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-10-10 16:23:38 -04:00 committed by Jason Volk
parent 127fb1a37b
commit aa6f6c1bfa
7 changed files with 23 additions and 5 deletions

1
Cargo.lock generated
View file

@ -705,7 +705,6 @@ dependencies = [
"reqwest", "reqwest",
"ring", "ring",
"ruma", "ruma",
"rustls 0.23.14",
"sanitize-filename", "sanitize-filename",
"serde", "serde",
"serde_json", "serde_json",

View file

@ -101,7 +101,6 @@ features = ["typed-header", "tracing"]
[workspace.dependencies.axum-server] [workspace.dependencies.axum-server]
version = "0.7.1" version = "0.7.1"
default-features = false default-features = false
features = ["tls-rustls"]
# to listen on both HTTP and HTTPS if listening on TLS dierctly from conduwuit for complement or sytest # to listen on both HTTP and HTTPS if listening on TLS dierctly from conduwuit for complement or sytest
[workspace.dependencies.axum-server-dual-protocol] [workspace.dependencies.axum-server-dual-protocol]

View file

@ -80,7 +80,6 @@ regex.workspace = true
reqwest.workspace = true reqwest.workspace = true
ring.workspace = true ring.workspace = true
ruma.workspace = true ruma.workspace = true
rustls.workspace = true
sanitize-filename.workspace = true sanitize-filename.workspace = true
serde_json.workspace = true serde_json.workspace = true
serde_regex.workspace = true serde_regex.workspace = true

View file

@ -66,6 +66,9 @@ console = [
# "conduit-router/dev_release_log_level", # "conduit-router/dev_release_log_level",
# "conduit-service/dev_release_log_level", # "conduit-service/dev_release_log_level",
#] #]
direct_tls = [
"conduit-router/direct_tls"
]
element_hacks = [ element_hacks = [
"conduit-api/element_hacks", "conduit-api/element_hacks",
"conduit-service/element_hacks", "conduit-service/element_hacks",

View file

@ -42,9 +42,16 @@ systemd = [
"dep:sd-notify", "dep:sd-notify",
] ]
direct_tls = [
"axum-server/tls-rustls",
"dep:rustls",
"dep:axum-server-dual-protocol",
]
[dependencies] [dependencies]
axum-client-ip.workspace = true axum-client-ip.workspace = true
axum-server-dual-protocol.workspace = true axum-server-dual-protocol.workspace = true
axum-server-dual-protocol.optional = true
axum-server.workspace = true axum-server.workspace = true
axum.workspace = true axum.workspace = true
conduit-admin.workspace = true conduit-admin.workspace = true
@ -63,6 +70,7 @@ hyper.workspace = true
hyper-util.workspace = true hyper-util.workspace = true
ruma.workspace = true ruma.workspace = true
rustls.workspace = true rustls.workspace = true
rustls.optional = true
sentry.optional = true sentry.optional = true
sentry-tower.optional = true sentry-tower.optional = true
sentry-tower.workspace = true sentry-tower.workspace = true

View file

@ -1,4 +1,5 @@
mod plain; mod plain;
#[cfg(feature = "direct_tls")]
mod tls; mod tls;
mod unix; mod unix;
@ -23,7 +24,14 @@ pub(super) async fn serve(
if cfg!(unix) && config.unix_socket_path.is_some() { if cfg!(unix) && config.unix_socket_path.is_some() {
unix::serve(server, app, shutdown).await unix::serve(server, app, shutdown).await
} else if config.tls.is_some() { } else if config.tls.is_some() {
tls::serve(server, app, handle, addrs).await #[cfg(feature = "direct_tls")]
return tls::serve(server, app, handle, addrs).await;
#[cfg(not(feature = "direct_tls"))]
return conduit::Err!(Config(
"tls",
"conduwuit was not built with direct TLS support (\"direct_tls\")"
));
} else { } else {
plain::serve(server, app, handle, addrs).await plain::serve(server, app, handle, addrs).await
} }

View file

@ -20,7 +20,9 @@ pub(super) async fn serve(
// we use ring for ruma and hashing state, but aws-lc-rs is the new default. // we use ring for ruma and hashing state, but aws-lc-rs is the new default.
// without this, TLS mode will panic. // without this, TLS mode will panic.
_ = rustls::crypto::aws_lc_rs::default_provider().install_default(); rustls::crypto::aws_lc_rs::default_provider()
.install_default()
.expect("failed to initialise aws-lc-rs rustls crypto provider");
debug!("Using direct TLS. Certificate path {certs} and certificate private key path {key}",); debug!("Using direct TLS. Certificate path {certs} and certificate private key path {key}",);
info!( info!(