Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AWS|Core] Fix signature v4 non canonicalising header case properly #4

Merged
merged 1 commit into from
Jan 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/fog/aws/signaturev4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ def canonical_query_string(query)
def canonical_headers(headers)
canonical_headers = ''

for key in headers.keys.sort_by {|k| k.to_s}
for key in headers.keys.sort_by {|k| k.to_s.downcase}
canonical_headers << "#{key.to_s.downcase}:#{headers[key].to_s.strip}\n"
end
canonical_headers
end

def signed_headers(headers)
headers.keys.map {|key| key.to_s}.sort.map {|key| key.downcase}.join(';')
headers.keys.map {|key| key.to_s.downcase}.sort.join(';')
end

end
Expand Down
6 changes: 6 additions & 0 deletions tests/signaturev4_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
end
end

tests('get-headers-mixed-case-headers') do
returns(@signer.sign({:headers => {'HOST' => 'host.foo.com', 'date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/'}, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=b27ccfbfa7df52a200ff74193ca6e32d4b48b8856fab7ebf1c595d0670a7e470'
end
end

tests('get-vanilla-query-order-key with symbol keys') do
returns(@signer.sign({:query => {:'a' => 'foo', :'b' => 'foo'}, :headers => {:'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '/'}, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=date;host, Signature=0dc122f3b28b831ab48ba65cb47300de53fbe91b577fe113edac383730254a3b'
Expand Down