summaryrefslogtreecommitdiff
path: root/lib/mixlib/authentication/signatureverification.rb
diff options
context:
space:
mode:
authorRyan Cragun <me@ryan.ec>2017-04-18 16:46:16 -0700
committerRyan Cragun <me@ryan.ec>2017-04-19 13:26:37 -0700
commit88ff22da3888462e23be414de46ec1a7426e69b8 (patch)
tree0b853d7616ee871deae12fc4d7db9cf967012a01 /lib/mixlib/authentication/signatureverification.rb
parent0c5c683a23b7d4b6fd2cbb61a2010af2e513aacf (diff)
downloadmixlib-authentication-ryan/cloud-319.tar.gz
[CLOUD-319] Make mixlib-log an optional dependencyryan/cloud-319
This change makes mixlib-log an optional dependency. When it's available in the LOAD_PATH it will be used by default, otherwise, all logging will will be forwarded to a null logger that does nothing. This is useful for cases where small utilities can consume mixlib-authentication and not have to pull in additional gems. Signed-off-by: Ryan Cragun <me@ryan.ec>
Diffstat (limited to 'lib/mixlib/authentication/signatureverification.rb')
-rw-r--r--lib/mixlib/authentication/signatureverification.rb24
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/mixlib/authentication/signatureverification.rb b/lib/mixlib/authentication/signatureverification.rb
index 842fc1f..898e05b 100644
--- a/lib/mixlib/authentication/signatureverification.rb
+++ b/lib/mixlib/authentication/signatureverification.rb
@@ -76,7 +76,7 @@ module Mixlib
# X-Ops-Content-Hash:
# X-Ops-Authorization-#{line_number}
def authenticate_request(user_secret, time_skew = (15 * 60))
- Mixlib::Authentication::Log.debug "Initializing header auth : #{request.inspect}"
+ Mixlib::Authentication.logger.debug "Initializing header auth : #{request.inspect}"
@user_secret = user_secret
@allowed_time_skew = time_skew # in seconds
@@ -150,14 +150,14 @@ module Mixlib
end
# Keep the debug messages lined up so it's easy to scan them
- Mixlib::Authentication::Log.debug("Verifying request signature:")
- Mixlib::Authentication::Log.debug(" Expected Block is: '#{candidate_block}'")
- Mixlib::Authentication::Log.debug("Decrypted block is: '#{request_decrypted_block}'")
- Mixlib::Authentication::Log.debug("Signatures match? : '#{@valid_signature}'")
+ Mixlib::Authentication.logger.debug("Verifying request signature:")
+ Mixlib::Authentication.logger.debug(" Expected Block is: '#{candidate_block}'")
+ Mixlib::Authentication.logger.debug("Decrypted block is: '#{request_decrypted_block}'")
+ Mixlib::Authentication.logger.debug("Signatures match? : '#{@valid_signature}'")
@valid_signature
rescue => e
- Mixlib::Authentication::Log.debug("Failed to verify request signature: #{e.class.name}: #{e.message}")
+ Mixlib::Authentication.logger.debug("Failed to verify request signature: #{e.class.name}: #{e.message}")
@valid_signature = false
end
@@ -169,9 +169,9 @@ module Mixlib
@valid_content_hash = (content_hash == hashed_body)
# Keep the debug messages lined up so it's easy to scan them
- Mixlib::Authentication::Log.debug("Expected content hash is: '#{hashed_body}'")
- Mixlib::Authentication::Log.debug(" Request Content Hash is: '#{content_hash}'")
- Mixlib::Authentication::Log.debug(" Hashes match?: #{@valid_content_hash}")
+ Mixlib::Authentication.logger.debug("Expected content hash is: '#{hashed_body}'")
+ Mixlib::Authentication.logger.debug(" Request Content Hash is: '#{content_hash}'")
+ Mixlib::Authentication.logger.debug(" Hashes match?: #{@valid_content_hash}")
@valid_content_hash
end
@@ -211,11 +211,11 @@ module Mixlib
# Any file that's included in the request is hashed if it's there. Otherwise,
# we hash the body.
if file_param
- Mixlib::Authentication::Log.debug "Digesting file_param: '#{file_param.inspect}'"
+ Mixlib::Authentication.logger.debug "Digesting file_param: '#{file_param.inspect}'"
@hashed_body = digester.hash_file(file_param, digest)
else
body = request.raw_post
- Mixlib::Authentication::Log.debug "Digesting body: '#{body}'"
+ Mixlib::Authentication.logger.debug "Digesting body: '#{body}'"
@hashed_body = digester.hash_string(body, digest)
end
end
@@ -232,7 +232,7 @@ module Mixlib
def timestamp_within_bounds?(time1, time2)
time_diff = (time2 - time1).abs
is_allowed = (time_diff < @allowed_time_skew)
- Mixlib::Authentication::Log.debug "Request time difference: #{time_diff}, within #{@allowed_time_skew} seconds? : #{!!is_allowed}"
+ Mixlib::Authentication.logger.debug "Request time difference: #{time_diff}, within #{@allowed_time_skew} seconds? : #{!!is_allowed}"
is_allowed
end
end