Skip to content

Commit 0eeb3eb

Browse files
committed
Merge remote-tracking branch 'origin/mcrypt' into libs-upgrade
2 parents 380eb66 + 93949eb commit 0eeb3eb

File tree

2 files changed

+17
-247
lines changed

2 files changed

+17
-247
lines changed

lib/internal/Magento/Framework/Encryption/Test/Unit/Crypt/_files/_crypt_fixtures.php

Lines changed: 4 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -14,235 +14,43 @@
1414
5 => '',
1515
],
1616
1 => [
17-
0 => 'cc188f97f1bbd2f7a265e57c0dbb004ac29c1a88dc846ea6aed1c80c',
18-
1 => 'blowfish',
19-
2 => 'cbc',
20-
3 => '48da27c4',
21-
4 => '',
22-
5 => '',
23-
],
24-
2 => [
25-
0 => '8bf1685366faa72ce1e4fbe1f89656e1de1fd186331c8fa255dde0eb',
26-
1 => 'blowfish',
27-
2 => 'cfb',
28-
3 => '70c1592a',
29-
4 => '',
30-
5 => '',
31-
],
32-
3 => [
33-
0 => '5d304b80fbe2f6d6eaa51103d7558368e15f843b005fbd6353b7d0dd',
34-
1 => 'blowfish',
35-
2 => 'ofb',
36-
3 => 'a8e85663',
37-
4 => '',
38-
5 => '',
39-
],
40-
4 => [
41-
0 => 'f33d7a68248758b77863569a9caa08271fcda17eb3903e8c8f01ea48',
42-
1 => 'blowfish',
43-
2 => 'nofb',
44-
3 => '5919959b',
45-
4 => '',
46-
5 => '',
47-
],
48-
5 => [
4917
0 => '7e34794ae07b3540a683cfd47b24a039',
5018
1 => 'rijndael-128',
5119
2 => 'ecb',
5220
3 => '4b30de87edb9eee1',
5321
4 => '',
5422
5 => '',
5523
],
56-
6 => [
57-
0 => 'eed11fb167c5ba7c6666b0379d3f0efd',
58-
1 => 'rijndael-128',
59-
2 => 'cbc',
60-
3 => 'f87fb9492e358ff7',
61-
4 => '',
62-
5 => '',
63-
],
64-
7 => [
65-
0 => 'b0baa1454a71e4902d2f21cca5822a43',
66-
1 => 'rijndael-128',
67-
2 => 'cfb',
68-
3 => 'ca5f40f310fbf41c',
69-
4 => '',
70-
5 => '',
71-
],
72-
8 => [
73-
0 => '097577dd9bd37a37670d4ffac6db71ca',
74-
1 => 'rijndael-128',
75-
2 => 'ofb',
76-
3 => '9662705b5c8a92e2',
77-
4 => '',
78-
5 => '',
79-
],
80-
9 => [
81-
0 => '26283c5ee61006051e109fb13cbeadd4',
82-
1 => 'rijndael-128',
83-
2 => 'nofb',
84-
3 => 'fbae555d61cb4ab3',
85-
4 => '',
86-
5 => '',
87-
],
88-
10 => [
89-
0 => '912940718c6991dcc9927fe1357a59eb',
90-
1 => 'rijndael-256',
91-
2 => 'ecb',
92-
3 => '6041192a9ed0647219bfba45306be4bc',
93-
4 => '',
94-
5 => '',
95-
],
96-
11 => [
24+
2 => [
9725
0 => '22eaec79b2ae279beac05375f1dd301f',
9826
1 => 'rijndael-256',
9927
2 => 'cbc',
10028
3 => 'a4c67e7ee66f7c8dde975dd224e47533',
10129
4 => '',
10230
5 => '',
10331
],
104-
12 => [
105-
0 => '331ff7ee00849ef02acfcc4a4c44b002',
106-
1 => 'rijndael-256',
107-
2 => 'cfb',
108-
3 => 'e7da553b177006fb878f2189815b146c',
109-
4 => '',
110-
5 => '',
111-
],
112-
13 => [
113-
0 => '52b9991fb182434f8ef64db604c1946a',
114-
1 => 'rijndael-256',
115-
2 => 'ofb',
116-
3 => '95118150491d3acb936fed8f8aad942a',
117-
4 => '',
118-
5 => '',
119-
],
120-
14 => [
121-
0 => '42cba7ea2c940077df289a594170c846',
122-
1 => 'rijndael-256',
123-
2 => 'nofb',
124-
3 => '11211b3d82f6a7d8cc864f3ffee958c1',
125-
4 => '',
126-
5 => '',
127-
],
128-
15 => [
32+
3 => [
12933
0 => '72f761d4c435986911087485b8664d40b28d12f818eca42edf84fecd',
13034
1 => 'blowfish',
13135
2 => 'ecb',
13236
3 => '5612d7ae',
13337
4 => 'Hello world!!!',
13438
5 => 'UObRTUnq3jCNZjJOxwNubA==',
13539
],
136-
16 => [
137-
0 => '63341175e4edd8ef27ea0d754f985b6bbfddd29b381ea8473a450b8c',
138-
1 => 'blowfish',
139-
2 => 'cbc',
140-
3 => '8cc63606',
141-
4 => 'Hello world!!!',
142-
5 => '18QUXHt++6HiTQynQ4nUkg==',
143-
],
144-
17 => [
145-
0 => '5c4beba2e7571460dd0c2a6971dec5d707b6d8681a69e927ba8fac9f',
146-
1 => 'blowfish',
147-
2 => 'cfb',
148-
3 => 'e93e050d',
149-
4 => 'Hello world!!!',
150-
5 => '11ubM60SiGkecJRFZMQ=',
151-
],
152-
18 => [
153-
0 => '073f901024e51b0ab85cf5944a90aea92bf353083ff642024f61a62d',
154-
1 => 'blowfish',
155-
2 => 'ofb',
156-
3 => 'a9b4f0ca',
157-
4 => 'Hello world!!!',
158-
5 => 'SqliQR1lHxY4r/HCgoI=',
159-
],
160-
19 => [
161-
0 => '56df989b718351624480eb7776f827da7caf7996a6aa38dfa3e7328a',
162-
1 => 'blowfish',
163-
2 => 'nofb',
164-
3 => '4178906f',
165-
4 => 'Hello world!!!',
166-
5 => 'vkPrtkjZ9TPapsG1sEY=',
167-
],
168-
20 => [
40+
4 => [
16941
0 => '6f326ec41c0e1d17fc030018043c0862',
17042
1 => 'rijndael-128',
17143
2 => 'ecb',
17244
3 => '0a85b06abcb9ea59',
17345
4 => 'Hello world!!!',
17446
5 => 'dYsG1NhOM0lvXj32RqXJuw==',
17547
],
176-
21 => [
177-
0 => '7891bd79c8bae053e795733dd6b99d4e',
178-
1 => 'rijndael-128',
179-
2 => 'cbc',
180-
3 => '11e5244c25e3cdc2',
181-
4 => 'Hello world!!!',
182-
5 => '5rMjKp16UzjD1rxcTFqNfg==',
183-
],
184-
22 => [
185-
0 => '247ec5c7e7fa07628090ed1e07bc601f',
186-
1 => 'rijndael-128',
187-
2 => 'cfb',
188-
3 => '7afdde5cb2adca91',
189-
4 => 'Hello world!!!',
190-
5 => 'OOhZb1g3owMU05jD2qk=',
191-
],
192-
23 => [
193-
0 => '0cedc5085da7c010a4136f7cc4c8f073',
194-
1 => 'rijndael-128',
195-
2 => 'ofb',
196-
3 => 'f7cf137c927714de',
197-
4 => 'Hello world!!!',
198-
5 => 'iq9Kx0artzuKew+HWpU=',
199-
],
200-
24 => [
201-
0 => 'a0374d4b62c0394e01407f4133bc61c1',
202-
1 => 'rijndael-128',
203-
2 => 'nofb',
204-
3 => '282ff6bb6270b4e5',
205-
4 => 'Hello world!!!',
206-
5 => 'gO5d+xbHk8E+8EH308E=',
207-
],
208-
25 => [
209-
0 => 'afa6f9c61c9199e2e4b6a1426dead6d4',
210-
1 => 'rijndael-256',
211-
2 => 'ecb',
212-
3 => '1ae41175585077595667ef251d8f74e4',
213-
4 => 'Hello world!!!',
214-
5 => 'qTO/oVNzMhFZCnjCY90IuMuJcb7UVa7SXygKHWExX70=',
215-
],
216-
26 => [
48+
5 => [
21749
0 => '774bb6dac74b24796469d1865df679be',
21850
1 => 'rijndael-256',
21951
2 => 'cbc',
22052
3 => 'dd20d7bab2cb020b14c1561440ccfa61',
22153
4 => 'Hello world!!!',
22254
5 => '4APJzBRpwuZSqbIfr/GPS+Zb8wV/uo9qNSOvk68cGRM=',
22355
],
224-
27 => [
225-
0 => '0a319daff472006ec9d10a70920dd592',
226-
1 => 'rijndael-256',
227-
2 => 'cfb',
228-
3 => '99fa50190792623b19a62a2d59b40105',
229-
4 => 'Hello world!!!',
230-
5 => 'GbcnmzgYRB+4ETtw5zQ=',
231-
],
232-
28 => [
233-
0 => '4fbd81fce821dd6042b46051eddcc300',
234-
1 => 'rijndael-256',
235-
2 => 'ofb',
236-
3 => 'b78b752f32a9788347f6f70e7a5fe1f0',
237-
4 => 'Hello world!!!',
238-
5 => 'PvbnFhmV0tej2c6zVIc=',
239-
],
240-
29 => [
241-
0 => 'c183b2078424e7c9c129ba425421c0eb',
242-
1 => 'rijndael-256',
243-
2 => 'nofb',
244-
3 => '97b3940cce9106b7c5a7f266f0a334bd',
245-
4 => 'Hello world!!!',
246-
5 => '2HhsW5Wlw9glUVy9mGo=',
247-
],
24856
];

lib/internal/Magento/Framework/Encryption/Test/Unit/CryptTest.php

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ class CryptTest extends \PHPUnit\Framework\TestCase
1515

1616
private static $_cipherInfo;
1717

18-
protected $_supportedCiphers = [MCRYPT_BLOWFISH, MCRYPT_RIJNDAEL_128, MCRYPT_RIJNDAEL_256];
19-
20-
protected $_supportedModes = [
21-
MCRYPT_MODE_ECB,
22-
MCRYPT_MODE_CBC,
23-
MCRYPT_MODE_CFB,
24-
MCRYPT_MODE_OFB,
25-
MCRYPT_MODE_NOFB,
18+
private const SUPPORTED_CIPHER_MODE_COMBINATIONS = [
19+
MCRYPT_BLOWFISH => [MCRYPT_MODE_ECB],
20+
MCRYPT_RIJNDAEL_128 => [MCRYPT_MODE_ECB],
21+
MCRYPT_RIJNDAEL_256 => [MCRYPT_MODE_CBC],
2622
];
2723

2824
protected function setUp()
@@ -42,23 +38,7 @@ protected function _getRandomString($length)
4238
protected function _requireCipherInfo()
4339
{
4440
$filename = __DIR__ . '/Crypt/_files/_cipher_info.php';
45-
/* Generate allowed sizes for encryption key and init vector
46-
$data = array();
47-
foreach ($this->_supportedCiphers as $cipher) {
48-
if (!array_key_exists($cipher, $data)) {
49-
$data[$cipher] = array();
50-
}
51-
foreach ($this->_supportedModes as $mode) {
52-
$cipherHandle = mcrypt_module_open($cipher, '', $mode, '');
53-
$data[$cipher][$mode] = array(
54-
'key_size' => mcrypt_enc_get_key_size($cipherHandle),
55-
'iv_size' => mcrypt_enc_get_iv_size($cipherHandle),
56-
);
57-
mcrypt_module_close($cipherHandle);
58-
}
59-
}
60-
file_put_contents($filename, '<?php return ' . var_export($data, true) . ";\n", LOCK_EX);
61-
*/
41+
6242
if (!self::$_cipherInfo) {
6343
self::$_cipherInfo = include $filename;
6444
}
@@ -76,11 +56,12 @@ protected function _getInitVectorSize($cipherName, $modeName)
7656
return self::$_cipherInfo[$cipherName][$modeName]['iv_size'];
7757
}
7858

79-
public function getCipherModeCombinations()
59+
public function getCipherModeCombinations(): array
8060
{
8161
$result = [];
82-
foreach ($this->_supportedCiphers as $cipher) {
83-
foreach ($this->_supportedModes as $mode) {
62+
foreach (self::SUPPORTED_CIPHER_MODE_COMBINATIONS as $cipher => $modes) {
63+
/** @var array $modes */
64+
foreach ($modes as $mode) {
8465
$result[$cipher . '-' . $mode] = [$cipher, $mode];
8566
}
8667
}
@@ -105,8 +86,9 @@ public function testConstructor($cipher, $mode)
10586
public function getConstructorExceptionData()
10687
{
10788
$result = [];
108-
foreach ($this->_supportedCiphers as $cipher) {
109-
foreach ($this->_supportedModes as $mode) {
89+
foreach (self::SUPPORTED_CIPHER_MODE_COMBINATIONS as $cipher => $modes) {
90+
/** @var array $modes */
91+
foreach ($modes as $mode) {
11092
$tooLongKey = str_repeat('-', $this->_getKeySize($cipher, $mode) + 1);
11193
$tooShortInitVector = str_repeat('-', $this->_getInitVectorSize($cipher, $mode) - 1);
11294
$tooLongInitVector = str_repeat('-', $this->_getInitVectorSize($cipher, $mode) + 1);
@@ -140,27 +122,7 @@ public function testConstructorDefaults()
140122
public function getCryptData()
141123
{
142124
$fixturesFilename = __DIR__ . '/Crypt/_files/_crypt_fixtures.php';
143-
/* Generate fixtures
144-
$fixtures = array();
145-
foreach (array('', 'Hello world!!!') as $inputString) {
146-
foreach ($this->_supportedCiphers as $cipher) {
147-
foreach ($this->_supportedModes as $mode) {
148-
$randomKey = $this->_getRandomString($this->_getKeySize($cipher, $mode));
149-
$randomInitVector = $this->_getRandomString($this->_getInitVectorSize($cipher, $mode));
150-
$crypt = new \Magento\Framework\Encryption\Crypt($randomKey, $cipher, $mode, $randomInitVector);
151-
$fixtures[] = array(
152-
$randomKey, // Encryption key
153-
$cipher,
154-
$mode,
155-
$randomInitVector, // Init vector
156-
$inputString, // String to encrypt
157-
base64_encode($crypt->encrypt($inputString)) // Store result of encryption as base64
158-
);
159-
}
160-
}
161-
}
162-
file_put_contents($fixturesFilename, '<?php return ' . var_export($fixtures, true) . ";\n", LOCK_EX);
163-
*/
125+
164126
$result = include $fixturesFilename;
165127
/* Restore encoded string back to binary */
166128
foreach ($result as &$cryptParams) {

0 commit comments

Comments
 (0)