Method: RightAws::AwsUtils.sign_request_v2

Defined in:
lib/awsbase/right_awsbase.rb

.sign_request_v2(aws_secret_access_key, service_hash, http_verb, host, uri) ⇒ Object

Signature Version 2 EC2, SQS and SDB requests must be signed by this guy. See: docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/index.html?REST_RESTAuth.html

http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1928


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/awsbase/right_awsbase.rb', line 77

def self.sign_request_v2(aws_secret_access_key, service_hash, http_verb, host, uri)
  fix_service_params(service_hash, '2')
  # select a signing method (make an old openssl working with sha1)
  # make 'HmacSHA256' to be a default one
  service_hash['SignatureMethod'] = 'HmacSHA256' unless ['HmacSHA256', 'HmacSHA1'].include?(service_hash['SignatureMethod'])
  service_hash['SignatureMethod'] = 'HmacSHA1'   unless @@digest256
  # select a digest
  digest = (service_hash['SignatureMethod'] == 'HmacSHA256' ? @@digest256 : @@digest1)
  # form string to sign
  canonical_string = service_hash.keys.sort.map do |key|
    "#{amz_escape(key)}=#{amz_escape(service_hash[key])}"
  end.join('&')
  string_to_sign = "#{http_verb.to_s.upcase}\n#{host.downcase}\n#{uri}\n#{canonical_string}"
  # sign the string
  signature      = amz_escape(Base64.encode64(OpenSSL::HMAC.digest(digest, aws_secret_access_key, string_to_sign)).strip)
  "#{canonical_string}&Signature=#{signature}"
end