def initialize(params = {}, proxy = nil)
super
ssl_context = OpenSSL::SSL::SSLContext.new
if params[:ssl_verify_peer]
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
if params[:ssl_ca_path]
ssl_context.ca_path = params[:ssl_ca_path]
elsif params[:ssl_ca_file]
ssl_context.ca_file = params[:ssl_ca_file]
else
store = OpenSSL::X509::Store.new
store.set_default_paths
ssl_context.cert_store = store
end
else
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
if @params.has_key?(:client_cert) && @params.has_key?(:client_key)
ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(@params[:client_cert]))
ssl_context.key = OpenSSL::PKey::RSA.new(File.read(@params[:client_key]))
end
@socket = OpenSSL::SSL::SSLSocket.new(@socket, ssl_context)
@socket.sync_close = true
if @proxy
@socket << "CONNECT " << @params[:host] << ":" << @params[:port] << Excon::HTTP_1_1
@socket << "Host: " << @params[:host] << ":" << @params[:port] << Excon::CR_NL << Excon::CR_NL
while line = @socket.readline.strip
break if line.empty?
end
end
@socket.connect
if params[:ssl_verify_peer]
@socket.post_connection_check(@params[:host])
end
@socket
end