Skip to content

Commit 8ac40ba

Browse files
authored
Merge pull request #659 from rhenium/ky/ssl-ca-file-ca-path-raise
ssl: raise SSLError if loading ca_file or ca_path fails
2 parents 3f45150 + 7eb10f7 commit 8ac40ba

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

ext/openssl/ossl_ssl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,9 +885,9 @@ ossl_sslctx_setup(VALUE self)
885885
if (ca_path && !SSL_CTX_load_verify_dir(ctx, ca_path))
886886
ossl_raise(eSSLError, "SSL_CTX_load_verify_dir");
887887
#else
888-
if(ca_file || ca_path){
889-
if (!SSL_CTX_load_verify_locations(ctx, ca_file, ca_path))
890-
rb_warning("can't set verify locations");
888+
if (ca_file || ca_path) {
889+
if (!SSL_CTX_load_verify_locations(ctx, ca_file, ca_path))
890+
ossl_raise(eSSLError, "SSL_CTX_load_verify_locations");
891891
}
892892
#endif
893893

test/openssl/test_ssl.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,40 @@ def test_exception_in_verify_callback_is_ignored
481481
}
482482
end
483483

484+
def test_ca_file
485+
start_server(ignore_listener_error: true) { |port|
486+
# X509_STORE is shared; setting ca_file to SSLContext affects store
487+
store = OpenSSL::X509::Store.new
488+
assert_equal false, store.verify(@svr_cert)
489+
490+
ctx = Tempfile.create("ca_cert.pem") { |f|
491+
f.puts(@ca_cert.to_pem)
492+
f.close
493+
494+
ctx = OpenSSL::SSL::SSLContext.new
495+
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
496+
ctx.cert_store = store
497+
ctx.ca_file = f.path
498+
ctx.setup
499+
ctx
500+
}
501+
assert_nothing_raised {
502+
server_connect(port, ctx) { |ssl| ssl.puts("abc"); ssl.gets }
503+
}
504+
assert_equal true, store.verify(@svr_cert)
505+
}
506+
end
507+
508+
def test_ca_file_not_found
509+
path = Tempfile.create("ca_cert.pem") { |f| f.path }
510+
ctx = OpenSSL::SSL::SSLContext.new
511+
ctx.ca_file = path
512+
# OpenSSL >= 1.1.0: /no certificate or crl found/
513+
assert_raise(OpenSSL::SSL::SSLError) {
514+
ctx.setup
515+
}
516+
end
517+
484518
def test_finished_messages
485519
server_finished = nil
486520
server_peer_finished = nil

0 commit comments

Comments
 (0)