Skip to content

Commit 74a0c37

Browse files
committed
AC-8017 system settings improvement
1 parent e5ffa96 commit 74a0c37

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

dev/tests/integration/testsuite/Magento/EncryptionKey/Setup/Patch/Data/SodiumChachaPatchTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\EncryptionKey\Setup\Patch\Data;
1010

11+
use Magento\Framework\Config\ConfigOptionsListConstants;
1112
use Magento\Framework\ObjectManagerInterface;
1213
use Magento\Framework\App\DeploymentConfig;
1314
use Magento\Framework\Encryption\Encryptor;
@@ -88,7 +89,7 @@ private function legacyEncrypt(string $data): string
8889
$handle = @mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
8990
$initVectorSize = @mcrypt_enc_get_iv_size($handle);
9091
$initVector = str_repeat("\0", $initVectorSize);
91-
@mcrypt_generic_init($handle, $this->deployConfig->get(static::PATH_KEY), $initVector);
92+
@mcrypt_generic_init($handle, $this->getEncryptionKey(), $initVector);
9293

9394
$encrpted = @mcrypt_generic($handle, $data);
9495

@@ -98,4 +99,12 @@ private function legacyEncrypt(string $data): string
9899

99100
return '0:' . Encryptor::CIPHER_RIJNDAEL_256 . ':' . base64_encode($encrpted);
100101
}
102+
103+
private function getEncryptionKey(): string
104+
{
105+
$key = $this->deployConfig->get(static::PATH_KEY);
106+
return (str_starts_with($key, ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX)) ?
107+
base64_decode(substr($key, strlen(ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX))) :
108+
$key;
109+
}
101110
}

dev/tests/integration/testsuite/Magento/Sales/_files/payment_enc_cc.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Framework\Api\SearchCriteriaBuilder;
1010
use Magento\Framework\Api\SearchCriteria;
11+
use Magento\Framework\Config\ConfigOptionsListConstants;
1112
use Magento\Sales\Api\OrderRepositoryInterface;
1213
use Magento\Sales\Model\ResourceModel\Order\Payment\EncryptionUpdateTest;
1314
use Magento\Framework\App\DeploymentConfig;
@@ -30,7 +31,14 @@
3031
$handle = @mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
3132
$initVectorSize = @mcrypt_enc_get_iv_size($handle);
3233
$initVector = str_repeat("\0", $initVectorSize);
33-
@mcrypt_generic_init($handle, $deployConfig->get('crypt/key'), $initVector);
34+
35+
// Key is also encrypted to support 256-key
36+
$key = $deployConfig->get('crypt/key');
37+
$originalKey = (str_starts_with($key, ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX)) ?
38+
base64_decode(substr($key, strlen(ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX))) :
39+
$key;
40+
41+
@mcrypt_generic_init($handle, $originalKey, $initVector);
3442

3543
$encCcNumber = @mcrypt_generic($handle, EncryptionUpdateTest::TEST_CC_NUMBER);
3644

0 commit comments

Comments
 (0)