File tree Expand file tree Collapse file tree 6 files changed +11
-12
lines changed
app/code/Magento/EncryptionKey/Model/ResourceModel/Key
lib/internal/Magento/Framework Expand file tree Collapse file tree 6 files changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -120,10 +120,8 @@ public function changeEncryptionKey($key = null)
120
120
}
121
121
122
122
if (null === $ key ) {
123
- $ key = $ this ->random ->getRandomBytes (
124
- ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE ,
125
- ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX
126
- );
123
+ $ key = ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX .
124
+ $ this ->random ->getRandomBytes (ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE );
127
125
}
128
126
$ this ->encryptor ->setNewKey ($ key );
129
127
Original file line number Diff line number Diff line change @@ -611,7 +611,7 @@ private function getArgonHash(
611
611
*/
612
612
private function decodeKey (string $ key )
613
613
{
614
- return (strpos ($ key , ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX ) === 0 ) ?
614
+ return (str_starts_with ($ key , ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX )) ?
615
615
base64_decode (substr ($ key , strlen (ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX ))) :
616
616
$ key ;
617
617
}
Original file line number Diff line number Diff line change @@ -25,8 +25,9 @@ class KeyValidator
25
25
*/
26
26
public function isValid ($ value ) : bool
27
27
{
28
- if (strpos ($ value , ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX ) === 0 ) {
29
- return (bool )$ value ;
28
+ if (str_starts_with ($ value , ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX )) {
29
+ return (bool )$ value
30
+ && preg_match ('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/ ' , $ value );
30
31
} else {
31
32
return $ value
32
33
&& strlen ($ value ) === ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE
Original file line number Diff line number Diff line change @@ -89,12 +89,11 @@ public function getUniqueHash($prefix = '')
89
89
* Generate a base64 encoded binary string.
90
90
*
91
91
* @param int $length
92
- * @param string $prefix
93
92
* @return string
94
93
* @throws Exception
95
94
*/
96
- public function getRandomBytes ($ length, $ prefix = '' )
95
+ public function getRandomBytes ($ length )
97
96
{
98
- return $ prefix . base64_encode (random_bytes ($ length ));
97
+ return base64_encode (random_bytes ($ length ));
99
98
}
100
99
}
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ public function generate()
48
48
*/
49
49
private function getRandomString ()
50
50
{
51
- return $ this ->random ->getRandomString (ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE );
51
+ return ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX .
52
+ $ this ->random ->getRandomBytes (ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE );
52
53
}
53
54
}
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ public function testStringForHashingIsReadFromRandom()
40
40
{
41
41
$ this ->randomMock
42
42
->expects ($ this ->once ())
43
- ->method ('getRandomString ' )
43
+ ->method ('getRandomBytes ' )
44
44
->willReturn ('' );
45
45
46
46
$ this ->cryptKeyGenerator ->generate ();
You can’t perform that action at this time.
0 commit comments