Class: Fog::InternetArchive::SignatureV4

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/internet_archive/signaturev4.rb

Instance Method Summary collapse

Constructor Details

#initialize(ia_access_key_id, secret_key, region, service) ⇒ SignatureV4

Returns a new instance of SignatureV4.



6
7
8
9
10
11
# File 'lib/fog/internet_archive/signaturev4.rb', line 6

def initialize(ia_access_key_id, secret_key, region,service)
  @region = region
  @service = service
  @ia_access_key_id  = ia_access_key_id
  @hmac = Fog::HMAC.new('sha256', 'AWS4' + secret_key)
end

Instance Method Details

#sign(params, date) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/internet_archive/signaturev4.rb', line 13

def sign(params, date)
  canonical_request = <<-DATA
#{params[:method].to_s.upcase}
#{params[:path]}
#{canonical_query_string(params[:query])}
#{canonical_headers(params[:headers])}
#{signed_headers(params[:headers])}
#{Digest::SHA256.hexdigest(params[:body] || '')}
DATA
  canonical_request.chop!
  credential_scope = "#{date.utc.strftime('%Y%m%d')}/#{@region}/#{@service}/aws4_request"
  string_to_sign = <<-DATA
AWS4-HMAC-SHA256
#{date.to_iso8601_basic}
#{credential_scope}
#{Digest::SHA256.hexdigest(canonical_request)}
DATA

  string_to_sign.chop!

  signature = derived_hmac(date).sign(string_to_sign)

  "AWS4-HMAC-SHA256 Credential=#{@ia_access_key_id}/#{credential_scope}, SignedHeaders=#{signed_headers(params[:headers])}, Signature=#{signature.unpack('H*').first}"
end