Skip to content
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

Remove dependency on mcrypt #200

Merged
merged 1 commit into from
Jan 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Deprecated
- The service `payment.encryption_service` has been deprecated and is now an alias to `payment.encryption.mcrypt`. Parameters specified for `payment.encryption_service` are automatically set for `payment.encryption.mcrypt` so no changes are required in service configuration until `payment.encryption_service` is removed in 2.0.
- The `secret` configuration option has been deprecated in favor of `encryption.secret` and will be removed in 2.0. Please note that if you start using `encryption.secret` you also need to set `encryption.provider` to `mcrypt` since mcrypt is not the default when using the `encryption.*` options.
- `JMS\Payment\CoreBundle\Cryptography\MCryptEncryptionService` has been deprecated and will be removed in 2.0 (`mcrypt` has been deprecated in PHP 7.1 and is removed in PHP 7.2). Refer to http://jmspaymentcorebundle.readthedocs.io/en/stable/guides/mcrypt.html for instructions on how to migrate away from `mcrypt`.

### Added
- Added support for custom encryption providers.
- Added support for data encryption with [defuse/php-encryption](https://github.com/defuse/php-encryption).
- Added ability to configure which crypto provider should be used. Current available options are `mcrypt` (not recommended since it will be removed in PHP 7.2) and `defuse_php_encryption`.
- Added console command to generate an encryption key for use with `defuse_php_encryption`.
- Added ability to configure which encryption provider should be used. Current available options are `mcrypt` (not recommended since it will be removed in PHP 7.2) and `defuse_php_encryption`.

### Removed
- Removed support for PHP 5.3. If you're still using PHP 5.3, please consider upgrading since it reached End Of Life in August 2014. Otherwise, use `1.2.*`.
Expand Down
8 changes: 5 additions & 3 deletions Cryptography/MCryptEncryptionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ public function __construct($secret, $cipher = 'rijndael-256', $mode = 'ctr')
throw new \RuntimeException('The mcrypt extension must be loaded.');
}

if (!in_array($cipher, mcrypt_list_algorithms(), true)) {
@trigger_error('mcrypt has been deprecated in PHP 7.1 and is removed in PHP 7.2. Refer to http://jmspaymentcorebundle.readthedocs.io/en/stable/guides/mcrypt.html for instructions on how to migrate away from mcrypt', E_USER_DEPRECATED);

if (!in_array($cipher, @mcrypt_list_algorithms(), true)) {
throw new \InvalidArgumentException(sprintf('The cipher "%s" is not supported.', $cipher));
}

if (!in_array($mode, mcrypt_list_modes(), true)) {
if (!in_array($mode, @mcrypt_list_modes(), true)) {
throw new \InvalidArgumentException(sprintf('The mode "%s" is not supported.', $mode));
}

Expand All @@ -62,7 +64,7 @@ public function __construct($secret, $cipher = 'rijndael-256', $mode = 'ctr')
}

$key = hash('sha256', $secret, true);
if (strlen($key) > $size = mcrypt_get_key_size($this->cipher, $this->mode)) {
if (strlen($key) > $size = @mcrypt_get_key_size($this->cipher, $this->mode)) {
$key = substr($key, 0, $size);
}
$this->key = $key;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Features:
- Persistence of financial entities (such as payments, transactions, etc.)
- Transaction management including retry logic
- Encryption of sensitive data
- Supports [many](http://jmspaymentcorebundle.readthedocs.io/en/latest/backends.html) payment backends out of the box
- Supports [many](http://jmspaymentcorebundle.readthedocs.io/en/stable/backends.html) payment backends out of the box
- Easily support other payment backends

# Documentation
Expand Down
4 changes: 4 additions & 0 deletions Resources/doc/guides/mcrypt.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Migrating from Mcrypt
=====================

Coming soon
24 changes: 9 additions & 15 deletions Resources/doc/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,28 @@ And register the bundle in your ``AppKernel.php``:
Configuration
-------------
The configuration is as simple as setting a random secret which will be used for encrypting data, in case this is requested.

You can generate the secret with the following command:
The configuration is as simple as setting an encryption key which will be used for encrypting data. You can generate a random key with the following command:

.. code-block :: bash
bin/console jms_payment_core:generate-key
And then use it in your configuration:

.. configuration-block ::
.. code-block :: yaml
.. code-block :: yaml
# app/config/config.yml
jms_payment_core:
encryption:
secret: output_of_above_command
# app/config/config.yml
jms_payment_core:
encryption:
secret: output_of_above_command
.. warning ::
If you change the secret, all data encrypted with the old secret will become unreadable.
If you change the ``secret`` or the ``crypto`` provider, all encrypted data will become unreadable.
Create database tables
----------------------
This bundle requires a few database tables to function. You can create these tables as follows.
This bundle requires a few database tables, which you can create as follows.

If you're not using database migrations:

Expand All @@ -65,14 +61,13 @@ Or, if you're using migrations:
bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate
.. warning ::
.. note ::
It's assumed you have entity auto mapping enabled, which is usually the case. If you don't, you need to either enable it:
.. code-block :: yaml
# app/config/config.yml
doctrine:
orm:
auto_mapping: true
Expand All @@ -82,7 +77,6 @@ Or, if you're using migrations:
.. code-block :: yaml
# app/config/config.yml
doctrine:
orm:
mappings:
Expand Down