Skip to content
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

ssl: raise SSLError if loading ca_file or ca_path fails #659

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions ext/openssl/ossl_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,9 +885,9 @@ ossl_sslctx_setup(VALUE self)
if (ca_path && !SSL_CTX_load_verify_dir(ctx, ca_path))
ossl_raise(eSSLError, "SSL_CTX_load_verify_dir");
#else
if(ca_file || ca_path){
if (!SSL_CTX_load_verify_locations(ctx, ca_file, ca_path))
rb_warning("can't set verify locations");
if (ca_file || ca_path) {
if (!SSL_CTX_load_verify_locations(ctx, ca_file, ca_path))
ossl_raise(eSSLError, "SSL_CTX_load_verify_locations");
}
#endif

Expand Down
34 changes: 34 additions & 0 deletions test/openssl/test_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,40 @@ def test_exception_in_verify_callback_is_ignored
}
end

def test_ca_file
start_server(ignore_listener_error: true) { |port|
# X509_STORE is shared; setting ca_file to SSLContext affects store
store = OpenSSL::X509::Store.new
assert_equal false, store.verify(@svr_cert)

ctx = Tempfile.create("ca_cert.pem") { |f|
f.puts(@ca_cert.to_pem)
f.close

ctx = OpenSSL::SSL::SSLContext.new
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
ctx.cert_store = store
ctx.ca_file = f.path
ctx.setup
ctx
}
assert_nothing_raised {
server_connect(port, ctx) { |ssl| ssl.puts("abc"); ssl.gets }
}
assert_equal true, store.verify(@svr_cert)
}
end

def test_ca_file_not_found
path = Tempfile.create("ca_cert.pem") { |f| f.path }
ctx = OpenSSL::SSL::SSLContext.new
ctx.ca_file = path
# OpenSSL >= 1.1.0: /no certificate or crl found/
assert_raise(OpenSSL::SSL::SSLError) {
ctx.setup
}
end

def test_finished_messages
server_finished = nil
server_peer_finished = nil
Expand Down