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 Ruby 2.4.x - key must be 32 bytes #115

Closed
scottwater opened this issue Apr 24, 2017 · 1 comment
Closed

Support for Ruby 2.4.x - key must be 32 bytes #115

scottwater opened this issue Apr 24, 2017 · 1 comment

Comments

@scottwater
Copy link

Trying to generate a scoped key on Ruby 2.4.1 both with gem versions 0.9.3 and 0.9.7:

keen (0.9.7) lib/keen/aes_helper_old.rb:27:in key=' keen (0.9.7) lib/keen/aes_helper_old.rb:27:in aes256_encrypt'
keen (0.9.7) lib/keen/scoped_key.rb:33:in `encrypt!'

Here is code you can use to generate the exception:

master_key = ENV['KEEN_MASTER_KEY']
filters = {user_id: 1}
keen_filters = filters.map {|k,v| {property_name: k, operator: 'eq', property_value: v}}
Keen::ScopedKey.new(master_key, { filters: keen_filters, allowed_operations: [ "read" ]}).encrypt!

Also, my master key is exactly 32 characters long. If I were to use it to something like 'x' it no longer throws the exception.

@scottwater
Copy link
Author

Digging through the code, it looks like if the key is 32 characters long, it shouldn't be padded.

This works for me: https://gist.github.com/scottwater/ebe6fd1df2955cae336cc957ff28ca20

It sounds like previous versions of Ruby's SSL support truncated keys greater than 32 characters. So the extra padding applied in AESHelperOld was simply stripped out. (see: attr-encrypted/encryptor#26)

The monkey patch above works locally for me in both Ruby 2.3.3 and Ruby 2.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants