diff --git a/src/config.rs b/src/config.rs index 199d91d..f7eb36d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,7 +24,7 @@ pub struct Config { pub bind_port: u16, #[serde(default = "default_certificate")] - pub certificate: String, + pub certificate: Option, #[serde(default = "default_username")] pub username: Option, @@ -74,8 +74,8 @@ fn default_stream() -> String { "both".to_string() } -fn default_certificate() -> String { - "".to_string() +fn default_certificate() -> Option { + None } fn default_tls_client_auth() -> String { diff --git a/src/gst.rs b/src/gst.rs index 0c20234..c3edc91 100644 --- a/src/gst.rs +++ b/src/gst.rs @@ -124,17 +124,15 @@ impl RtspServer { } pub fn set_tls(&self, cert_file: &str, client_auth: TlsAuthenticationMode) -> Result<()> { - if ! cert_file.is_empty() { - debug!("Setting up TLS using {}", cert_file); - let auth = self.server.get_auth().unwrap_or_else(|| RTSPAuth::new()); + debug!("Setting up TLS using {}", cert_file); + let auth = self.server.get_auth().unwrap_or_else(|| RTSPAuth::new()); - let cert = TlsCertificate::new_from_file(cert_file).expect("Not a valid TLS certificate or not found."); - auth.set_tls_certificate(Some(&cert)); - auth.set_tls_authentication_mode(client_auth); - auth.set_supported_methods(RTSPAuthMethod::None); + let cert = TlsCertificate::new_from_file(&cert_file).expect("Not a valid TLS certificate or not found."); + auth.set_tls_certificate(Some(&cert)); + auth.set_tls_authentication_mode(client_auth); + auth.set_supported_methods(RTSPAuthMethod::None); - self.server.set_auth(Some(&auth)); - } + self.server.set_auth(Some(&auth)); Ok(()) } diff --git a/src/main.rs b/src/main.rs index a6f447f..5e9a945 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,10 @@ fn main() -> Result<(), Error> { "none" => TlsAuthenticationMode::None, _ => unreachable!(), }; - rtsp.set_tls(&config.certificate, tls_client_auth).expect("Failed to set up TLS"); + + if let Some(cert_path) = &config.certificate { + rtsp.set_tls(&cert_path, tls_client_auth).expect("Failed to set up TLS"); + } let name = &config.username; let pass = &config.password;