update ws dependencies as well as http rustls dependency

This commit is contained in:
Joakim Frostegård 2024-01-07 10:40:50 +01:00
parent 071f088d8b
commit 3042539101
16 changed files with 499 additions and 295 deletions

View file

@ -37,5 +37,5 @@ toml = "0.5"
# Optional
glommio = { version = "0.8", optional = true }
hwloc = { version = "0.5", optional = true }
rustls = { version = "0.21", optional = true }
rustls-pemfile = { version = "1", optional = true }
rustls = { version = "0.22", optional = true }
rustls-pemfile = { version = "2", optional = true }

View file

@ -17,10 +17,20 @@ pub fn create_rustls_config(
})?;
let mut f = BufReader::new(f);
rustls_pemfile::certs(&mut f)?
.into_iter()
.map(|bytes| rustls::Certificate(bytes))
.collect()
let mut certs = Vec::new();
for cert in rustls_pemfile::certs(&mut f) {
match cert {
Ok(cert) => {
certs.push(cert);
}
Err(err) => {
::log::error!("error parsing certificate: {:#?}", err)
}
}
}
certs
};
let private_key = {
@ -32,16 +42,16 @@ pub fn create_rustls_config(
})?;
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 key = rustls_pemfile::pkcs8_private_keys(&mut f)
.next()
.ok_or(anyhow::anyhow!("No private keys in file"))??;
key
};
let tls_config = rustls::ServerConfig::builder()
.with_safe_defaults()
.with_no_client_auth()
.with_single_cert(certs, private_key)
.with_single_cert(certs, rustls::pki_types::PrivateKeyDer::Pkcs8(private_key))
.with_context(|| "create rustls config")?;
Ok(tls_config)