-
Notifications
You must be signed in to change notification settings - Fork 153
Mcrypt to Sodium migration #4
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
Conversation
1. Possibly, 2.3.x patch version. The implementation should be fully backward compatible | ||
2. Use Sodium library for encryption, as this is the latest encryption library supported natively by the latest PHP version (PHP 7.2) | ||
3. Ensure encryption is possible on PHP 7.1, which is also supported by Magneto 2.3 | ||
4. Data is migrated to the new algorithm if necessary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
migrated to be compatible with the new algorithm
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
## 3. Data migration | ||
|
||
* Limited or expected-to-be small amount of data to be converted during upgrade process | ||
* Large amount of data to be migrated on the fly: the data is re-encrypted when read and stored again during application work. Currently used encryption algorithms are secure enough to allow the data stay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should specify a procedure of converting all the remaining data at some point. Because not all data will be accessed over the specific period of time.
The time of the upgrade was a concerns for SIs during migration to Magento 2.2 because of serialize
to json_encode
conversion, we need to make sure to prevent similar issues this time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we don't migrate the data, the application will work fine, we will still support old algorithms. While, for serialize
-> json_encode
task, we had to migrate all the data during upgrade because we had to eliminate usages of serialize
.
I'll add to the document (as a separate PR) as we investigate options for data migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added example of CLI implementation.
Adding comment from @paragonie-scott on the difference between aead and secretbox functions: This really comes down to a matter of taste.
Given the two options: I'd choose crypto_aead_xchacha20poly1305_ietf_encrypt() and crypto_aead_xchacha20poly1305_ietf_decrypt() over the secretbox API, but neither option is bad.
Let's say you wanted to encrypt password hashes in the database, per user. A naive approach that would work would be this:
The benefit of this API change is subtle. Consider the following scenario where you have access to a website's database (via read/write SQL injection) but not the filesystem (so, not the keys). If you wanted to steal users' passwords, you'd need to first be able to decrypt the hashes then crack them. To do so you need the key. If you can't steal it from the filesytem, both secretbox and AEAD approaches will stop this attack. So far so good. Suppose the attacker simply wants to impersonate a user. So what they do is:
In this case, the AEAD approach stops the attack since the ciphertext will fail to decrypt, because their serial IDs are mismatched. The secretbox approach will not, because it has no context; it only cares about encryption and decryption. While I do prefer the AEAD approach in my own designs, if you don't foresee any use for the additional data being included in the authenticated tag and the thin margin between the security postures of Salsa20 and ChaCha aren't a concern to you, feel free to use secretbox (which uses xsalsa20 instead of xchacha20). |
Epic: magento-engcom/php-7.2-support#135 (https://app.zenhub.com/workspace/o/magento-engcom/php-7.2-support/issues/127)
Original document (for better view) https://github.com/magento-architects/architecture/blob/sodium/design-documents/mcrypt-to-sodium-migration.md (or you can use "View" button on the "Files changed" tab).