From 9f1d465ac411ef2efc5930bbdf56b8ea67b48690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 7 Jun 2021 20:42:01 +0200 Subject: specify if we accept invalid server certs or not --- mumlib/src/command.rs | 1 + mumlib/src/config.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) (limited to 'mumlib') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 351d7f6..36bda72 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -53,6 +53,7 @@ pub enum CommandResponse { ServerConnect { welcome_message: Option, }, + ServerCertReject, ServerStatus { version: u32, users: u32, diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs index 1bd3784..3edef37 100644 --- a/mumlib/src/config.rs +++ b/mumlib/src/config.rs @@ -10,8 +10,15 @@ use std::path::{Path, PathBuf}; use toml::value::Array; use toml::Value; +/// A TOML-friendly version of [Config]. +/// +/// Values need to be placed before tables due to how TOML works. #[derive(Debug, Deserialize, Serialize)] struct TOMLConfig { + // Values + accept_all_invalid_certs: Option, + + // Tables audio: Option, servers: Option, } @@ -20,6 +27,10 @@ struct TOMLConfig { pub struct Config { pub audio: AudioConfig, pub servers: Vec, + /// Whether we allow connecting to servers with invalid server certificates. + /// + /// None implies false but we can show a better message to the user. + pub allow_invalid_server_cert: Option, } impl Config { @@ -64,6 +75,7 @@ pub struct ServerConfig { pub port: Option, pub username: Option, pub password: Option, + pub accept_invalid_cert: Option, } impl ServerConfig { @@ -105,6 +117,7 @@ impl TryFrom for Config { }) .transpose()? .unwrap_or_default(), + allow_invalid_server_cert: config.accept_all_invalid_certs, }) } } @@ -125,6 +138,7 @@ impl From for TOMLConfig { .map(|s| Value::try_from::(s).unwrap()) .collect(), ), + accept_all_invalid_certs: config.allow_invalid_server_cert, } } } -- cgit v1.2.1 From 24ab81363b18f874c68690ae54ba8a27bd46acd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 11 Jun 2021 18:35:00 +0200 Subject: servert cert reject is error --- mumlib/src/command.rs | 1 - mumlib/src/error.rs | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'mumlib') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 36bda72..351d7f6 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -53,7 +53,6 @@ pub enum CommandResponse { ServerConnect { welcome_message: Option, }, - ServerCertReject, ServerStatus { version: u32, users: u32, diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index e88bd97..91c15e1 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -11,6 +11,7 @@ pub enum Error { InvalidServerAddr(String, u16), InvalidUsername(String), InvalidServerPassword, + ServerCertReject, } impl std::error::Error for Error {} @@ -26,6 +27,7 @@ impl fmt::Display for Error { } Error::InvalidUsername(username) => write!(f, "Invalid username: {}", username), Error::InvalidServerPassword => write!(f, "Invalid server password"), + Error::ServerCertReject => write!(f, "Invalid server certificate"), } } } -- cgit v1.2.1