Skip to content

RUST-2144 Use recommended openssl probing API #1297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/runtime/tls_openssl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{pin::Pin, sync::Once};
use std::pin::Pin;

use openssl::{
error::ErrorStack,
Expand Down Expand Up @@ -45,8 +45,6 @@ pub(super) async fn tls_connect(
tcp_stream: TcpStream,
cfg: &TlsConfig,
) -> Result<TlsStream> {
init_trust();

let mut stream = make_ssl_stream(host, tcp_stream, cfg).map_err(|err| {
Error::from(ErrorKind::InvalidTlsConfig {
message: err.to_string(),
Expand All @@ -71,6 +69,11 @@ fn make_openssl_connector(cfg: TlsOptions) -> Result<SslConnector> {

let mut builder = SslConnector::builder(SslMethod::tls_client()).map_err(openssl_err)?;

let probe = openssl_probe::probe();
builder
.load_verify_locations(probe.cert_file.as_deref(), probe.cert_dir.as_deref())
.map_err(openssl_err)?;

let TlsOptions {
allow_invalid_certificates,
ca_file_path,
Expand Down Expand Up @@ -111,15 +114,6 @@ fn make_openssl_connector(cfg: TlsOptions) -> Result<SslConnector> {
Ok(builder.build())
}

fn init_trust() {
static ONCE: Once = Once::new();
// nosemgrep: unsafe-usage
ONCE.call_once(|| unsafe {
// mongodb rating: No Fix Needed
openssl_probe::init_openssl_env_vars()
})
}

fn make_ssl_stream(
host: &str,
tcp_stream: TcpStream,
Expand Down