summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-08-06 20:39:37 -0700
committerGitHub <noreply@github.com>2019-08-06 20:39:37 -0700
commit32a8c4ae7122d793adc4df308393fcb2cbc99cd0 (patch)
tree421e2e242290c407e2014e8ae03257fba559adc1 /lib
parenta338f147c50c1248a4aeee84cd093470e34d4171 (diff)
parentc3746ef86c6f0f94bd75ab83e34d1810ab9a0e59 (diff)
downloadmixlib-authentication-32a8c4ae7122d793adc4df308393fcb2cbc99cd0.tar.gz
Merge pull request #48 from chef/bk
Update project owner + Remove Travis CI
Diffstat (limited to 'lib')
-rw-r--r--lib/mixlib/authentication.rb2
-rw-r--r--lib/mixlib/authentication/http_authentication_request.rb2
-rw-r--r--lib/mixlib/authentication/signatureverification.rb2
-rw-r--r--lib/mixlib/authentication/signedheaderauth.rb54
-rw-r--r--lib/mixlib/authentication/version.rb2
5 files changed, 32 insertions, 30 deletions
diff --git a/lib/mixlib/authentication.rb b/lib/mixlib/authentication.rb
index 167ed22..b2019ee 100644
--- a/lib/mixlib/authentication.rb
+++ b/lib/mixlib/authentication.rb
@@ -18,7 +18,7 @@
module Mixlib
module Authentication
- DEFAULT_SERVER_API_VERSION = "0"
+ DEFAULT_SERVER_API_VERSION = "0".freeze
attr_accessor :logger
module_function :logger, :logger=
diff --git a/lib/mixlib/authentication/http_authentication_request.rb b/lib/mixlib/authentication/http_authentication_request.rb
index 967c0e3..16907d1 100644
--- a/lib/mixlib/authentication/http_authentication_request.rb
+++ b/lib/mixlib/authentication/http_authentication_request.rb
@@ -22,7 +22,7 @@ module Mixlib
module Authentication
class HTTPAuthenticationRequest
- MANDATORY_HEADERS = [:x_ops_sign, :x_ops_userid, :x_ops_timestamp, :host, :x_ops_content_hash]
+ MANDATORY_HEADERS = %i{x_ops_sign x_ops_userid x_ops_timestamp host x_ops_content_hash}.freeze
attr_reader :request
diff --git a/lib/mixlib/authentication/signatureverification.rb b/lib/mixlib/authentication/signatureverification.rb
index 1dfafd6..3231214 100644
--- a/lib/mixlib/authentication/signatureverification.rb
+++ b/lib/mixlib/authentication/signatureverification.rb
@@ -203,7 +203,7 @@ module Mixlib
# No file_param; we're running in Merb, or it's just not there..
if file_param.nil?
hash_param = request.params.values.find { |value| value.respond_to?(:has_key?) } # Hash responds to :has_key? .
- if !hash_param.nil?
+ unless hash_param.nil?
file_param = hash_param.values.find { |value| value.respond_to?(:read) } # File/Tempfile responds to :read.
end
end
diff --git a/lib/mixlib/authentication/signedheaderauth.rb b/lib/mixlib/authentication/signedheaderauth.rb
index 2a54c76..0ca74c4 100644
--- a/lib/mixlib/authentication/signedheaderauth.rb
+++ b/lib/mixlib/authentication/signedheaderauth.rb
@@ -34,7 +34,7 @@ module Mixlib
"1.0" => "sha1",
"1.1" => "sha1",
"1.3" => "sha256",
- }.freeze()
+ }.freeze
# Use of SUPPORTED_ALGORITHMS and SUPPORTED_VERSIONS is deprecated. Use
# ALGORITHM_FOR_VERSION instead
@@ -74,15 +74,14 @@ module Mixlib
# * `:host`: The host part of the URI
def self.signing_object(args = {})
SigningObject.new(args[:http_method],
- args[:path],
- args[:body],
- args[:host],
- args[:timestamp],
- args[:user_id],
- args[:file],
- args[:proto_version],
- args[:headers]
- )
+ args[:path],
+ args[:body],
+ args[:host],
+ args[:timestamp],
+ args[:user_id],
+ args[:file],
+ args[:proto_version],
+ args[:headers])
end
def algorithm
@@ -175,7 +174,7 @@ module Mixlib
# ====Parameters
#
def canonical_path
- p = path.gsub(/\/+/, "/")
+ p = path.gsub(%r{/+}, "/")
p.length > 1 ? p.chomp("/") : p
end
@@ -191,6 +190,7 @@ module Mixlib
else
@hashed_body_digest = digest
end
+
# Hash the file object if it was passed in, otherwise hash based on
# the body.
# TODO: tim 2009-12-28: It'd be nice to just remove this special case,
@@ -283,11 +283,13 @@ module Mixlib
do_sign_ssh_agent(rsa_key, string_to_sign)
else
raise AuthenticationError, "RSA private key is required to sign requests, but a public key was provided" unless rsa_key.private?
+
rsa_key.sign(digest.new, string_to_sign)
end
else
raise AuthenticationError, "Agent signing mode requires signing protocol version 1.3 or newer" if use_ssh_agent
raise AuthenticationError, "RSA private key is required to sign requests, but a public key was provided" unless rsa_key.private?
+
rsa_key.private_encrypt(string_to_sign)
end
end
@@ -339,25 +341,25 @@ module Mixlib
# generate a request signature. `SignedHeaderAuth.signing_object()`
# provides a more convenient interface to the constructor.
SigningObject = Struct.new(:http_method, :path, :body, :host,
- :timestamp, :user_id, :file, :proto_version,
- :headers) do
+ :timestamp, :user_id, :file, :proto_version,
+ :headers) do
- include SignedHeaderAuth
+ include SignedHeaderAuth
- def proto_version
- (self[:proto_version] || SignedHeaderAuth::DEFAULT_PROTO_VERSION).to_s
- end
+ def proto_version
+ (self[:proto_version] || SignedHeaderAuth::DEFAULT_PROTO_VERSION).to_s
+ end
- def server_api_version
- key = (self[:headers] || {}).keys.select do |k|
- k.casecmp("x-ops-server-api-version") == 0
- end.first
- if key
- self[:headers][key]
- else
- DEFAULT_SERVER_API_VERSION
+ def server_api_version
+ key = (self[:headers] || {}).keys.select do |k|
+ k.casecmp("x-ops-server-api-version") == 0
+ end.first
+ if key
+ self[:headers][key]
+ else
+ DEFAULT_SERVER_API_VERSION
+ end
end
end
- end
end
end
diff --git a/lib/mixlib/authentication/version.rb b/lib/mixlib/authentication/version.rb
index 99d74d0..cade16a 100644
--- a/lib/mixlib/authentication/version.rb
+++ b/lib/mixlib/authentication/version.rb
@@ -16,6 +16,6 @@
module Mixlib
module Authentication
- VERSION = "3.0.2"
+ VERSION = "3.0.2".freeze
end
end