use openssl instead of ruby-hmac

This commit is contained in:
geemus 2010-06-15 21:04:16 -07:00
Родитель 0651d89271
Коммит 3d8d40f2d6
10 изменённых файлов: 74 добавлений и 63 удалений

Просмотреть файл

@ -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'

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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'

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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'

Просмотреть файл

@ -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

Просмотреть файл

@ -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

19
lib/fog/hmac.rb Normal file
Просмотреть файл

@ -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