Skip to content

Commit 69aa6f4

Browse files
committed
Don't verify hostname when verify_hostname is false in tls_options
1 parent e25b881 commit 69aa6f4

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/net/ldap/connection.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ def open_connection(server)
5353
prepare_socket(server.merge(socket: @socket_class.new(host, port, socket_opts)), timeout)
5454
if encryption
5555
if encryption[:tls_options] &&
56-
encryption[:tls_options][:verify_mode] &&
57-
encryption[:tls_options][:verify_mode] == OpenSSL::SSL::VERIFY_NONE
56+
(encryption[:tls_options][:verify_mode] &&
57+
encryption[:tls_options][:verify_mode] == OpenSSL::SSL::VERIFY_NONE ||
58+
encryption[:tls_options].key?(:verify_hostname) &&
59+
encryption[:tls_options][:verify_hostname] == false)
5860
warn "not verifying SSL hostname of LDAPS server '#{host}:#{port}'"
5961
else
6062
@conn.post_connection_check(host)

test/integration/test_bind.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ def test_bind_tls_with_cafile
4747
@ldap.get_operation_result.inspect
4848
end
4949

50+
def test_bind_tls_with_bad_hostname_no_verify_hostname_no_ca_passes
51+
@ldap.host = INTEGRATION_HOSTNAME
52+
@ldap.encryption(
53+
method: :start_tls,
54+
tls_options: { verify_hostname: false },
55+
)
56+
assert @ldap.bind(BIND_CREDS),
57+
@ldap.get_operation_result.inspect
58+
end
59+
60+
def test_bind_tls_with_bad_hostname_no_verify_hostname_no_ca_opt_merge_passes
61+
@ldap.host = '127.0.0.1'
62+
@ldap.encryption(
63+
method: :start_tls,
64+
tls_options: TLS_OPTS.merge(verify_hostname: false),
65+
)
66+
assert @ldap.bind(BIND_CREDS),
67+
@ldap.get_operation_result.inspect
68+
end
69+
5070
def test_bind_tls_with_bad_hostname_verify_none_no_ca_passes
5171
@ldap.host = INTEGRATION_HOSTNAME
5272
@ldap.encryption(

0 commit comments

Comments
 (0)