This commit is contained in:
Matt Brubeck 2025-03-17 16:21:55 -07:00
parent 6177043fa7
commit e6a5d42aeb
4 changed files with 24 additions and 12 deletions

View file

@ -50,8 +50,13 @@ impl Display for CertLoadError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self { match self {
Self::NoReadCertDir => write!(f, "Could not read from certificate directory."), Self::NoReadCertDir => write!(f, "Could not read from certificate directory."),
Self::Empty => write!(f, "No keys or certificates were found in the given directory.\nSpecify the --hostname option to generate these automatically."), Self::Empty => write!(
Self::BadKey(domain, err) => write!(f, "The key file for {domain} is malformed: {err:?}"), f,
"No keys or certificates were found in the given directory.\nSpecify the --hostname option to generate these automatically."
),
Self::BadKey(domain, err) => {
write!(f, "The key file for {domain} is malformed: {err:?}")
}
Self::MissingKey(domain) => write!(f, "The key file for {domain} is missing."), Self::MissingKey(domain) => write!(f, "The key file for {domain} is missing."),
Self::MissingCert(domain) => { Self::MissingCert(domain) => {
write!(f, "The certificate file for {domain} is missing.") write!(f, "The certificate file for {domain} is missing.")
@ -134,13 +139,13 @@ impl CertStore {
Err(CertLoadError::EmptyDomain(_)) => { /* there are no fallback keys */ } Err(CertLoadError::EmptyDomain(_)) => { /* there are no fallback keys */ }
Err(CertLoadError::Empty) | Err(CertLoadError::NoReadCertDir) => unreachable!(), Err(CertLoadError::Empty) | Err(CertLoadError::NoReadCertDir) => unreachable!(),
Err(CertLoadError::BadKey(_, e)) => { Err(CertLoadError::BadKey(_, e)) => {
return Err(CertLoadError::BadKey("fallback".to_string(), e)) return Err(CertLoadError::BadKey("fallback".to_string(), e));
} }
Err(CertLoadError::MissingKey(_)) => { Err(CertLoadError::MissingKey(_)) => {
return Err(CertLoadError::MissingKey("fallback".to_string())) return Err(CertLoadError::MissingKey("fallback".to_string()));
} }
Err(CertLoadError::MissingCert(_)) => { Err(CertLoadError::MissingCert(_)) => {
return Err(CertLoadError::MissingCert("fallback".to_string())) return Err(CertLoadError::MissingCert("fallback".to_string()));
} }
// For the fallback keys there is no domain name to verify them // For the fallback keys there is no domain name to verify them
// against, so we can skip that step and only have to do it for the // against, so we can skip that step and only have to do it for the

View file

@ -7,7 +7,7 @@ use codes::*;
use metadata::{FileOptions, PresetMeta}; use metadata::{FileOptions, PresetMeta};
use { use {
percent_encoding::{percent_decode_str, percent_encode, AsciiSet, CONTROLS}, percent_encoding::{AsciiSet, CONTROLS, percent_decode_str, percent_encode},
rcgen::{CertificateParams, DnType, KeyPair}, rcgen::{CertificateParams, DnType, KeyPair},
std::{ std::{
borrow::Cow, borrow::Cow,
@ -27,9 +27,9 @@ use {
sync::Mutex, sync::Mutex,
}, },
tokio_rustls::{ tokio_rustls::{
TlsAcceptor,
rustls::{server::ServerConfig, version::TLS13}, rustls::{server::ServerConfig, version::TLS13},
server::TlsStream, server::TlsStream,
TlsAcceptor,
}, },
url::{Host, Url}, url::{Host, Url},
}; };

View file

@ -1,5 +1,5 @@
use configparser::ini::Ini; use configparser::ini::Ini;
use glob::{glob_with, MatchOptions}; use glob::{MatchOptions, glob_with};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::time::SystemTime; use std::time::SystemTime;
@ -146,7 +146,10 @@ impl FileOptions {
|| !header.chars().nth(1).unwrap().is_ascii_digit() || !header.chars().nth(1).unwrap().is_ascii_digit()
|| !header.chars().nth(2).unwrap().is_whitespace() || !header.chars().nth(2).unwrap().is_whitespace()
{ {
log::error!("Line for {:?} starts like a full header line, but it is incorrect; ignoring it.", path); log::error!(
"Line for {:?} starts like a full header line, but it is incorrect; ignoring it.",
path
);
return; return;
} }
let separator = header.chars().nth(2).unwrap(); let separator = header.chars().nth(2).unwrap();
@ -154,7 +157,11 @@ impl FileOptions {
// the Gemini specification says that the third // the Gemini specification says that the third
// character has to be a space, so correct any // character has to be a space, so correct any
// other whitespace to it (e.g. tabs) // other whitespace to it (e.g. tabs)
log::warn!("Full Header line for {:?} has an invalid character, treating {:?} as a space.", path, separator); log::warn!(
"Full Header line for {:?} has an invalid character, treating {:?} as a space.",
path,
separator
);
} }
let status = header let status = header
.chars() .chars()

View file

@ -13,7 +13,7 @@
//! You should have received a copy of the GNU General Public License //! You should have received a copy of the GNU General Public License
//! along with this program. If not, see <https://www.gnu.org/licenses/>. //! along with this program. If not, see <https://www.gnu.org/licenses/>.
use rustls::{pki_types::CertificateDer, ClientConnection, RootCertStore}; use rustls::{ClientConnection, RootCertStore, pki_types::CertificateDer};
use std::convert::TryInto; use std::convert::TryInto;
use std::io::{BufRead, BufReader, Read, Write}; use std::io::{BufRead, BufReader, Read, Write};
use std::net::{SocketAddr, TcpStream, ToSocketAddrs}; use std::net::{SocketAddr, TcpStream, ToSocketAddrs};
@ -530,7 +530,7 @@ mod vhosts {
mod multicert { mod multicert {
use super::*; use super::*;
use rustls::{pki_types::CertificateDer, ClientConnection, RootCertStore}; use rustls::{ClientConnection, RootCertStore, pki_types::CertificateDer};
use std::io::Write; use std::io::Write;
use std::net::TcpStream; use std::net::TcpStream;