diff --git a/Gemfile b/Gemfile index a9bbb5c56..edeb50958 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,6 @@ gem 'json', ">= 0" gem 'mime-types', ">= 0" gem 'net-ssh', ">= 0" gem 'nokogiri', ">= 0" -gem 'ruby-hmac', ">= 0" gem 'rspec', '>= 0' gem 'shindo', '>= 0.1.5' gem 'builder', '>= 0' diff --git a/Gemfile.lock b/Gemfile.lock index dd2cabec8..e9e28a9a8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,49 +1,4 @@ --- -dependencies: - formatador: - group: - - :default - version: ">= 0.0.10" - rake: - group: - - :default - version: ">= 0" - rspec: - group: - - :default - version: ">= 0" - mime-types: - group: - - :default - version: ">= 0" - ruby-hmac: - group: - - :default - version: ">= 0" - json: - group: - - :default - version: ">= 0" - net-ssh: - group: - - :default - version: ">= 0" - excon: - group: - - :default - version: ">= 0.0.26" - builder: - group: - - :default - version: ">= 0" - shindo: - group: - - :default - version: ">= 0.1.5" - nokogiri: - group: - - :default - version: ">= 0" specs: - rake: version: 0.8.7 @@ -65,11 +20,50 @@ specs: version: 1.4.2 - rspec: version: 1.3.0 -- ruby-hmac: - version: 0.4.0 - shindo: version: 0.1.5 -hash: f165ab405ad34fe69f19febaa994c2509087a809 +hash: 58a08d793d993ef27b7140767d8a94aa21a49a13 sources: - Rubygems: uri: http://gemcutter.org +dependencies: + formatador: + version: ">= 0.0.10" + group: + - :default + nokogiri: + version: ">= 0" + group: + - :default + rspec: + version: ">= 0" + group: + - :default + rake: + version: ">= 0" + group: + - :default + mime-types: + version: ">= 0" + group: + - :default + net-ssh: + version: ">= 0" + group: + - :default + json: + version: ">= 0" + group: + - :default + excon: + version: ">= 0.0.26" + group: + - :default + builder: + version: ">= 0" + group: + - :default + shindo: + version: ">= 0.1.5" + group: + - :default diff --git a/fog.gemspec b/fog.gemspec index 2aa2c0f3b..df5061a6b 100644 --- a/fog.gemspec +++ b/fog.gemspec @@ -48,7 +48,6 @@ Gem::Specification.new do |s| s.add_dependency('mime-types') s.add_dependency('net-ssh') s.add_dependency('nokogiri') - s.add_dependency('ruby-hmac') ## List your development dependencies here. Development dependencies are ## those that are only needed during development diff --git a/lib/fog.rb b/lib/fog.rb index 58ffa71bd..90ad81c53 100644 --- a/lib/fog.rb +++ b/lib/fog.rb @@ -4,7 +4,6 @@ require 'cgi' require 'digest/md5' require 'excon' require 'formatador' -require 'hmac-sha2' require 'json' require 'mime/types' require 'net/ssh' @@ -22,6 +21,7 @@ require 'fog/collection' require 'fog/connection' require 'fog/deprecation' require 'fog/errors' +require 'fog/hmac' require 'fog/model' require 'fog/parser' require 'fog/service' diff --git a/lib/fog/aws.rb b/lib/fog/aws.rb index ed7db9cdb..03bc00dc4 100644 --- a/lib/fog/aws.rb +++ b/lib/fog/aws.rb @@ -33,8 +33,8 @@ module Fog end end string_to_sign = "POST\n#{options[:host]}\n/\n" << body.chop - hmac = options[:hmac].update(string_to_sign) - body << "Signature=#{CGI.escape(Base64.encode64(hmac.digest).chomp!).gsub(/\+/, '%20')}" + signed_string = options[:hmac].sign(string_to_sign) + body << "Signature=#{CGI.escape(Base64.encode64(signed_string).chomp!).gsub(/\+/, '%20')}" body end diff --git a/lib/fog/aws/ec2.rb b/lib/fog/aws/ec2.rb index dec6ff342..03fe02e9f 100644 --- a/lib/fog/aws/ec2.rb +++ b/lib/fog/aws/ec2.rb @@ -145,7 +145,7 @@ module Fog def initialize(options={}) @aws_access_key_id = options[:aws_access_key_id] @aws_secret_access_key = options[:aws_secret_access_key] - @hmac = HMAC::SHA256.new(@aws_secret_access_key) + @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key) @host = options[:host] || case options[:region] when 'ap-southeast-1' 'ec2.ap-southeast-1.amazonaws.com' @@ -158,8 +158,8 @@ module Fog else 'ec2.amazonaws.com' end - @port = options[:port] || 443 - @scheme = options[:scheme] || 'https' + @port = options[:port] || 443 + @scheme = options[:scheme] || 'https' end private diff --git a/lib/fog/aws/elb.rb b/lib/fog/aws/elb.rb index 92731971e..d48d178e7 100644 --- a/lib/fog/aws/elb.rb +++ b/lib/fog/aws/elb.rb @@ -48,7 +48,7 @@ module Fog def initialize(options={}) @aws_access_key_id = options[:aws_access_key_id] @aws_secret_access_key = options[:aws_secret_access_key] - @hmac = HMAC::SHA256.new(@aws_secret_access_key) + @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key) @host = options[:host] || case options[:region] when 'ap-southeast-1' 'elasticloadbalancing.ap-southeast-1.amazonaws.com' diff --git a/lib/fog/aws/s3.rb b/lib/fog/aws/s3.rb index 2015a229e..18ad38cde 100644 --- a/lib/fog/aws/s3.rb +++ b/lib/fog/aws/s3.rb @@ -124,8 +124,8 @@ module Fog def initialize(options={}) @aws_access_key_id = options[:aws_access_key_id] @aws_secret_access_key = options[:aws_secret_access_key] - @digest = OpenSSL::Digest::Digest.new('sha1') - @host = options[:host] || case options[:region] + @hmac = Fog::HMAC.new('sha1', @aws_secret_access_key) + @host = options[:host] || case options[:region] when 'ap-southeast-1' 's3-ap-southeast-1.amazonaws.com' when 'us-west-1' @@ -133,8 +133,8 @@ module Fog else 's3.amazonaws.com' end - @port = options[:port] || 443 - @scheme = options[:scheme] || 'https' + @port = options[:port] || 443 + @scheme = options[:scheme] || 'https' reload end @@ -200,7 +200,7 @@ DATA canonical_resource.chop! string_to_sign << "#{canonical_resource}" - signed_string = OpenSSL::HMAC.digest(@digest, @aws_secret_access_key, string_to_sign) + signed_string = @hmac.sign(string_to_sign) signature = Base64.encode64(signed_string).chomp! end end diff --git a/lib/fog/aws/simpledb.rb b/lib/fog/aws/simpledb.rb index e65ff8408..92ed83f0e 100644 --- a/lib/fog/aws/simpledb.rb +++ b/lib/fog/aws/simpledb.rb @@ -63,7 +63,7 @@ module Fog def initialize(options={}) @aws_access_key_id = options[:aws_access_key_id] @aws_secret_access_key = options[:aws_secret_access_key] - @hmac = HMAC::SHA256.new(@aws_secret_access_key) + @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key) @host = options[:host] || 'sdb.amazonaws.com' @nil_string = options[:nil_string]|| 'nil' @port = options[:port] || 443 diff --git a/lib/fog/hmac.rb b/lib/fog/hmac.rb new file mode 100644 index 000000000..58d7bbc47 --- /dev/null +++ b/lib/fog/hmac.rb @@ -0,0 +1,19 @@ +module Fog + class HMAC + + def initialize(type, key) + @digest = case type + when 'sha1' + OpenSSL::Digest::Digest.new('sha1') + when 'sha256' + OpenSSL::Digest::Digest.new('sha256') + end + @key = key + end + + def sign(data) + OpenSSL::HMAC.digest(@digest, @key, data) + end + + end +end \ No newline at end of file