You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@opensourcepos/org thoughts?
The standard encryption cipher used in CI4 is aes-256-ctr. This is inherently more secure than CI3's aes-128-cbc, but that also means that as of CI4.3.1 it still cannot decrypt CI3 encrypted text. As of 4.3.0 there is supposed to be backward compatible, but it's incorrectly trying to decrypt the data with a aes-256-ctr cipher.
I have been able to import the CI3 encryption class as a library and it works to encrypt CI3 versions of the data. The solution here is not to continue using CI3 encryption.
Instead we need to migrate the encrypted data to CI4. To do this we need to create a migration that will pull down all the rows that are encrypted, decrypt them, then re-encrypt them using CI4 encryption and send them back to the database tables. A couple of things to think through:
I believe AES-128-CBC uses a 16 character key, though will accept a 32 character key (I think it just truncates it). We need to decide how to handle situations where the install has a 16 character key, as that will not be acceptable once the data has been decrypted.
IMO the most obvious solution here would be to pull down data, decrypt it, then generate a new key, copy the old key into the .env as a commented line and replace it with a new randomly generated 32 character key. We need to think through all the implications of this though. By copying the line in the .env and then commenting it out, they don't lose their old key in case it's needed.
After further inspection it seems that pretty much everyone will need to have their encryption key upgraded. This is because the aes-128-cbc encryption algorithm we were using have a key length of 32 characters, but the native 256 bit aes-256-ctr encryption algorithm uses a 64 character key.
With that I've added to the existing ci4 migration so that it
Pulls CI3 encrypted data from the database (only existing in the app_config table)
Upgrades or creates the key if it's less than 64 characters and comments out the old key (in case someone wants to keep it).
Re-encrypts the data in CI4 format with the new encryption key.
Saves that to the database in hex format.
I'm still doing some testing on it. I need to make sure it works for new installs or existing.
good idea indeed to keep the old key around , in case something goes wrong. Probably a good test is to read the newly encrypted value back again and decrypt it, to see if it's the same.
good idea indeed to keep the old key around , in case something goes wrong. Probably a good test is to read the newly encrypted value back again and decrypt it, to see if it's the same.
I did this in my testing, but didn't leave it in the code once I was satisfied that it was encrypting, then able to decrypt it. That said, I could potentially add into the migration a check and if it doesn't encrypt/decrypt properly then don't upload it to the database, revert the encryption key and abort the migration.
Activity
objecttothis commentedon Feb 18, 2023
Additionally the key replacer could check the length of the current key and do nothing if it's already 32 characters.
objecttothis commentedon Feb 19, 2023
After further inspection it seems that pretty much everyone will need to have their encryption key upgraded. This is because the aes-128-cbc encryption algorithm we were using have a key length of 32 characters, but the native 256 bit aes-256-ctr encryption algorithm uses a 64 character key.
With that I've added to the existing ci4 migration so that it
I'm still doing some testing on it. I need to make sure it works for new installs or existing.
jekkos commentedon Feb 20, 2023
good idea indeed to keep the old key around , in case something goes wrong. Probably a good test is to read the newly encrypted value back again and decrypt it, to see if it's the same.
objecttothis commentedon Feb 20, 2023
I did this in my testing, but didn't leave it in the code once I was satisfied that it was encrypting, then able to decrypt it. That said, I could potentially add into the migration a check and if it doesn't encrypt/decrypt properly then don't upload it to the database, revert the encryption key and abort the migration.
objecttothis commentedon Feb 27, 2023
This is done.