lib/ronin/network/ssl.rb in ronin-support-0.5.0 vs lib/ronin/network/ssl.rb in ronin-support-0.5.1

- old
+ new

@@ -40,14 +40,12 @@ # @since 1.3.0 # # @api private # VERIFY = Hash.new do |hash,key| - verify_const = if key - "VERIFY_#{key.to_s.upcase}" - else - 'VERIFY_NONE' + verify_const = if key then "VERIFY_#{key.to_s.upcase}" + else 'VERIFY_NONE' end unless OpenSSL::SSL.const_defined?(verify_const) raise(RuntimeError,"unknown verify mode #{key}") end @@ -106,22 +104,23 @@ # def ssl_connect(host,port,options={}) local_host = options[:local_host] local_port = options[:local_port] + cert = options[:cert] + key = options[:key] + socket = tcp_connect(host,port,local_host,local_port) ssl_context = OpenSSL::SSL::SSLContext.new() ssl_context.verify_mode = SSL::VERIFY[options[:verify]] - if options[:cert] - cert_file = File.new(options[:cert]) - ssl_context.cert = OpenSSL::X509::Certificate.new(cert_file) + if cert + ssl_context.cert = OpenSSL::X509::Certificate.new(File.new(cert)) end - if options[:key] - key_file = File.new(options[:key]) - ssl_context.key = OpenSSL::PKey::RSA.new(key_file) + if key + ssl_context.key = OpenSSL::PKey::RSA.new(File.new(key)) end ssl_socket = OpenSSL::SSL::SSLSocket.new(socket,ssl_context) ssl_socket.sync_close = true ssl_socket.connect