From 555d498f3860568486f552c996436b0b64f0e513 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 25 Jan 2025 13:51:32 -0500 Subject: [PATCH] Expose SSL_CTX_load_verify_locations --- openssl/src/ssl/mod.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index f5a696ab5..c341642a2 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -924,12 +924,23 @@ impl SslContextBuilder { /// The file should contain a sequence of PEM-formatted CA certificates. #[corresponds(SSL_CTX_load_verify_locations)] pub fn set_ca_file>(&mut self, file: P) -> Result<(), ErrorStack> { - let file = CString::new(file.as_ref().as_os_str().to_str().unwrap()).unwrap(); + self.load_verify_locations(Some(file.as_ref()), None) + } + + /// Loads trusted root certificates from a file and/or a directory. + #[corresponds(SSL_CTX_load_verify_locations)] + pub fn load_verify_locations( + &mut self, + ca_file: Option<&Path>, + ca_path: Option<&Path>, + ) -> Result<(), ErrorStack> { + let ca_file = ca_file.map(|p| CString::new(p.as_os_str().to_str().unwrap()).unwrap()); + let ca_path = ca_path.map(|p| CString::new(p.as_os_str().to_str().unwrap()).unwrap()); unsafe { cvt(ffi::SSL_CTX_load_verify_locations( self.as_ptr(), - file.as_ptr() as *const _, - ptr::null(), + ca_file.as_ref().map_or(ptr::null(), |s| s.as_ptr()), + ca_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()), )) .map(|_| ()) }