From c5c8e5d72aa2f0f0c2b2ffff47f3ddee97fc6ff7 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Tue, 22 Apr 2025 14:51:03 +0100 Subject: [PATCH] Individual cert and key paths --- README.md | 3 ++- src/main.rs | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 998f501..4719319 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ round ## Usage ``` ---pem-dir | Directory containing `key.pem` and `cert.pem` files, enables TLS support +--cert | Path of `cert.pem` (for TLS) +--key | Path of `key.pem` (for TLS) --sock
| Bind to the given socket. Defaults to 0.0.0.0:3000. ``` diff --git a/src/main.rs b/src/main.rs index 213b5c4..1d16155 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,10 +21,15 @@ pub type Rng = ChaCha8Rng; #[derive(Parser)] pub struct Args { + /// Socket to bind to, defaults to 0.0.0.0:3000 #[arg(long)] sock: Option, #[arg(long)] - pem_dir: Option, + /// Path of the certificate .pem + cert: Option, + /// Path of the private key .pem + #[arg(long)] + key: Option, } #[tokio::main] @@ -122,15 +127,15 @@ async fn main() { .unwrap_or("0.0.0.0:4000") .parse() .unwrap(); - if let Some(pem_dir) = args.pem_dir { - let config = RustlsConfig::from_pem_file(pem_dir.join("cert.pem"), pem_dir.join("key.pem")) - .await - .unwrap(); + if let (Some(cert), Some(key)) = (args.cert, args.key) { + println!("Enabling TLS..."); + let config = RustlsConfig::from_pem_file(cert, key).await.unwrap(); bind_rustls(sock, config) .serve(app.into_make_service()) .await .unwrap(); } else { + println!("WARNING: TLS disabled."); axum_server::bind(sock) .serve(app.into_make_service()) .await