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

Fix TLS connections not verified by default #900

Merged
merged 1 commit into from May 1, 2020
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
4 changes: 3 additions & 1 deletion lib/redis/connection/ruby.rb
Expand Up @@ -263,7 +263,9 @@ def self.connect(host, port, timeout, ssl_params)
tcp_sock = TCPSocket.connect(host, port, timeout)

ctx = OpenSSL::SSL::SSLContext.new
ctx.set_params(ssl_params) if ssl_params && !ssl_params.empty?

# The provided parameters are merged into OpenSSL::SSL::SSLContext::DEFAULT_PARAMS
ctx.set_params(ssl_params || {})

ssl_sock = new(tcp_sock, ctx)
ssl_sock.hostname = host
Expand Down
9 changes: 9 additions & 0 deletions test/ssl_test.rb
Expand Up @@ -30,6 +30,15 @@ def test_unverified_ssl_connection
end
end

def test_verify_certificates_by_default
assert_raises(OpenSSL::SSL::SSLError) do
RedisMock.start({ :ping => proc { "+PONG" } }, ssl_server_opts("untrusted")) do |port|
redis = Redis.new(:port => port, :ssl => true)
redis.ping
end
end
end

def test_ssl_blocking
RedisMock.start({}, ssl_server_opts("trusted")) do |port|
redis = Redis.new(:port => port, :ssl => true, :ssl_params => { :ca_file => ssl_ca_file })
Expand Down