! Fixes that last ssl topic

This commit is contained in:
Kaspar Schiess 2010-02-12 15:08:56 +01:00
parent 1509aa8ef6
commit b849681f5f
3 changed files with 456 additions and 446 deletions

View file

@ -1129,8 +1129,6 @@ module Net
end # class LDAP
class LDAP
# This is a private class used internally by the library. It should not be called by user code.
class Connection # :nodoc:
@ -1156,6 +1154,21 @@ module Net
yield self if block_given?
end
module GetbyteForSSLSocket
def getbyte
getc.ord
end
end
def self.wrap_with_ssl(io)
ctx = OpenSSL::SSL::SSLContext.new
conn = OpenSSL::SSL::SSLSocket.new(io, ctx)
conn.connect
conn.sync_close = true
conn.extend(GetbyteForSSLSocket) unless conn.respond_to?(:getbyte)
conn
end
#--
# Helper method called only from new, and only after we have a successfully-opened
@ -1186,10 +1199,7 @@ module Net
def setup_encryption args
case args[:method]
when :simple_tls
ctx = OpenSSL::SSL::SSLContext.new
@conn = OpenSSL::SSL::SSLSocket.new(@conn, ctx)
@conn.connect
@conn.sync_close = true
@conn = self.class.wrap_with_ssl(@conn)
# additional branches requiring server validation and peer certs, etc. go here.
when :start_tls
msgid = next_msgid.to_ber
@ -1201,10 +1211,7 @@ module Net
pdu = Net::LdapPdu.new(be)
raise LdapError.new("no start_tls result") if pdu.nil?
if pdu.result_code.zero?
ctx = OpenSSL::SSL::SSLContext.new
@conn = OpenSSL::SSL::SSLSocket.new(@conn, ctx)
@conn.connect
@conn.sync_close = true
@conn = self.class.wrap_with_ssl(@conn)
else
raise LdapError.new("start_tls failed: #{pdu.result_code}")
end
@ -1578,8 +1585,6 @@ module Net
end # class Connection
end # class LDAP
end # module Net

View file

@ -19,8 +19,11 @@ describe "BER serialisation (SSL)" do
before(:each) do
@from, @to = IO.pipe
@to = Net::LDAP::SSLSocket.wrap(to)
@from = Net::LDAP::SSLSocket.wrap(from)
flexmock(OpenSSL::SSL::SSLSocket).
new_instances.should_receive(:connect => nil)
@to = Net::LDAP::Connection.wrap_with_ssl(to)
@from = Net::LDAP::Connection.wrap_with_ssl(from)
end
it "should transmit strings" do

View file

@ -1 +1,3 @@
Spec::Runner.configure do |config|
config.mock_with :flexmock
end