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

Don't verify hostname when verify_hostname is false in tls_options #349

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/net/ldap/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ def open_connection(server)
prepare_socket(server.merge(socket: @socket_class.new(host, port, socket_opts)), timeout, host)
if encryption
if encryption[:tls_options] &&
encryption[:tls_options][:verify_mode] &&
encryption[:tls_options][:verify_mode] == OpenSSL::SSL::VERIFY_NONE
(encryption[:tls_options][:verify_mode] &&
encryption[:tls_options][:verify_mode] == OpenSSL::SSL::VERIFY_NONE ||
encryption[:tls_options].key?(:verify_hostname) &&
encryption[:tls_options][:verify_hostname] == false)
warn "not verifying SSL hostname of LDAPS server '#{host}:#{port}'"
else
@conn.post_connection_check(host)
Expand Down
28 changes: 28 additions & 0 deletions test/integration/test_bind.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ def test_bind_tls_with_cafile
@ldap.get_operation_result.inspect
end

def test_bind_tls_with_bad_hostname_no_verify_hostname_no_ca_passes
omit_unless TLS_OPTS.key?(:verify_hostname)

@ldap.host = '127.0.0.1'
@ldap.encryption(
method: :start_tls,
tls_options: { verify_mode: OpenSSL::SSL::VERIFY_PEER,
verify_hostname: false,
ca_file: CA_FILE },
)
assert @ldap.bind(BIND_CREDS),
@ldap.get_operation_result.inspect
end

def test_bind_tls_with_bad_hostname_no_verify_hostname_no_ca_opt_merge_passes
omit_unless TLS_OPTS.key?(:verify_hostname)

@ldap.host = '127.0.0.1'
@ldap.encryption(
method: :start_tls,
tls_options: TLS_OPTS.merge(verify_mode: OpenSSL::SSL::VERIFY_PEER,
verify_hostname: false,
ca_file: CA_FILE),
)
assert @ldap.bind(BIND_CREDS),
@ldap.get_operation_result.inspect
end

def test_bind_tls_with_bad_hostname_verify_none_no_ca_passes
@ldap.host = INTEGRATION_HOSTNAME
@ldap.encryption(
Expand Down
Loading