Skip to content

Commit

Permalink
Ruby 2.0 compatibility (#50)
Browse files Browse the repository at this point in the history
* Update CI tested ruby versions

* Add support for latest OpenSSL version in ruby >=2.4 thanks to @kangguru 

* ruby 2.0 requires an older version of nokogiri

* closes #49 #47
  • Loading branch information
Lars committed Jun 16, 2017
1 parent bb76791 commit 8b6e9d3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
language: ruby
env:
- JAVA_OPTS=-Djava.security.egd=file:/dev/./urandom --server -Dcext.enabled=false -Xcompile.invokedynamic=false
rvm:
- 2.0.0
- 2.1.8
- 2.2.4
- jruby
- 2.1.10
- 2.2.7
- 2.3.4
- 2.4.1
- jruby-9.1.10.0
7 changes: 6 additions & 1 deletion epics.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ Gem::Specification.new do |spec|
spec.post_install_message += "Please create an issue on github (railslove/epics) if anything does not work as expected. And contact team@railslove.com if you are looking for support with your integration.\n"
spec.post_install_message += "\e[32m" + ("*" * 60) + "\n\e[0m"

spec.add_dependency "nokogiri"
if RUBY_VERSION < '2.1'
spec.add_dependency "nokogiri", '< 1.7.0'
else
spec.add_dependency "nokogiri"
end

spec.add_dependency "gyoku"
spec.add_dependency "faraday"
spec.add_dependency "rubyzip", ">= 1.0.0"
Expand Down
10 changes: 7 additions & 3 deletions lib/epics/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ def HPB
exponent = Base64.decode64(node.at_xpath(".//*[local-name() = 'Exponent']").content)

bank = OpenSSL::PKey::RSA.new
bank.n = OpenSSL::BN.new(modulus, 2)
bank.e = OpenSSL::BN.new(exponent, 2)
if bank.respond_to?(:set_key)
bank.set_key(OpenSSL::BN.new(modulus, 2), OpenSSL::BN.new(exponent, 2), nil)
else
bank.n = OpenSSL::BN.new(modulus, 2)
bank.e = OpenSSL::BN.new(exponent, 2)
end

self.keys["#{host_id.upcase}.#{type}"] = Epics::Key.new(bank)
end
Expand Down Expand Up @@ -225,7 +229,7 @@ def dump_keys
end

def cipher
@cipher ||= OpenSSL::Cipher::Cipher.new("aes-256-cbc")
@cipher ||= OpenSSL::Cipher.new("aes-256-cbc")
end

def encrypt(data)
Expand Down
2 changes: 1 addition & 1 deletion lib/epics/generic_upload_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(client, document)
end

def cipher
@cipher ||= OpenSSL::Cipher::Cipher.new("aes-128-cbc")
@cipher ||= OpenSSL::Cipher.new("aes-128-cbc")
end

def digester
Expand Down
2 changes: 1 addition & 1 deletion lib/epics/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def order_data
end

def cipher
cipher = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
cipher = OpenSSL::Cipher.new("aes-128-cbc")

cipher.decrypt
cipher.padding = 0
Expand Down
3 changes: 2 additions & 1 deletion spec/generic_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
end

describe '#signature_value' do
before { allow(OpenSSL::Random).to receive(:random_bytes).and_return(Base64.strict_decode64("7wtROfiX4tyN60cygJUSsHkhzxX1RVJa8vGNYnflvKc=")) }
before { allow(OpenSSL::Random).to receive(:random_bytes).with(16).and_return("\x01" * 16) } # fake random_key requires a 16byte lenght but is not used in this test
before { allow(OpenSSL::Random).to receive(:random_bytes).with(32).and_return(Base64.strict_decode64("7wtROfiX4tyN60cygJUSsHkhzxX1RVJa8vGNYnflvKc=")) } # digest requires 32 bytes

it 'will be the signed document' do
expect(subject.signature_value).to eq("BQBMyxGHYoAbbmbMJRFbGrvUNinY15+qeeRLF708VL+tuENnbJMO6xHLWxU1rksOnu4xDzxfua9b3IxIaxLyTTFDuVi6bbu3sBslhIt2frdigo0xBL14KUJQ/pYiMj+2pfNYhtVxzamrnvgPSLNAEn36JykK2d347chT87HlZ7CAGNBS7lJHAzRP1v7Hkc+kKttkkWCpOGk06R6FUCxxVKXmQketMEl/scsMyJ3JtBe/EcjEZdDe5WcqZYUu5ARrfEiAeyutVRZnu17c3nKwkmWl7UqFAwp16cS8IPNL4i5FGCytgKl/kyaoxaE/P1lrGOkHcCTsSR0bAbARhndfdQ==")
Expand Down

0 comments on commit 8b6e9d3

Please sign in to comment.