Sha256: bd690365c6e9ccaf8b5228e202b6cfd0394fb7e79718571fc776832c0ace36b5

Contents?: true

Size: 1.3 KB

Versions: 75

Compression:

Stored size: 1.3 KB

Contents

require 'openssl'
require 'em-http'

module EmHttpSslPatch
  def ssl_verify_peer(cert_string)
    cert = nil
    begin
      cert = OpenSSL::X509::Certificate.new(cert_string)
    rescue OpenSSL::X509::CertificateError
      return false
    end

    @last_seen_cert = cert

    if certificate_store.verify(@last_seen_cert)
      begin
        certificate_store.add_cert(@last_seen_cert)
      rescue OpenSSL::X509::StoreError => e
        raise e unless e.message == 'cert already in hash table'
      end
      true
    else
      raise OpenSSL::SSL::SSLError.new(%(unable to verify the server certificate for "#{host}"))
    end
  end

  def ssl_handshake_completed
    return true unless verify_peer?

    unless OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
      raise OpenSSL::SSL::SSLError.new(%(host "#{host}" does not match the server certificate))
    else
      true
    end
  end

  def verify_peer?
    parent.connopts.tls[:verify_peer]
  end

  def host
    parent.uri.host
  end

  def certificate_store
    @certificate_store ||= begin
      store = OpenSSL::X509::Store.new
      store.set_default_paths
      ca_file = parent.connopts.tls[:cert_chain_file]
      store.add_file(ca_file) if ca_file
      store
    end
  end
end

EventMachine::HttpStubConnection.send(:include, EmHttpSslPatch)

Version data entries

75 entries across 67 versions & 6 rubygems

Version Path
faraday-0.17.6 lib/faraday/adapter/em_http_ssl_patch.rb
faraday-0.17.5 lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_http_ssl_patch.rb