@@ -33,9 +33,10 @@ def socket_class=(socket_class)
33
33
def prepare_socket ( server , timeout = nil )
34
34
socket = server [ :socket ]
35
35
encryption = server [ :encryption ]
36
+ hostname = server [ :host ]
36
37
37
38
@conn = socket
38
- setup_encryption ( encryption , timeout ) if encryption
39
+ setup_encryption ( encryption , timeout , hostname ) if encryption
39
40
end
40
41
41
42
def open_connection ( server )
@@ -86,7 +87,7 @@ def close
86
87
end
87
88
end
88
89
89
- def self . wrap_with_ssl ( io , tls_options = { } , timeout = nil )
90
+ def self . wrap_with_ssl ( io , tls_options = { } , timeout = nil , hostname = nil )
90
91
raise Net ::LDAP ::NoOpenSSLError , "OpenSSL is unavailable" unless Net ::LDAP ::HasOpenSSL
91
92
92
93
ctx = OpenSSL ::SSL ::SSLContext . new
@@ -96,6 +97,7 @@ def self.wrap_with_ssl(io, tls_options = {}, timeout=nil)
96
97
ctx . set_params ( tls_options ) unless tls_options . empty?
97
98
98
99
conn = OpenSSL ::SSL ::SSLSocket . new ( io , ctx )
100
+ conn . hostname = hostname
99
101
100
102
begin
101
103
if timeout
@@ -148,11 +150,11 @@ def self.wrap_with_ssl(io, tls_options = {}, timeout=nil)
148
150
# communications, as with simple_tls. Thanks for Kouhei Sutou for
149
151
# generously contributing the :start_tls path.
150
152
#++
151
- def setup_encryption ( args , timeout = nil )
153
+ def setup_encryption ( args , timeout = nil , hostname = nil )
152
154
args [ :tls_options ] ||= { }
153
155
case args [ :method ]
154
156
when :simple_tls
155
- @conn = self . class . wrap_with_ssl ( @conn , args [ :tls_options ] , timeout )
157
+ @conn = self . class . wrap_with_ssl ( @conn , args [ :tls_options ] , timeout , hostname )
156
158
# additional branches requiring server validation and peer certs, etc.
157
159
# go here.
158
160
when :start_tls
@@ -170,7 +172,7 @@ def setup_encryption(args, timeout=nil)
170
172
171
173
raise Net ::LDAP ::StartTLSError ,
172
174
"start_tls failed: #{ pdu . result_code } " unless pdu . result_code . zero?
173
- @conn = self . class . wrap_with_ssl ( @conn , args [ :tls_options ] , timeout )
175
+ @conn = self . class . wrap_with_ssl ( @conn , args [ :tls_options ] , timeout , hostname )
174
176
else
175
177
raise Net ::LDAP ::EncMethodUnsupportedError , "unsupported encryption method #{ args [ :method ] } "
176
178
end
0 commit comments