-
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 (Decryption failed) when rotating #97
Comments
Hey @herunan, those steps look correct. A few questions:
|
Is it a requirement for there to be actual values at all for the rotation to work? Edit: tested with an |
Can you paste the stack trace for the error? Also, I'd confirm you can still decrypt after doing step 5 (run |
I'm getting some odd behaviour where the first instance of
What was the This is the full trace:
I recreated the local database and created a new user account and a newly-generated set of keys. Then attempted to rotate following the steps above. Same results. |
Okay, I found the issue. It seems that the previous key is accepted for the first decryption operation every time you start a Rails console session. As soon as you run a second operation, it won't accept the previous key. I connected the dots when I was able to rotate once I singled out the email with: |
It seems like the issue is I'd try forking and adding some debugging around here to see how the options change between the first and second time. Also, to get the full stack trace in the Rails console, you can do: begin; User.last.email; rescue => e; puts e.backtrace; end |
I've been using the same docs on a brand new Rails app and I'm facing the same issue on the second decryption per session. These are my migrations:
My model and initializer for the rotation setup after creating a user with email (master keys are throwaways):
Full stack trace after decrypting a second time:
|
From the stack trace, it looks like you're on Lockbox 0.4.9. Try upgrading to the latest version (0.6.2). |
🤦♂️ |
When I try to rotate the key I get
Lockbox::DecryptionError (Decryption failed)
(even inmaster
, which helped in this issue)Steps to reproduce:
I have a master key in place here:
Rails.application.credentials.lockbox[:master_key]
Suppose it got leaked. I generate a new key:
Lockbox.generate_key
I store it as the new
master_key
here:Rails.application.credentials.lockbox[:master_key]
The old one is now
old_master_key
here:Rails.application.credentials.lockbox[:old_master_key]
I modify my User model with:
encrypts :email, :unconfirmed_email, previous_versions: [{master_key: Rails.application.credentials.lockbox[:old_master_key]}]
I run
Lockbox.rotate(User, attributes: [:email, :unconfirmed_email])
I get
Lockbox::DecryptionError (Decryption failed)
The text was updated successfully, but these errors were encountered: