This repository was archived by the owner on Apr 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Discussion: Encryption with Libsodium
Olga Kopylova edited this page May 4, 2018
·
4 revisions
The original Design Document is at HLD Removing mcrypt and adding libsodium.
Purpose of this page is to provide transparency via an open discussion. The page may include:
- open questions
- ideas and proposals
- notes and action items from the meetings
The page will be updated as the discussion progresses. See revisions of the page if needed.
- What functions should we use:
crypto_aead_*
orcrypto_secretbox*
? See - recommendations (includes code sample)- Also, clarify what ciphers are used to understand what needs to be added to the ciphertext
-
XChaCha20-Poly1305-IETF
(check what's supported by current library version) forcrypto_aead_xchacha20poly1305_ietf
orxsalsa20poly1305
forcrypto_secretbox
-
- Also, clarify what ciphers are used to understand what needs to be added to the ciphertext
- Decide on migration strategy
- Calculate possible amount of stored encrypted data
- Investigate if it's safe to use https://github.com/paragonie/sodium_compat
- It supports functions mentioned above
- Based on the #3 decide on the implementation strategy:
- Completely switch to sodium (if
sodium_compat
is an acceptable option) - Support both
mcrypt
andsodium
based on what's installed in the system. Usemcrypt_compat
formcrypt
support as we don't havemcrypt
incomposer.json
requirements
- Completely switch to sodium (if
- Use
mcrypt
for decrypting existing data. Usemcrypt_compat
. The mcrypt library in Magento Framework should be deprecated
- Deprecate
\Magento\Framework\Encryption\Crypt
. Its interface is incompatible with Sodium interface, so can't be reused. It can be still used for decrypting of old data.mcrypt_compat
is already included in Magento 2.3, so nothing needs to be done in the class itself- Potentially we won't be able to remove the library for long time (ever?) because merchants may migrate from old versions of Magento at any time in the future, and so it may be necessary to decrypt old data at any time. As an option (if it's necessary to remove the library for security compliance), we may remove it from the Magento Framework and release as a separate package with recommendations to use it for migration. In this case it should be distributed as a tool that migrates data, so that Magento code doesn't have references to the library.
- Create
EncryptorAdapterInterface
- Create
SodiumAdapter
implementation - No necessity to create an
mcrypt
implementation as it will be deprecated anyways, it should not be an alternative forEncryptorAdapterInterface
. Use existing\Magento\Framework\Encryption\Crypt
instead (the only use case is to decrypt old messages
- Create
- In
\Magento\Framework\Encryption\Encryptor
- Add new version of cipher: based on the investigation
- In
\Magento\Framework\Encryption\Encryptor::decrypt()
:- Identify the library used for encryption based on the data
- Select the "strategy" (mcrypt vs sodium). As the
mcrypt
implementation does not really implement theEncryptorAdapterInterface
interface, it won't be a real strategy, just different classes will be used based on the cipher. - Decrypt
- In
\Magento\Framework\Encryption\Encryptor::encrypt()
- Use sodium adapter
-
Design Document
- Discussion: Encryption with Libsodium
- Info
- ZenHub board
-
Weekly calls(on pause): - Slack: #feature-php-72