-
Notifications
You must be signed in to change notification settings - Fork 69
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
Lockbox::DecryptionError even when the old key is provided in previous_versions #35
Comments
Hey @eddierubeiz, |
Thanks a lot for your prompt reply! I'll figure it out. In the meantime, it does look like I'm passing
gives me |
I was able to rotate the key using the clue @ankane provided. Thanks! I'm attaching the recipe that worked for me, in case anyone has this problem later on: Your
|
Hey @eddierubeiz, big thanks for sharing! It looks like Your instructions are great! Have been meaning to add better docs for this in the readme. Will do this later today. With the new option, users should be able to do: encrypts :patron_name, :patron_email, previous_versions: [{master_key: "..."}] You can speed up step 4 by updating both at once (saves a DB query). Admin::RAndRItem.unscoped.find_each { |x| x.update!(patron_name: x.patron_name, patron_email: x.patron_email) } There's a bit more that can be optimized by batching DB transactions (I've been meaning to do this for Lockbox.rotate(Admin::RAndRItem, attributes: [:patron_name, :patron_email]) that handles this automatically. |
Yeah -- that will be a very useful feature. Thanks for your help; we appreciate it. |
On master, you can now do: Lockbox.rotate(Admin::RAndRItem, attributes: [:patron_name, :patron_email]) which includes the optimization mentioned above. Will add it to the readme once the next version goes out. |
The rotation with the encrypts :patron_name, previous_versions: [{master_key: ENV['LOCKBOX_MASTER_KEY_OLD']}] I have to fetch the attribute key by the old master key to be able to decrypt the value and do the rotation: encrypts :patron_name, previous_versions: [{key: Lockbox.attribute_key(table: 'r_and_r_items', attribute: 'patron_name_ciphertext', master_key: ENV['LOCKBOX_MASTER_KEY_OLD'])}] Edit: exchange "encrypt" with correct meaning "decrypt" |
Hi @ankane, with the encrypts :patron_name, previous_versions: [{master_key: ENV['LOCKBOX_MASTER_KEY_OLD']}] |
I install
lockbox-0.3.1
I set up a model with
encrypts :patron_email
I run the migration
add_column :r_and_r_items, :patron_name_ciphertext, :text
I set my master key in dev:
I persist an item with this key.
It's persisted correctly -- the value in the database is encrypted, and the value as shown is correct.
Let's suppose my key is compromised.
I now change the lockbox_master_key used to
As expected, I get a
Lockbox::DecryptionError: Decryption failed
if I try to decrypt the encoded patron_email with the new key.I now change the model to:
Expected behavior:
Lockbox attempts to decypher the encrypted patron_email, fails, then tries with the key listed in previous_versions, succeeds, and returns that.
Actual behavior:
Lockbox::DecryptionError: Decryption failed is thrown.
The text was updated successfully, but these errors were encountered: