mirror of
https://github.com/greatest-ape/aquatic.git
synced 2026-08-29 07:08:20 +00:00
Improve rustls config creation error messages
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
|
||||
use anyhow::Context;
|
||||
|
||||
pub type RustlsConfig = rustls::ServerConfig;
|
||||
|
||||
pub fn create_rustls_config(
|
||||
@@ -7,7 +9,12 @@ pub fn create_rustls_config(
|
||||
tls_private_key_path: &Path,
|
||||
) -> anyhow::Result<RustlsConfig> {
|
||||
let certs = {
|
||||
let f = File::open(tls_certificate_path)?;
|
||||
let f = File::open(tls_certificate_path).with_context(|| {
|
||||
format!(
|
||||
"open tls certificate file at {}",
|
||||
tls_certificate_path.to_string_lossy()
|
||||
)
|
||||
})?;
|
||||
let mut f = BufReader::new(f);
|
||||
|
||||
rustls_pemfile::certs(&mut f)?
|
||||
@@ -17,7 +24,12 @@ pub fn create_rustls_config(
|
||||
};
|
||||
|
||||
let private_key = {
|
||||
let f = File::open(tls_private_key_path)?;
|
||||
let f = File::open(tls_private_key_path).with_context(|| {
|
||||
format!(
|
||||
"open tls private key file at {}",
|
||||
tls_private_key_path.to_string_lossy()
|
||||
)
|
||||
})?;
|
||||
let mut f = BufReader::new(f);
|
||||
|
||||
rustls_pemfile::pkcs8_private_keys(&mut f)?
|
||||
@@ -29,7 +41,8 @@ pub fn create_rustls_config(
|
||||
let tls_config = rustls::ServerConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_no_client_auth()
|
||||
.with_single_cert(certs, private_key)?;
|
||||
.with_single_cert(certs, private_key)
|
||||
.with_context(|| "create rustls config")?;
|
||||
|
||||
Ok(tls_config)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user