Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for new openssl #49

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
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: ruby
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
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