Module: SimpleAWS::Signing::Version3

Included in:
SimpleAWS::SES
Defined in:
lib/simple_aws/signing/version3.rb

Overview

Implementation of "Signature Version 3" signing, the X-Amzn-Authorization header

Instance Method Summary collapse

Instance Method Details

#build_signature_for(timestamp) ⇒ Object


32
33
34
# File 'lib/simple_aws/signing/version3.rb', line 32

def build_signature_for(timestamp)
  OpenSSL::HMAC.digest("sha256", self.secret_key, timestamp.httpdate)
end

#finish_and_sign_request(request) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/simple_aws/signing/version3.rb', line 14

def finish_and_sign_request(request)
  timestamp = Time.now.utc
  request.params.merge!({
    "AWSAccessKeyId" => self.access_key,
    "Timestamp" => timestamp.strftime("%Y-%m-%dT%H:%M:%SZ"),
    "Version" => self.version
  })

  request.headers["Date"] = timestamp.httpdate

  request.headers["X-Amzn-Authorization"] =
    "AWS3-HTTPS AWSAccessKeyId=#{self.access_key}, " +
    "Algorithm=HmacSHA256, " +
    "Signature=#{Base64.encode64(build_signature_for(timestamp)).chomp}"

  request
end