Permalink
Browse files

Merge remote branch 'rabbit/master'

Conflicts:
	VERSION.yml
  • Loading branch information...
2 parents 887c6b6 + ee33048 commit 05e7bc11a10ec08be6971cc311dae5869e26258f Amos Elliston committed Dec 10, 2010
Showing with 29 additions and 0 deletions.
  1. +29 −0 lib/amqp/server.rb
View
@@ -2,6 +2,12 @@
require 'thread'
require 'timeout'
+begin
+ require 'openssl'
+rescue LoadError
+ warn "Unable to load SSL extension - you will be unable to make ssl connections."
+end
+
module Carrot::AMQP
class Server
CONNECT_TIMEOUT = 1.0
@@ -23,6 +29,9 @@ def initialize(opts = {})
@insist = opts[:insist]
@status = 'NOT CONNECTED'
+ @use_ssl = !!opts[:ssl]
+ @ssl_verify = opts[:ssl_verify] || OpenSSL::SSL::VERIFY_PEER
+
@multithread = opts[:multithread]
start_session
end
@@ -93,6 +102,23 @@ def send_command(cmd, *args)
end
end
+ def start_ssl
+ unless defined?(OpenSSL)
+ raise "SSL Extension not installed"
+ end
+
+ ctx = OpenSSL::SSL::SSLContext.new
+ ctx.verify_mode = @ssl_verify
+
+ @socket = OpenSSL::SSL::SSLSocket.new(@socket, ctx)
+ @socket.sync_close = true
+ @socket.connect
+
+ if ctx.verify_mode != OpenSSL::SSL::VERIFY_NONE
+ @socket.post_connection_check(@address)
+ end
+ end
+
def socket
return @socket if @socket and not @socket.closed?
@@ -106,6 +132,9 @@ def socket
if Socket.constants.include? 'TCP_NODELAY'
@socket.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
end
+
+ start_ssl if @use_ssl
+
@status = 'CONNECTED'
rescue SocketError, SystemCallError, IOError, Timeout::Error => e
msg = e.message << " - #{@host}:#{@port}"

0 comments on commit 05e7bc1

Please sign in to comment.