Class: Fog::AWS::SignatureV4
- Inherits:
-
Object
- Object
- Fog::AWS::SignatureV4
- Defined in:
- lib/fog/aws/signaturev4.rb
Instance Method Summary collapse
-
#initialize(aws_access_key_id, secret_key, region, service) ⇒ SignatureV4
constructor
A new instance of SignatureV4.
- #sign(params, date) ⇒ Object
Constructor Details
#initialize(aws_access_key_id, secret_key, region, service) ⇒ SignatureV4
Returns a new instance of SignatureV4.
7 8 9 10 11 12 |
# File 'lib/fog/aws/signaturev4.rb', line 7 def initialize(aws_access_key_id, secret_key, region,service) @region = region @service = service @aws_access_key_id = aws_access_key_id @hmac = Fog::HMAC.new('sha256', 'AWS4' + secret_key) end |
Instance Method Details
#sign(params, date) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/aws/signaturev4.rb', line 14 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=#{@aws_access_key_id}/#{credential_scope}, SignedHeaders=#{signed_headers(params[:headers])}, Signature=#{signature.unpack('H*').first}" end |