http: use create_rustls_config from aquatic_common

This commit is contained in:
Joakim Frostegård 2022-04-03 19:43:44 +02:00
parent bf4b32748b
commit 610057a231
4 changed files with 11 additions and 41 deletions

View file

@ -2,15 +2,12 @@
use aquatic_common::cpu_pinning::{pin_current_if_configured_to, WorkerIndex};
use aquatic_common::{
access_list::update_access_list, privileges::drop_privileges_after_socket_binding,
rustls_config::create_rustls_config,
};
use common::{State, TlsConfig};
use common::State;
use glommio::{channels::channel_mesh::MeshBuilder, prelude::*};
use signal_hook::{consts::SIGUSR1, iterator::Signals};
use std::{
fs::File,
io::BufReader,
sync::{atomic::AtomicUsize, Arc},
};
use std::sync::{atomic::AtomicUsize, Arc};
use crate::config::Config;
@ -64,7 +61,10 @@ pub fn run_inner(config: Config, state: State) -> anyhow::Result<()> {
let num_bound_sockets = Arc::new(AtomicUsize::new(0));
let tls_config = Arc::new(create_tls_config(&config).unwrap());
let tls_config = Arc::new(create_rustls_config(
&config.network.tls_certificate_path,
&config.network.tls_private_key_path,
)?);
let mut executors = Vec::new();
@ -151,32 +151,3 @@ pub fn run_inner(config: Config, state: State) -> anyhow::Result<()> {
Ok(())
}
fn create_tls_config(config: &Config) -> anyhow::Result<TlsConfig> {
let certs = {
let f = File::open(&config.network.tls_certificate_path)?;
let mut f = BufReader::new(f);
rustls_pemfile::certs(&mut f)?
.into_iter()
.map(|bytes| futures_rustls::rustls::Certificate(bytes))
.collect()
};
let private_key = {
let f = File::open(&config.network.tls_private_key_path)?;
let mut f = BufReader::new(f);
rustls_pemfile::pkcs8_private_keys(&mut f)?
.first()
.map(|bytes| futures_rustls::rustls::PrivateKey(bytes.clone()))
.ok_or(anyhow::anyhow!("No private keys in file"))?
};
let tls_config = futures_rustls::rustls::ServerConfig::builder()
.with_safe_defaults()
.with_no_client_auth()
.with_single_cert(certs, private_key)?;
Ok(tls_config)
}