module AWS::Core::Signature::Version3

Public Instance Methods

add_authorization!(signer) click to toggle source
# File lib/aws/core/signature/version_3.rb, line 22
def add_authorization!(signer)

  self.access_key_id = signer.access_key_id

  headers["x-amz-date"] ||= (headers["date"] ||= Time.now.rfc822)
  headers["host"] ||= host

  headers["x-amz-security-token"] = signer.session_token if 
    signer.respond_to?(:session_token) and signer.session_token

  # compute the authorization
  request_hash = OpenSSL::Digest::SHA256.digest(string_to_sign)
  signature = signer.sign(request_hash)
  headers["x-amzn-authorization"] =
    "AWS3 "+
    "AWSAccessKeyId=#{signer.access_key_id},"+
    "Algorithm=HmacSHA256,"+
    "SignedHeaders=#{headers_to_sign.join(';')},"+
    "Signature=#{signature}"
end

Protected Instance Methods

canonical_headers() click to toggle source
# File lib/aws/core/signature/version_3.rb, line 55
def canonical_headers
  headers_to_sign.map do |name|
    value = headers[name]
    "#{name.downcase.strip}:#{value.strip}\n"
  end.sort.join
end
headers_to_sign() click to toggle source
# File lib/aws/core/signature/version_3.rb, line 62
def headers_to_sign
  headers.keys.select do |header|
      header == "host" ||
      header == "content-encoding" ||
      header =~ %r^x-amz/
  end
end
string_to_sign() click to toggle source
# File lib/aws/core/signature/version_3.rb, line 45
def string_to_sign
  [
    http_method,
    "/",
    "",
    canonical_headers,
    body
  ].join("\n")
end