-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move ClientConfig construction to tls/client_config.rs
- Loading branch information
1 parent
f0ae01a
commit 25b2de3
Showing
6 changed files
with
54 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::sync::Arc; | ||
|
||
use anyhow::bail; | ||
use rustls::crypto::ring; | ||
|
||
pub(crate) fn load_certs() -> anyhow::Result<Arc<rustls::RootCertStore>> { | ||
let der_certs = rustls_native_certs::load_native_certs(); | ||
|
||
if !der_certs.errors.is_empty() { | ||
bail!("could not parse certificates: {:?}", der_certs.errors); | ||
} | ||
|
||
let mut store = rustls::RootCertStore::empty(); | ||
store.add_parsable_certificates(der_certs.certs); | ||
Ok(Arc::new(store)) | ||
} | ||
|
||
/// Loads the root certificates and constructs a client config suitable for connecting to the neon compute. | ||
/// This function is blocking. | ||
pub fn compute_client_config_with_root_certs() -> anyhow::Result<rustls::ClientConfig> { | ||
Ok( | ||
rustls::ClientConfig::builder_with_provider(Arc::new(ring::default_provider())) | ||
.with_safe_default_protocol_versions() | ||
.expect("ring should support the default protocol versions") | ||
.with_root_certificates(load_certs()?) | ||
.with_no_client_auth(), | ||
) | ||
} | ||
|
||
#[cfg(test)] | ||
pub fn compute_client_config_with_certs( | ||
certs: impl IntoIterator<Item = rustls::pki_types::CertificateDer<'static>>, | ||
) -> rustls::ClientConfig { | ||
let mut store = rustls::RootCertStore::empty(); | ||
store.add_parsable_certificates(certs); | ||
|
||
rustls::ClientConfig::builder_with_provider(Arc::new(ring::default_provider())) | ||
.with_safe_default_protocol_versions() | ||
.expect("ring should support the default protocol versions") | ||
.with_root_certificates(store) | ||
.with_no_client_auth() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod client_config; | ||
pub mod postgres_rustls; | ||
pub mod server_config; | ||
|
||
|