add support for local trust store for rustls

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
schnell 2024-08-22 12:24:58 +02:00 committed by Maxime “pep” Buquet
commit 274baaef9a
No known key found for this signature in database
GPG key ID: DEDA74AEECA9D0F2
2 changed files with 14 additions and 5 deletions

View file

@ -120,9 +120,15 @@ async fn get_tls_stream<S: AsyncRead + AsyncWrite + Unpin>(
let domain = xmpp_stream.jid.domain().to_string();
let domain = ServerName::try_from(domain).map_err(|e| StartTlsError::DnsNameError(e))?;
let stream = xmpp_stream.into_inner();
let root_store = RootCertStore {
roots: webpki_roots::TLS_SERVER_ROOTS.into(),
};
let mut root_store = RootCertStore::empty();
#[cfg(feature = "webpki-roots")]
{
root_store.extend(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
}
#[cfg(feature = "rustls-native-certs")]
{
root_store.add_parsable_certificates(rustls_native_certs::load_native_certs()?);
}
let config = ClientConfig::builder()
.with_root_certificates(root_store)
.with_no_client_auth();