Skip to content

Commit ca1f668

Browse files
committed
Merge branch '2.4-develop' of https://github.com/adobe-commerce-tier-4/magento2ce into ACP2E-3043
2 parents 21abc71 + b90bf99 commit ca1f668

File tree

29 files changed

+1541
-485
lines changed

29 files changed

+1541
-485
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Config\Model\Data\ReEncryptorList\CoreConfigDataReEncryptor;
9+
10+
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Framework\Encryption\EncryptorInterface;
12+
use Magento\EncryptionKey\Model\Data\ReEncryptorList\ReEncryptor\HandlerInterface;
13+
use Magento\EncryptionKey\Model\Data\ReEncryptorList\ReEncryptor\Handler\ErrorFactory;
14+
use Magento\Framework\DB\Query\Generator;
15+
16+
/**
17+
* Handler for core configuration re-encryption.
18+
*/
19+
class Handler implements HandlerInterface
20+
{
21+
/**
22+
* @var string
23+
*/
24+
private const PATTERN = "^[[:digit:]]+:[[:digit:]]+:.*$";
25+
26+
/**
27+
* @var string
28+
*/
29+
private const TABLE_NAME = "core_config_data";
30+
31+
/**
32+
* @var int
33+
*/
34+
private const BATCH_SIZE = 1000;
35+
36+
/**
37+
* @var string
38+
*/
39+
private const IDENTIFIER = "config_id";
40+
41+
/**
42+
* @var EncryptorInterface
43+
*/
44+
private EncryptorInterface $encryptor;
45+
46+
/**
47+
* @var ResourceConnection
48+
*/
49+
private ResourceConnection $resourceConnection;
50+
51+
/**
52+
* @var ErrorFactory
53+
*/
54+
private ErrorFactory $errorFactory;
55+
56+
/**
57+
* @var Generator
58+
*/
59+
private Generator $queryGenerator;
60+
61+
/**
62+
* @param EncryptorInterface $encryptor
63+
* @param ResourceConnection $resourceConnection
64+
* @param ErrorFactory $errorFactory
65+
* @param Generator $queryGenerator
66+
*/
67+
public function __construct(
68+
EncryptorInterface $encryptor,
69+
ResourceConnection $resourceConnection,
70+
ErrorFactory $errorFactory,
71+
Generator $queryGenerator
72+
) {
73+
$this->encryptor = $encryptor;
74+
$this->resourceConnection = $resourceConnection;
75+
$this->errorFactory = $errorFactory;
76+
$this->queryGenerator = $queryGenerator;
77+
}
78+
79+
/**
80+
* @inheritDoc
81+
*/
82+
public function reEncrypt(): array
83+
{
84+
$errors = [];
85+
$tableName = $this->resourceConnection->getTableName(
86+
self::TABLE_NAME
87+
);
88+
$connection = $this->resourceConnection->getConnection();
89+
90+
$select = $connection->select()
91+
->from($tableName, ['config_id', 'value'])
92+
->where('value != ?', '')
93+
->where('value IS NOT NULL')
94+
->where('value REGEXP ?', self::PATTERN);
95+
96+
$iterator = $this->queryGenerator->generate(
97+
self::IDENTIFIER,
98+
$select,
99+
self::BATCH_SIZE
100+
);
101+
102+
foreach ($iterator as $batch) {
103+
foreach ($connection->fetchAll($batch) as $row) {
104+
try {
105+
$connection->update(
106+
$tableName,
107+
['value' => $this->encryptor->encrypt($this->encryptor->decrypt($row['value']))],
108+
['config_id = ?' => $row['config_id']]
109+
);
110+
} catch (\Throwable $e) {
111+
$errors[] = $this->errorFactory->create(
112+
self::IDENTIFIER,
113+
$row['config_id'],
114+
$e->getMessage()
115+
);
116+
117+
continue;
118+
}
119+
}
120+
}
121+
122+
return $errors;
123+
}
124+
}

app/code/Magento/Config/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"magento/module-directory": "*",
1414
"magento/module-email": "*",
1515
"magento/module-media-storage": "*",
16-
"magento/module-store": "*"
16+
"magento/module-store": "*",
17+
"magento/module-encryption-key": "*"
1718
},
1819
"type": "magento2-module",
1920
"license": [

app/code/Magento/Config/etc/di.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
@@ -409,4 +409,17 @@
409409
</argument>
410410
</arguments>
411411
</type>
412+
<virtualType name="Magento\Config\Model\Data\ReEncryptorList\CoreConfigDataReEncryptor" type="Magento\EncryptionKey\Model\Data\ReEncryptorList\ReEncryptor">
413+
<arguments>
414+
<argument name="description" xsi:type="string">Re-encrypts 'value' column in the 'core_config_data' DB table.</argument>
415+
<argument name="handler" xsi:type="object">Magento\Config\Model\Data\ReEncryptorList\CoreConfigDataReEncryptor\Handler</argument>
416+
</arguments>
417+
</virtualType>
418+
<type name="Magento\EncryptionKey\Model\Data\ReEncryptorList">
419+
<arguments>
420+
<argument name="reEncryptors" xsi:type="array">
421+
<item name="core_config_data" xsi:type="object">Magento\Config\Model\Data\ReEncryptorList\CoreConfigDataReEncryptor</item>
422+
</argument>
423+
</arguments>
424+
</type>
412425
</config>

app/code/Magento/EncryptionKey/Block/Adminhtml/Crypt/Key/Edit.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\EncryptionKey\Block\Adminhtml\Crypt\Key;
77

88
/**
99
* Encryption key change edit page block
1010
*
1111
* @api
12+
* @deprecated
13+
* @see Extensible Data ReEncryption Mechanism Implemented
1214
* @since 100.0.2
1315
*/
1416
class Edit extends \Magento\Backend\Block\Widget\Form\Container

app/code/Magento/EncryptionKey/Block/Adminhtml/Crypt/Key/Form.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -11,6 +11,8 @@
1111
* Encryption key change form block
1212
*
1313
* @api
14+
* @deprecated
15+
* @see Extensible Data ReEncryption Mechanism Implemented
1416
* @since 100.0.2
1517
*/
1618
class Form extends \Magento\Backend\Block\Widget\Form\Generic
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\EncryptionKey\Console\Command;
9+
10+
use Magento\Framework\Console\Cli;
11+
use Symfony\Component\Console\Command\Command;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
use Magento\EncryptionKey\Model\Data\ReEncryptorList;
15+
16+
/**
17+
* Command for displaying a list of available data re-encryptors.
18+
*/
19+
class ListReEncryptorsCommand extends Command
20+
{
21+
/**
22+
* @var ReEncryptorList
23+
*/
24+
private ReEncryptorList $reEncryptorList;
25+
26+
/**
27+
* @param ReEncryptorList $reEncryptorList
28+
*/
29+
public function __construct(
30+
ReEncryptorList $reEncryptorList
31+
) {
32+
$this->reEncryptorList = $reEncryptorList;
33+
34+
parent::__construct();
35+
}
36+
37+
/**
38+
* @inheritDoc
39+
*/
40+
protected function configure()
41+
{
42+
$this->setName('encryption:data:list-re-encryptors');
43+
44+
$this->setDescription(
45+
'Shows a list of available data re-encryptors.'
46+
);
47+
48+
parent::configure();
49+
}
50+
51+
/**
52+
* @inheritDoc
53+
*/
54+
protected function execute(InputInterface $input, OutputInterface $output)
55+
{
56+
foreach ($this->reEncryptorList->getReEncryptors() as $name => $reEncryptor) {
57+
$output->writeln(
58+
sprintf(
59+
'<fg=green>%-40s</> %s',
60+
$name,
61+
$reEncryptor->getDescription()
62+
)
63+
);
64+
}
65+
66+
return Cli::RETURN_SUCCESS;
67+
}
68+
}

0 commit comments

Comments
 (0)