Using option when setting up TLS

This commit is contained in:
QuantumEntangledAndy committed 2020-07-03 12:38:09 +07:00
1 parent 1b68d73399
commit 5ff211747e
3 files changed
+14 -13

No files matched your search

+3 -3
View File
@@ -24,7 +24,7 @@ pub struct Config {
pub bind_port: u16,
#[serde(default = "default_certificate")]
pub certificate: String,
pub certificate: Option<String>,
#[serde(default = "default_username")]
pub username: Option<String>,
@@ -74,8 +74,8 @@ fn default_stream() -> String {
"both".to_string()
}
fn default_certificate() -> String {
"".to_string()
fn default_certificate() -> Option<String> {
None
}
fn default_tls_client_auth() -> String {
+7 -9
View File
@@ -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(())
}
+4 -1
View File
@@ -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;