lib/plezi/eventmachine/ssl_connection.rb in plezi-0.8.4 vs lib/plezi/eventmachine/ssl_connection.rb in plezi-0.8.5

- old
+ new

@@ -10,11 +10,17 @@ class SSLConnection < Connection #the SSL socket attr_reader :ssl_socket def initialize socket, params - if params[:ssl] || params[:ssl_key] || params[:ssl_cert] + if params[:ssl_client] + context = OpenSSL::SSL::SSLContext.new + context.set_params verify_mode: OpenSSL::SSL::VERIFY_NONE # OpenSSL::SSL::VERIFY_PEER #OpenSSL::SSL::VERIFY_NONE + @ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, context) + @ssl_socket.sync_close = true + @ssl_socket.connect + elsif params[:ssl] || params[:ssl_key] || params[:ssl_cert] params[:ssl_cert], params[:ssl_key] = SSLConnection.self_cert unless params[:ssl_key] && params[:ssl_cert] context = OpenSSL::SSL::SSLContext.new context.set_params verify_mode: OpenSSL::SSL::VERIFY_NONE # OpenSSL::SSL::VERIFY_PEER #OpenSSL::SSL::VERIFY_NONE # context.options DoNotReverseLookup: true context.cert, context.key = params[:ssl_cert], params[:ssl_key] @@ -22,11 +28,11 @@ context.cert_store.set_default_paths @ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, context) @ssl_socket.sync_close = true @ssl_socket.accept end - raise "Not an SSL connection or SSL Socket creation failed" unless ssl_socket + raise "Not an SSL connection or SSL Socket creation failed" unless @ssl_socket super end # returns an IO-like object used for reading/writing (unlike the original IO object, this can be an SSL layer or any other wrapper object). @@ -66,10 +72,10 @@ # this is a public method and it should be used by child classes to implement each # read(_nonblock) action. accepts one argument ::size for an optional buffer size to be read. def read size = 1048576 data = '' begin - loop { data << @ssl_socket.read_nonblock(size).to_s } + (data << @ssl_socket.read_nonblock(size).to_s) until data.bytesize >= size rescue => e end return false if data.to_s.empty? touch