Skip to content

Commit

Permalink
Add support for latest OpenSSL version in ruby >=2.4
Browse files Browse the repository at this point in the history
thanks to @kangguru

closes #17
  • Loading branch information
bumi committed Jun 16, 2017
1 parent 02434f5 commit 613ddc7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
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

1 comment on commit 613ddc7

@bumi
Copy link
Collaborator Author

@bumi bumi commented on 613ddc7 Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually closes #47 not 17 ....

Please sign in to comment.