Skip to content

Commit

Permalink
feature-gate direct TLS mode to make rustls/aws-lc-rs optional
Browse files Browse the repository at this point in the history
Signed-off-by: strawberry <[email protected]>
  • Loading branch information
girlbossceo committed Oct 10, 2024
1 parent edff9a7 commit beb28cc
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ features = ["typed-header", "tracing"]
[workspace.dependencies.axum-server]
version = "0.7.1"
default-features = false
features = ["tls-rustls"]

# to listen on both HTTP and HTTPS if listening on TLS dierctly from conduwuit for complement or sytest
[workspace.dependencies.axum-server-dual-protocol]
Expand Down
1 change: 0 additions & 1 deletion src/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ regex.workspace = true
reqwest.workspace = true
ring.workspace = true
ruma.workspace = true
rustls.workspace = true
sanitize-filename.workspace = true
serde_json.workspace = true
serde_regex.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions src/main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ console = [
# "conduit-router/dev_release_log_level",
# "conduit-service/dev_release_log_level",
#]
direct_tls = [
"conduit-router/direct_tls"
]
element_hacks = [
"conduit-api/element_hacks",
"conduit-service/element_hacks",
Expand Down
8 changes: 8 additions & 0 deletions src/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@ systemd = [
"dep:sd-notify",
]

direct_tls = [
"axum-server/tls-rustls",
"dep:rustls",
"dep:axum-server-dual-protocol",
]

[dependencies]
axum-client-ip.workspace = true
axum-server-dual-protocol.workspace = true
axum-server-dual-protocol.optional = true
axum-server.workspace = true
axum.workspace = true
conduit-admin.workspace = true
Expand All @@ -63,6 +70,7 @@ hyper.workspace = true
hyper-util.workspace = true
ruma.workspace = true
rustls.workspace = true
rustls.optional = true
sentry.optional = true
sentry-tower.optional = true
sentry-tower.workspace = true
Expand Down
10 changes: 9 additions & 1 deletion src/router/serve/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod plain;
#[cfg(feature = "direct_tls")]
mod tls;
mod unix;

Expand All @@ -23,7 +24,14 @@ pub(super) async fn serve(
if cfg!(unix) && config.unix_socket_path.is_some() {
unix::serve(server, app, shutdown).await
} 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 {
plain::serve(server, app, handle, addrs).await
}
Expand Down
4 changes: 3 additions & 1 deletion src/router/serve/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
// 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}",);
info!(
Expand Down

0 comments on commit beb28cc

Please sign in to comment.