lib/net/ldap/connection.rb in net-ldap-0.17.1 vs lib/net/ldap/connection.rb in net-ldap-0.18.0

- old
+ new

@@ -31,13 +31,14 @@ end def prepare_socket(server, timeout=nil) socket = server[:socket] encryption = server[:encryption] + hostname = server[:host] @conn = socket - setup_encryption(encryption, timeout) if encryption + setup_encryption(encryption, timeout, hostname) if encryption end def open_connection(server) hosts = server[:hosts] encryption = server[:encryption] @@ -84,20 +85,21 @@ super io.close end end - def self.wrap_with_ssl(io, tls_options = {}, timeout=nil) + def self.wrap_with_ssl(io, tls_options = {}, timeout=nil, hostname=nil) raise Net::LDAP::NoOpenSSLError, "OpenSSL is unavailable" unless Net::LDAP::HasOpenSSL ctx = OpenSSL::SSL::SSLContext.new # By default, we do not verify certificates. For a 1.0 release, this should probably be changed at some point. # See discussion in https://github.com/ruby-ldap/ruby-net-ldap/pull/161 ctx.set_params(tls_options) unless tls_options.empty? conn = OpenSSL::SSL::SSLSocket.new(io, ctx) + conn.hostname = hostname begin if timeout conn.connect_nonblock else @@ -146,15 +148,15 @@ # The start_tls method is supported by many servers over the standard LDAP # port. It does not require an alternative port for encrypted # communications, as with simple_tls. Thanks for Kouhei Sutou for # generously contributing the :start_tls path. #++ - def setup_encryption(args, timeout=nil) + def setup_encryption(args, timeout=nil, hostname=nil) args[:tls_options] ||= {} case args[:method] when :simple_tls - @conn = self.class.wrap_with_ssl(@conn, args[:tls_options], timeout) + @conn = self.class.wrap_with_ssl(@conn, args[:tls_options], timeout, hostname) # additional branches requiring server validation and peer certs, etc. # go here. when :start_tls message_id = next_msgid request = [ @@ -168,10 +170,10 @@ raise Net::LDAP::NoStartTLSResultError, "no start_tls result" end raise Net::LDAP::StartTLSError, "start_tls failed: #{pdu.result_code}" unless pdu.result_code.zero? - @conn = self.class.wrap_with_ssl(@conn, args[:tls_options], timeout) + @conn = self.class.wrap_with_ssl(@conn, args[:tls_options], timeout, hostname) else raise Net::LDAP::EncMethodUnsupportedError, "unsupported encryption method #{args[:method]}" end end