Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Use OpenSSL::HMAC in preference to Digest::HMAC #88

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ script: rake
rvm:
- 1.9.3
- 2.0.0
- 2.1
- 2.2
- jruby-19mode
8 changes: 6 additions & 2 deletions lib/openid/cryptutil.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def CryptUtil.sha1(text)
end

def CryptUtil.hmac_sha1(key, text)
if Digest.const_defined? :HMAC, false
if defined?(OpenSSL) && OpenSSL.const_defined?(:HMAC) && OpenSSL::HMAC.respond_to?(:digest)
OpenSSL::HMAC.digest("sha1", key, text)
elsif Digest.const_defined? :HMAC, false
Digest::HMAC.new(key,Digest::SHA1).update(text).digest
else
return HMAC::SHA1.digest(key, text)
Expand All @@ -49,7 +51,9 @@ def CryptUtil.sha256(text)
end

def CryptUtil.hmac_sha256(key, text)
if Digest.const_defined? :HMAC, false
if defined?(OpenSSL) && OpenSSL.const_defined?(:HMAC) && OpenSSL::HMAC.respond_to?(:digest)
OpenSSL::HMAC.digest("sha256", key, text)
elsif Digest.const_defined? :HMAC, false
Digest::HMAC.new(key,Digest::SHA256).update(text).digest
else
return HMAC::SHA256.digest(key, text)
Expand Down
4 changes: 2 additions & 2 deletions lib/openid/trustroot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def TrustRoot._parse_url(url)
begin
url = URINorm.urinorm(url)
rescue URI::InvalidURIError
nil
return nil
end

begin
Expand Down Expand Up @@ -210,7 +210,7 @@ def TrustRoot.parse(trust_root)
return nil if parts.nil?

proto, host, port, path = parts
return nil if host[0] == '.'
return nil if host[0] == '.' || host.include?('*')

# check for URI fragment
if path and !path.index('#').nil?
Expand Down
2 changes: 1 addition & 1 deletion test/test_trustroot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _test_sanity(case_, sanity, desc)
assert tr.sane?, [case_, desc].join(' ')
assert OpenID::TrustRoot::TrustRoot.check_sanity(case_), [case_, desc].join(' ')
elsif sanity == 'insane'
assert !tr.sane?, [case_, desc].join(' ')
assert tr.nil? || !tr.sane?, [case_, desc].join(' ')
assert !OpenID::TrustRoot::TrustRoot.check_sanity(case_), [case_, desc].join(' ')
else
assert tr.nil?, case_
Expand Down