Skip to content

Commit c6dfef8

Browse files
abr-egnisabelatkinson
authored andcommitted
RUST-2144 Use recommended openssl probing API (mongodb#1297)
1 parent 2739e49 commit c6dfef8

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/runtime/tls_openssl.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{pin::Pin, sync::Once};
1+
use std::pin::Pin;
22

33
use openssl::{
44
error::ErrorStack,
@@ -45,8 +45,6 @@ pub(super) async fn tls_connect(
4545
tcp_stream: TcpStream,
4646
cfg: &TlsConfig,
4747
) -> Result<TlsStream> {
48-
init_trust();
49-
5048
let mut stream = make_ssl_stream(host, tcp_stream, cfg).map_err(|err| {
5149
Error::from(ErrorKind::InvalidTlsConfig {
5250
message: err.to_string(),
@@ -71,6 +69,11 @@ fn make_openssl_connector(cfg: TlsOptions) -> Result<SslConnector> {
7169

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

72+
let probe = openssl_probe::probe();
73+
builder
74+
.load_verify_locations(probe.cert_file.as_deref(), probe.cert_dir.as_deref())
75+
.map_err(openssl_err)?;
76+
7477
let TlsOptions {
7578
allow_invalid_certificates,
7679
ca_file_path,
@@ -111,15 +114,6 @@ fn make_openssl_connector(cfg: TlsOptions) -> Result<SslConnector> {
111114
Ok(builder.build())
112115
}
113116

114-
fn init_trust() {
115-
static ONCE: Once = Once::new();
116-
// nosemgrep: unsafe-usage
117-
ONCE.call_once(|| unsafe {
118-
// mongodb rating: No Fix Needed
119-
openssl_probe::init_openssl_env_vars()
120-
})
121-
}
122-
123117
fn make_ssl_stream(
124118
host: &str,
125119
tcp_stream: TcpStream,

0 commit comments

Comments
 (0)