Sha256: 34c344c8769595649c40675ef7520c193f6637189061a1f53169dd1fc1ca8340

Contents?: true

Size: 784 Bytes

Versions: 43

Compression:

Stored size: 784 Bytes

Contents

class DiscoApp::ProxyService

  # Return true iff the signature provided in the given query string matches
  # that calculated from the remaining query parameters and the given secret.
  def self.proxy_signature_is_valid?(query_string, secret)
    query_hash = Rack::Utils.parse_query(query_string)
    signature = query_hash.delete('signature').to_s
    ActiveSupport::SecurityUtils.variable_size_secure_compare(self.calculated_signature(query_hash, secret), signature)
  end

  # Return the calculated signature for the given query hash and secret.
  def self.calculated_signature(query_hash, secret)
    sorted_params = query_hash.collect{ |k, v| "#{k}=#{Array(v).join(',')}" }.sort.join
    OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), secret, sorted_params)
  end

end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
disco_app-0.8.4 app/services/disco_app/proxy_service.rb
disco_app-0.8.5 app/services/disco_app/proxy_service.rb
disco_app-0.8.6 app/services/disco_app/proxy_service.rb
disco_app-0.8.7 app/services/disco_app/proxy_service.rb
disco_app-0.8.8 app/services/disco_app/proxy_service.rb
disco_app-0.8.9 app/services/disco_app/proxy_service.rb
disco_app-0.9.0 app/services/disco_app/proxy_service.rb
disco_app-0.9.1 app/services/disco_app/proxy_service.rb
disco_app-0.9.2 app/services/disco_app/proxy_service.rb
disco_app-0.9.3 app/services/disco_app/proxy_service.rb
disco_app-0.9.4 app/services/disco_app/proxy_service.rb
disco_app-0.9.5 app/services/disco_app/proxy_service.rb
disco_app-0.9.6 app/services/disco_app/proxy_service.rb
disco_app-0.9.7 app/services/disco_app/proxy_service.rb
disco_app-0.9.8 app/services/disco_app/proxy_service.rb
disco_app-0.9.9 app/services/disco_app/proxy_service.rb
disco_app-0.9.10 app/services/disco_app/proxy_service.rb
disco_app-0.9.11 app/services/disco_app/proxy_service.rb
disco_app-0.10.0 app/services/disco_app/proxy_service.rb
disco_app-0.10.1 app/services/disco_app/proxy_service.rb