summaryrefslogtreecommitdiff
path: root/lib/mixlib/authentication
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mixlib/authentication')
-rw-r--r--lib/mixlib/authentication/digester.rb5
-rw-r--r--lib/mixlib/authentication/signatureverification.rb4
-rw-r--r--lib/mixlib/authentication/signedheaderauth.rb8
3 files changed, 9 insertions, 8 deletions
diff --git a/lib/mixlib/authentication/digester.rb b/lib/mixlib/authentication/digester.rb
index 071e5a7..c456824 100644
--- a/lib/mixlib/authentication/digester.rb
+++ b/lib/mixlib/authentication/digester.rb
@@ -17,13 +17,14 @@
#
require 'mixlib/authentication'
+require 'openssl'
module Mixlib
module Authentication
class Digester
class << self
- def hash_file(digest, f)
+ def hash_file(f, digest=OpenSSL::Digest::SHA1)
digester = digest.new
buf = ""
while f.read(16384, buf)
@@ -36,7 +37,7 @@ module Mixlib
#
# ====Parameters
#
- def hash_string(digest, str)
+ def hash_string(str, digest=OpenSSL::Digest::SHA1)
::Base64.encode64(digest.digest(str)).chomp
end
diff --git a/lib/mixlib/authentication/signatureverification.rb b/lib/mixlib/authentication/signatureverification.rb
index 3c35c28..20b18a5 100644
--- a/lib/mixlib/authentication/signatureverification.rb
+++ b/lib/mixlib/authentication/signatureverification.rb
@@ -214,11 +214,11 @@ module Mixlib
# we hash the body.
if file_param
Mixlib::Authentication::Log.debug "Digesting file_param: '#{file_param.inspect}'"
- @hashed_body = digester.hash_file(digest, file_param)
+ @hashed_body = digester.hash_file(file_param, digest)
else
body = request.raw_post
Mixlib::Authentication::Log.debug "Digesting body: '#{body}'"
- @hashed_body = digester.hash_string(digest, body)
+ @hashed_body = digester.hash_string(body, digest)
end
end
@hashed_body
diff --git a/lib/mixlib/authentication/signedheaderauth.rb b/lib/mixlib/authentication/signedheaderauth.rb
index 0b5f923..09a22ee 100644
--- a/lib/mixlib/authentication/signedheaderauth.rb
+++ b/lib/mixlib/authentication/signedheaderauth.rb
@@ -177,9 +177,9 @@ module Mixlib
# always sign the entire request body, using the expanded multipart
# body in the case of a file being include.
@hashed_body ||= if self.file && self.file.respond_to?(:read)
- digester.hash_file(digest, self.file)
+ digester.hash_file(self.file, digest)
else
- digester.hash_string(digest, self.body)
+ digester.hash_string(self.body, digest)
end
end
@@ -206,7 +206,7 @@ module Mixlib
else
[
"Method:#{http_method.to_s.upcase}",
- "Hashed Path:#{digester.hash_string(digest, canonical_path)}",
+ "Hashed Path:#{digester.hash_string(canonical_path, digest)}",
"X-Ops-Content-Hash:#{hashed_body(digest)}",
"X-Ops-Timestamp:#{canonical_time}",
"X-Ops-UserId:#{canonical_x_ops_user_id}"
@@ -218,7 +218,7 @@ module Mixlib
case proto_version
when "1.1"
# and 1.2 if that ever gets implemented
- digester.hash_string(digest, user_id)
+ digester.hash_string(user_id, digest)
else
# versions 1.0 and 1.3
user_id