diff options
author | Christopher Brown <cb@opscode.com> | 2009-11-04 11:06:03 -0800 |
---|---|---|
committer | Christopher Brown <cb@opscode.com> | 2009-11-04 11:06:03 -0800 |
commit | 5de2fd9a6410eec7fb353d56d960a63bdeb9d8f7 (patch) | |
tree | 850f964c86b15807b3f7ec90177843941a26fc6b /lib/mixlib/authentication/signedheaderauth.rb | |
parent | b5074922bfc716b681abb7d0bd122eea8190d005 (diff) | |
parent | c38ca86e2e79737f5bb7c67b83f15a2dec61a2ea (diff) | |
download | mixlib-authentication-5de2fd9a6410eec7fb353d56d960a63bdeb9d8f7.tar.gz |
Merge branch 'PL-316'
Diffstat (limited to 'lib/mixlib/authentication/signedheaderauth.rb')
-rw-r--r-- | lib/mixlib/authentication/signedheaderauth.rb | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/mixlib/authentication/signedheaderauth.rb b/lib/mixlib/authentication/signedheaderauth.rb index 87c596a..4d72a4a 100644 --- a/lib/mixlib/authentication/signedheaderauth.rb +++ b/lib/mixlib/authentication/signedheaderauth.rb @@ -39,11 +39,11 @@ module Mixlib end end - # Build the canonicalized request based on the method, other headers, etc. + # Build the canonicalized request based on the method, other headers, etc. # compute the signature from the request, using the looked-up user secret # ====Parameters - # private_key<String>:: user's RSA private key. - def sign(private_key) + # private_key<OpenSSL::PKey::RSA>:: user's RSA private key. + def sign(private_key) digester = Mixlib::Authentication::Digester.new @hashed_body = if self.file digester.hash_file(self.file) @@ -51,18 +51,26 @@ module Mixlib digester.hash_body(self.body) end - signature = Base64.encode64(private_key.private_encrypt(canonicalize_request)).chomp.gsub!(/\n/,"\n\t") - header_hash = { + header_hash = { "X-Ops-Sign" => SIGNING_DESCRIPTION, "X-Ops-Userid" => user_id, "X-Ops-Timestamp" => canonical_time, "X-Ops-Content-Hash" =>@hashed_body, - "Authorization" => signature, } + + # Our multiline hash for authorization will be encoded in multiple header + # lines - X-Ops-Authorization-1, ... (starts at 1, not 0!) + signature = Base64.encode64(private_key.private_encrypt(canonicalize_request)).chomp + signature_lines = signature.split(/\n/) + signature_lines.each_index do |idx| + key = "X-Ops-Authorization-#{idx + 1}" + header_hash[key] = signature_lines[idx] + end + Mixlib::Authentication::Log.debug "Header hash: #{header_hash.inspect}" header_hash - end + end # Build the canonicalized time based on utc & iso8601 # |