From: Brian Candler Date: 2010-05-02T17:43:58+09:00 Subject: Re: Upgrading a socket to an SSLSocket Baduk Baduk wrote: > Is it possible to 'upgrade' a normal socket to an SSL socket. I would > like to transmit and receive some data in plain text initially, before > performing the SSL handshake and start communicating securely, without > having to close and create a new socket. > > Does anyone have an example of this, preferably the more complete the > better =) There's a complete working example of this in ruby-ldapserver, see lib/ldap/server/connection.rb. The core is: def startssl # :yields: @mutex.synchronize do raise LDAP::ResultError::OperationsError if @ssl or @active_reqs.size > 0 yield if block_given? @io = OpenSSL::SSL::SSLSocket.new(@io, @opt[:ssl_ctx]) @io.sync_close = true @io.accept @ssl = true end end -- Posted via http://www.ruby-forum.com/.