Skip to content

Commit d9efe71

Browse files
Yaroslav VoronoySergey Nosov
authored andcommitted
MAGETWO-47050: Magento 2: encryption keys generated in the admin interface are very weak
1 parent dfa4a53 commit d9efe71

File tree

1 file changed

+15
-3
lines changed
  • app/code/Magento/EncryptionKey/Model/ResourceModel/Key

1 file changed

+15
-3
lines changed

app/code/Magento/EncryptionKey/Model/ResourceModel/Key/Change.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\Config\ConfigOptionsListConstants;
1010
use Magento\Framework\Config\Data\ConfigData;
1111
use Magento\Framework\Config\File\ConfigFilePool;
12+
use Magento\Framework\App\ObjectManager;
1213

1314
/**
1415
* Encryption key changer resource model
@@ -66,15 +67,13 @@ public function __construct(
6667
\Magento\Config\Model\Config\Structure $structure,
6768
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
6869
\Magento\Framework\App\DeploymentConfig\Writer $writer,
69-
\Magento\Framework\Math\Random $random,
7070
$connectionName = null
7171
) {
7272
$this->encryptor = clone $encryptor;
7373
parent::__construct($context, $connectionName);
7474
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::CONFIG);
7575
$this->structure = $structure;
7676
$this->writer = $writer;
77-
$this->random = $random;
7877
}
7978

8079
/**
@@ -102,7 +101,7 @@ public function changeEncryptionKey($key = null)
102101
}
103102

104103
if (null === $key) {
105-
$key = md5($this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE));
104+
$key = md5($this->getRandom()->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE));
106105
}
107106
$this->encryptor->setNewKey($key);
108107

@@ -125,6 +124,19 @@ public function changeEncryptionKey($key = null)
125124
}
126125
}
127126

127+
/**
128+
* Get Math Random
129+
*
130+
* @return \Magento\Framework\Math\Random
131+
*/
132+
public function getRandom()
133+
{
134+
if (!$this->random) {
135+
$this->random = ObjectManager::getInstance()->get('\Magento\Framework\Math\Random');
136+
}
137+
return $this->random;
138+
}
139+
128140
/**
129141
* Gather all encrypted system config values and re-encrypt them
130142
*

0 commit comments

Comments
 (0)