Individual cert and key paths

This commit is contained in:
Joshua Barretto 2025-04-22 14:51:03 +01:00
parent 8b39e1fca6
commit c5c8e5d72a
2 changed files with 12 additions and 6 deletions

View file

@ -15,7 +15,8 @@ round
## Usage ## Usage
``` ```
--pem-dir <directory> | Directory containing `key.pem` and `cert.pem` files, enables TLS support --cert <path> | Path of `cert.pem` (for TLS)
--key <path> | Path of `key.pem` (for TLS)
--sock <address> | Bind to the given socket. Defaults to 0.0.0.0:3000. --sock <address> | Bind to the given socket. Defaults to 0.0.0.0:3000.
``` ```

View file

@ -21,10 +21,15 @@ pub type Rng = ChaCha8Rng;
#[derive(Parser)] #[derive(Parser)]
pub struct Args { pub struct Args {
/// Socket to bind to, defaults to 0.0.0.0:3000
#[arg(long)] #[arg(long)]
sock: Option<String>, sock: Option<String>,
#[arg(long)] #[arg(long)]
pem_dir: Option<PathBuf>, /// Path of the certificate .pem
cert: Option<PathBuf>,
/// Path of the private key .pem
#[arg(long)]
key: Option<PathBuf>,
} }
#[tokio::main] #[tokio::main]
@ -122,15 +127,15 @@ async fn main() {
.unwrap_or("0.0.0.0:4000") .unwrap_or("0.0.0.0:4000")
.parse() .parse()
.unwrap(); .unwrap();
if let Some(pem_dir) = args.pem_dir { if let (Some(cert), Some(key)) = (args.cert, args.key) {
let config = RustlsConfig::from_pem_file(pem_dir.join("cert.pem"), pem_dir.join("key.pem")) println!("Enabling TLS...");
.await let config = RustlsConfig::from_pem_file(cert, key).await.unwrap();
.unwrap();
bind_rustls(sock, config) bind_rustls(sock, config)
.serve(app.into_make_service()) .serve(app.into_make_service())
.await .await
.unwrap(); .unwrap();
} else { } else {
println!("WARNING: TLS disabled.");
axum_server::bind(sock) axum_server::bind(sock)
.serve(app.into_make_service()) .serve(app.into_make_service())
.await .await