mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
Improve rustls config creation error messages
This commit is contained in:
parent
45e28cc39a
commit
608957a54b
1 changed files with 16 additions and 3 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
use std::{fs::File, io::BufReader, path::Path};
|
use std::{fs::File, io::BufReader, path::Path};
|
||||||
|
|
||||||
|
use anyhow::Context;
|
||||||
|
|
||||||
pub type RustlsConfig = rustls::ServerConfig;
|
pub type RustlsConfig = rustls::ServerConfig;
|
||||||
|
|
||||||
pub fn create_rustls_config(
|
pub fn create_rustls_config(
|
||||||
|
|
@ -7,7 +9,12 @@ pub fn create_rustls_config(
|
||||||
tls_private_key_path: &Path,
|
tls_private_key_path: &Path,
|
||||||
) -> anyhow::Result<RustlsConfig> {
|
) -> anyhow::Result<RustlsConfig> {
|
||||||
let certs = {
|
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);
|
let mut f = BufReader::new(f);
|
||||||
|
|
||||||
rustls_pemfile::certs(&mut f)?
|
rustls_pemfile::certs(&mut f)?
|
||||||
|
|
@ -17,7 +24,12 @@ pub fn create_rustls_config(
|
||||||
};
|
};
|
||||||
|
|
||||||
let private_key = {
|
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);
|
let mut f = BufReader::new(f);
|
||||||
|
|
||||||
rustls_pemfile::pkcs8_private_keys(&mut f)?
|
rustls_pemfile::pkcs8_private_keys(&mut f)?
|
||||||
|
|
@ -29,7 +41,8 @@ pub fn create_rustls_config(
|
||||||
let tls_config = rustls::ServerConfig::builder()
|
let tls_config = rustls::ServerConfig::builder()
|
||||||
.with_safe_defaults()
|
.with_safe_defaults()
|
||||||
.with_no_client_auth()
|
.with_no_client_auth()
|
||||||
.with_single_cert(certs, private_key)?;
|
.with_single_cert(certs, private_key)
|
||||||
|
.with_context(|| "create rustls config")?;
|
||||||
|
|
||||||
Ok(tls_config)
|
Ok(tls_config)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue