Skip to content

Commit cd3971b

Browse files
committed
ssl: use SSL_CTX_load_verify_{file,dir}() if available
SSL_CTX_load_verify_locations() is deprecated in OpenSSL 3.0 and replaced with those two separate functions. Use them if they exist.
1 parent d4c5afb commit cd3971b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

ext/openssl/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def find_openssl_library
174174
have_func("SSL_set0_tmp_dh_pkey")
175175
have_func("ERR_get_error_all")
176176
have_func("TS_VERIFY_CTX_set_certs(NULL, NULL)", "openssl/ts.h")
177+
have_func("SSL_CTX_load_verify_file")
177178

178179
Logging::message "=== Checking done. ===\n"
179180

ext/openssl/ossl_ssl.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,10 +828,17 @@ ossl_sslctx_setup(VALUE self)
828828
ca_file = NIL_P(val) ? NULL : StringValueCStr(val);
829829
val = rb_attr_get(self, id_i_ca_path);
830830
ca_path = NIL_P(val) ? NULL : StringValueCStr(val);
831+
#ifdef HAVE_SSL_CTX_LOAD_VERIFY_FILE
832+
if (ca_file && !SSL_CTX_load_verify_file(ctx, ca_file))
833+
ossl_raise(eSSLError, "SSL_CTX_load_verify_file");
834+
if (ca_path && !SSL_CTX_load_verify_dir(ctx, ca_path))
835+
ossl_raise(eSSLError, "SSL_CTX_load_verify_dir");
836+
#else
831837
if(ca_file || ca_path){
832838
if (!SSL_CTX_load_verify_locations(ctx, ca_file, ca_path))
833839
rb_warning("can't set verify locations");
834840
}
841+
#endif
835842

836843
val = rb_attr_get(self, id_i_verify_mode);
837844
verify_mode = NIL_P(val) ? SSL_VERIFY_NONE : NUM2INT(val);

0 commit comments

Comments
 (0)