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

Convergent encryption support #1

Merged
merged 1 commit into from
Oct 9, 2018
Merged

Conversation

finalwharf
Copy link

@finalwharf finalwharf commented Oct 1, 2018

What does this PR do?

  • Adds support for convergent encryption

Where should the reviewer start?

  • lib/vault/rails.rb
  • lib/vault/encrypted_model.rb

Any background context you want to provide?

  • Vault supports convergent encryption since v0.6.1, but this gem
    does not take advantage of this functionality.

/cc @popovm @bliof please review

@finalwharf finalwharf force-pushed the master branch 2 times, most recently from b816bff to 54b6047 Compare October 4, 2018 07:58
@finalwharf finalwharf force-pushed the convergent_encryption branch 2 times, most recently from 544c52f to 28c3d67 Compare October 4, 2018 12:44
@finalwharf finalwharf requested a review from popovm October 4, 2018 12:46
expect(first_person.email_encrypted).to eq second_person.email_encrypted
end

it 'generates different ciphertexts different plaintexts' do
Copy link
Member

Choose a reason for hiding this comment

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

for different plaintexts 👴

@@ -27,6 +27,10 @@ module Rails
DEV_WARNING = "[vault-rails] Using in-memory cipher - this is not secure " \
"and should never be used in production-like environments!".freeze

CONVERGENT_ENCRYPTION_CONTEXT = Base64.strict_encode64(
ENV.fetch('VAULT_CONVERGENT_ENCRYPTION_CONTEXT', 'convergent-encryption-context')
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove the default value here

@finalwharf finalwharf force-pushed the convergent_encryption branch 2 times, most recently from fa1feee to 6b0e6bf Compare October 5, 2018 06:30
@finalwharf finalwharf requested a review from bliof October 5, 2018 06:57
@@ -30,7 +30,7 @@ module Rails
class << self
# API client object based off the configured options in {Configurable}.
#
# @return [Vault::Client]
# @return [Vault::Client] for use with convergent encryption
Copy link

@bliof bliof Oct 5, 2018

Choose a reason for hiding this comment

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

You can drop the addition, you can use it without the convergent encryption

Copy link
Author

@finalwharf finalwharf Oct 5, 2018

Choose a reason for hiding this comment

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

Accidental copy/paste 🤷🏻‍♂️

lib/vault/rails.rb Show resolved Hide resolved
@finalwharf
Copy link
Author

Some context: Vault::Rails has two protected methods - memory_encrypt and memory_decrypt, that is uses for encryption in development and testing environments instead of accessing Vault. The two methods are from the official repo, and use AES 128 CBC without an Initialization Vector.

Both using the same IV and no IV in the first place poses the same security issues. The reason for using the same IV is to make the gem behave the same both in development and production as the current PR adds support for convergent encryption for production as well.

The way that the VAULT_CONVERGENT_ENCRYPTION_CONTEXT is used is not the same in dev and prod. In development I use it as an IV (to keep things simple), but in prod, Vault uses it for key derivation.

Again, memory encryption is used only when Vault is not enabled (dev and test envs).

Copy link

@bliof bliof left a comment

Choose a reason for hiding this comment

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

You are missing specs that verify that vault_decrypt and vault_encrypt correctly pass the options to the client.

Otherwise LGTM

lib/vault/rails.rb Outdated Show resolved Hide resolved
@finalwharf finalwharf force-pushed the convergent_encryption branch from 069c75e to 22113ec Compare October 5, 2018 13:43
@subodhsawant subodhsawant self-requested a review October 8, 2018 09:06
@subodhsawant
Copy link

@finalwharf @bliof - RE: memory_encrypt / memory_decrypt / AES CBC 128 / static IV - this is fine from a security perspective as long as it is used for development and testing

@finalwharf finalwharf force-pushed the convergent_encryption branch 2 times, most recently from 1ebdde1 to 37516fa Compare October 8, 2018 11:59
spec/unit/rails_spec.rb Show resolved Hide resolved

describe '.vault_encrypt' do
it 'sends the correct paramaters to vault client' do

Copy link

Choose a reason for hiding this comment

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

✂️

with(expected_route, expected_options).
and_return(spy('Vault::Secret'))

Vault::Rails.send(:vault_encrypt, 'path', 'key', 'plaintext', Vault::Rails.client, true)
Copy link

Choose a reason for hiding this comment

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

Please use the public methods to test this

@finalwharf finalwharf force-pushed the convergent_encryption branch 2 times, most recently from e4f4df2 to 6ab4e33 Compare October 8, 2018 14:42
Copy link

@bliof bliof left a comment

Choose a reason for hiding this comment

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

LGTM 👍

end
end

describe '.decrypt' do
Copy link

Choose a reason for hiding this comment

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

tbo you can delete this and the one above

Copy link
Member

@popovm popovm left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@finalwharf finalwharf force-pushed the convergent_encryption branch 2 times, most recently from 14365fc to 8fc09aa Compare October 9, 2018 05:50
What does this PR do?
---------------------
* Adds support for convergent encryption

Where should the reviewer start?
--------------------------------
* `lib/vault/rails.rb`
* `lib/vault/encrypted_model.rb`

Any background context you want to provide?
-------------------------------------------
* Vault supports convergent encryption since v0.6.1, but this gem
does not take advantage of this functionality.
@finalwharf finalwharf force-pushed the convergent_encryption branch from 8fc09aa to f71550c Compare October 9, 2018 05:56
@finalwharf finalwharf merged commit fc715f2 into master Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants