summaryrefslogtreecommitdiffstats
path: root/src/bin/server/tls.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-10-28 22:55:51 +0100
committersalmonik <salmonik@tuta.io>2026-10-28 22:55:51 +0100
commit87440d5a23f0fd894d949295a7c1ff85043550fc (patch)
tree53b2bada6872b6e565bb79982213616a50419b1c /src/bin/server/tls.rs
parentv0.3.1: clean up dependencies, stale tests and document verification (diff)
downloadzagan-bet-87440d5a23f0fd894d949295a7c1ff85043550fc.tar.gz
zagan-bet-87440d5a23f0fd894d949295a7c1ff85043550fc.zip
v0.4.0: add first-time TLS setup and server help
Diffstat (limited to 'src/bin/server/tls.rs')
-rw-r--r--src/bin/server/tls.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/bin/server/tls.rs b/src/bin/server/tls.rs
index 62a25db..292ebf7 100644
--- a/src/bin/server/tls.rs
+++ b/src/bin/server/tls.rs
@@ -9,25 +9,25 @@ pub struct TlsServer {
9} 9}
10 10
11impl TlsServer { 11impl TlsServer {
12 pub fn new( 12 pub fn new(cert_path: &str) -> Result<Self, Box<dyn std::error::Error>> {
13 cert_path: &str, 13 let cert_data = match std::fs::read(cert_path) {
14 _key_path: &str, 14 Ok(data) => data,
15 unsafe_mode: bool, 15 Err(error) => {
16 ) -> Result<Self, Box<dyn std::error::Error>> {
17 let cert_data = if unsafe_mode {
18 if std::path::Path::new(cert_path).exists() {
19 std::fs::read(cert_path)?
20 } else {
21 return Err(format!( 16 return Err(format!(
22 "Certificate file '{}' not found. In --unsafe mode, you must provide a valid PKCS12 certificate file.\n\ 17 "Could not read TLS identity '{}': {}\n\
23 You can generate one with:\n\ 18 \n\
24 openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes\n\ 19 First-time setup:\n\
25 openssl pkcs12 -export -out identity.p12 -inkey key.pem -in cert.pem", 20 \x20 cargo run --bin server -- --init\n\
26 cert_path 21 \n\
27 ).into()); 22 Or generate it manually:\n\
23 \x20 openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem \\\n\
24 \x20 -days 3650 -nodes -subj \"/CN=localhost\"\n\
25 \x20 openssl pkcs12 -export -out identity.p12 -inkey key.pem -in cert.pem \\\n\
26 \x20 -passout pass:",
27 cert_path, error
28 )
29 .into());
28 } 30 }
29 } else {
30 std::fs::read(cert_path)?
31 }; 31 };
32 32
33 let identity = native_tls::Identity::from_pkcs12(&cert_data, "")?; 33 let identity = native_tls::Identity::from_pkcs12(&cert_data, "")?;