Sha256: c5223b324a65c0c03d606d74c4e11a899e4b4e4941797e57b9cc6f0184f1d2ff

Contents?: true

Size: 1.38 KB

Versions: 62

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require 'openssl'
require 'em-http'

# EventMachine patch to make SSL work.
module EmHttpSslPatch
  def ssl_verify_peer(cert_string)
    begin
      @last_seen_cert = OpenSSL::X509::Certificate.new(cert_string)
    rescue OpenSSL::X509::CertificateError
      return false
    end

    unless certificate_store.verify(@last_seen_cert)
      raise OpenSSL::SSL::SSLError,
            %(unable to verify the server certificate for "#{host}")
    end

    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
  end

  def ssl_handshake_completed
    return true unless verify_peer?

    unless verified_cert_identity?
      raise OpenSSL::SSL::SSLError,
            %(host "#{host}" does not match the server certificate)
    end

    true
  end

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

  def verified_cert_identity?
    OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
  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.include(EmHttpSslPatch)

Version data entries

62 entries across 50 versions & 16 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/faraday-1.2.0/lib/faraday/adapter/em_http_ssl_patch.rb
avalara_sdk-24.2.29 vendor/bundle/ruby/2.7.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
faraday-em_http-2.0.0 lib/faraday/adapter/em_http_ssl_patch.rb
alloy_sdk-0.1.0 vendor/bundle/ruby/3.0.0/gems/faraday-1.0.1/lib/faraday/adapter/em_http_ssl_patch.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
mx-platform-ruby-0.4.0 vendor/bundle/ruby/2.6.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
mx-platform-ruby-0.3.2 vendor/bundle/ruby/2.6.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
mx-platform-ruby-0.3.1 vendor/bundle/ruby/2.6.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb
passbase-1.3.0 vendor/bundle/ruby/2.7.0/gems/faraday-em_http-1.0.0/lib/faraday/adapter/em_http_ssl_patch.rb