Merge branch 'master' into cpu-pinning-2022-03-30

This commit is contained in:
Joakim Frostegård 2022-04-04 22:49:25 +02:00
commit 908e18360c
63 changed files with 2513 additions and 446 deletions

View file

@ -14,9 +14,10 @@ name = "aquatic_common"
[features]
with-glommio = ["glommio"]
with-hwloc = ["hwloc"]
rustls-config = ["rustls", "rustls-pemfile"]
[dependencies]
aquatic_toml_config = "0.2.0"
aquatic_toml_config = { version = "0.2.0", path = "../aquatic_toml_config" }
ahash = "0.7"
anyhow = "1"
@ -34,3 +35,7 @@ serde = { version = "1", features = ["derive"] }
# Optional
glommio = { version = "0.7", optional = true }
hwloc = { version = "0.5", optional = true }
# rustls-config
rustls = { version = "0.20", optional = true }
rustls-pemfile = { version = "0.3", optional = true }

View file

@ -7,6 +7,8 @@ use rand::Rng;
pub mod access_list;
pub mod cpu_pinning;
pub mod privileges;
#[cfg(feature = "rustls-config")]
pub mod rustls_config;
/// Amortized IndexMap using AHash hasher
pub type AmortizedIndexMap<K, V> = indexmap_amortized::IndexMap<K, V, RandomState>;

View file

@ -0,0 +1,35 @@
use std::{fs::File, io::BufReader, path::Path};
pub type RustlsConfig = rustls::ServerConfig;
pub fn create_rustls_config(
tls_certificate_path: &Path,
tls_private_key_path: &Path,
) -> anyhow::Result<RustlsConfig> {
let certs = {
let f = File::open(tls_certificate_path)?;
let mut f = BufReader::new(f);
rustls_pemfile::certs(&mut f)?
.into_iter()
.map(|bytes| rustls::Certificate(bytes))
.collect()
};
let private_key = {
let f = File::open(tls_private_key_path)?;
let mut f = BufReader::new(f);
rustls_pemfile::pkcs8_private_keys(&mut f)?
.first()
.map(|bytes| rustls::PrivateKey(bytes.clone()))
.ok_or(anyhow::anyhow!("No private keys in file"))?
};
let tls_config = rustls::ServerConfig::builder()
.with_safe_defaults()
.with_no_client_auth()
.with_single_cert(certs, private_key)?;
Ok(tls_config)
}