-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Removing mcrypt compat and replacing it with OpenSSL lib #40053
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
base: 2.4-develop
Are you sure you want to change the base?
Conversation
This commit replaces the deprecated mcrypt extension usage with OpenSSL for encryption and decryption operations within the Magento framework. A new OpenSsl adapter has been introduced, and the Encryptor class has been updated to utilize it. Composer dependencies have been updated to reflect these changes.
Hi @jakwinkler. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
I always wondered about mcrypt in Magento, because it's considered deprecated since many many years. Is it actually still being used in Magento, I mean for real in practice, not in code? If yes, where or in which circumstances? |
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.
Pull Request Overview
This PR replaces the deprecated mcrypt-based encryption with an OpenSSL-backed implementation and removes the mcrypt compatibility library.
- Swaps out the
Mcrypt
adapter for a newOpenSsl
adapter in the core Encryptor - Adds explicit cipher-mode constants, updates method signatures with return types, and refines type hints
- Removes the
phpseclib/mcrypt_compat
dependency from composer
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
lib/internal/Magento/Framework/Encryption/Encryptor.php | Replaced Mcrypt usage with OpenSsl , added MODE constants, and tightened type hints/return types |
lib/internal/Magento/Framework/Encryption/Adapter/OpenSsl.php | Introduced new OpenSsl adapter implementing EncryptionAdapterInterface |
composer.json | Removed the phpseclib/mcrypt_compat package from dependencies |
Comments suppressed due to low confidence (2)
lib/internal/Magento/Framework/Encryption/Adapter/OpenSsl.php:100
- The decrypt() method can throw RuntimeException on failure but lacks a @throws annotation in the docblock; please document thrown exceptions for clarity.
public function decrypt(string $data): string
lib/internal/Magento/Framework/Encryption/Adapter/OpenSsl.php:16
- This new OpenSsl adapter is not covered by unit tests; consider adding tests to validate encrypt/decrypt flows for different ciphers and modes.
class OpenSsl implements EncryptionAdapterInterface
|
||
/** | ||
* Array of encryption keys | ||
* | ||
* @var string[] | ||
*/ | ||
protected $keys = []; | ||
protected array|false $keys = []; |
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.
The property $keys is declared as array|false but initialized to an empty array; consider refining the type to string[] or just array to reflect actual usage and improve clarity.
protected array|false $keys = []; | |
protected string[] $keys = []; |
Copilot uses AI. Check for mistakes.
|
||
/** | ||
* @var KeyValidator | ||
*/ | ||
private $keyValidator; | ||
private mixed $keyValidator; |
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.
Typing $keyValidator as mixed reduces type safety; consider using the explicit KeyValidator type or an interface to maintain strong typing.
private mixed $keyValidator; | |
private KeyValidator $keyValidator; |
Copilot uses AI. Check for mistakes.
// For CBC mode, if IV is not provided for encryption, generate one. | ||
// For decryption, the IV is expected to be part of the data or provided. | ||
if ($this->mode === Encryptor::MODE_CBC && $this->initVector === null) { | ||
$this->initVector = openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->cipherMethod)); |
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.
openssl_random_pseudo_bytes can return false on failure; handle the false case to avoid unexpected null or boolean values in IV generation.
$this->initVector = openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->cipherMethod)); | |
$ivLength = openssl_cipher_iv_length($this->cipherMethod); | |
$generatedIv = openssl_random_pseudo_bytes($ivLength); | |
if ($generatedIv === false) { | |
throw new \RuntimeException('Failed to generate initialization vector using OpenSSL.'); | |
} | |
$this->initVector = $generatedIv; |
Copilot uses AI. Check for mistakes.
@jakwinkler, please review the comments from Copilot and let us know if you would like anything to be fixed based on them. If no, I'll review the pull request |
@magento run all tests |
Description (*)
Replacing
mcrypt
withOpenSSL
lib to use up to date libraries.Fixed Issues (if relevant)
Manual testing scenarios (*)
Contribution checklist (*)