Skip to content

Commit

Permalink
Merge pull request ruby-amqp#33 from jbarciauskas/feature-sslopts
Browse files Browse the repository at this point in the history
Add support for SSL client certificates
  • Loading branch information
michaelklishin committed Jan 17, 2012
2 parents 1aba6b8 + 48bcd54 commit c3cc3d2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/qrack/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def initialize(connection_string_or_opts = Hash.new, opts = Hash.new)
@logfile = opts[:logfile] || nil
@logging = opts[:logging] || false
@ssl = opts[:ssl] || false
@ssl_cert = opts[:ssl_cert] || nil
@ssl_key = opts[:ssl_key] || nil
@verify_ssl = opts[:verify_ssl].nil? || opts[:verify_ssl]
@status = :not_connected
@frame_max = opts[:frame_max] || 131072
Expand Down Expand Up @@ -203,7 +205,16 @@ def socket

if @ssl
require 'openssl' unless defined? OpenSSL::SSL
@socket = OpenSSL::SSL::SSLSocket.new(@socket)
sslctx = OpenSSL::SSL::SSLContext.new
if @ssl_cert
cert_file = File.open(@ssl_cert)
sslctx.cert = OpenSSL::X509::Certificate.new(cert_file.read)
end
if @ssl_key
key_file = File.open(@ssl_key)
sslctx.key = OpenSSL::PKey::RSA.new(key_file.read)
end
@socket = OpenSSL::SSL::SSLSocket.new(@socket, sslctx)
@socket.sync_close = true
@socket.connect
@socket.post_connection_check(host) if @verify_ssl
Expand Down

0 comments on commit c3cc3d2

Please sign in to comment.