Experimental option to decrypt cache values

This commit is contained in:
Christian Münch committed 2023-08-16 12:28:14 +02:00
1 parent d4bec6b9ce
commit 41dc09be6b
2 files changed
+46 -7

No files matched your search

-1
View File
@@ -6,7 +6,6 @@ RECENT CHANGES
- Fix: #1259: Fix not correct routes for route:list command (by Bohdan Bakalov)
7.1.0
-----
+46 -6
View File
@@ -24,16 +24,33 @@ class ViewCommand extends AbstractMagentoCommand
*/
private $fpc;
/**
* @var \Magento\Framework\Encryption\EncryptorInterface
*/
private $encryptor;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* @param CacheInterface $cache
* @param FullPageCache $fpc
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
* @return void
*/
public function inject(
CacheInterface $cache,
FullPageCache $fpc
FullPageCache $fpc,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Magento\Framework\Serialize\SerializerInterface $serializer
) {
$this->cache = $cache;
$this->fpc = $fpc;
$this->encryptor = $encryptor;
$this->serializer = $serializer;
}
/**
@@ -60,6 +77,12 @@ class ViewCommand extends AbstractMagentoCommand
InputOption::VALUE_NONE,
'Unserialize output'
)
->addOption(
'decrypt',
null,
InputOption::VALUE_NONE,
'Decrypt output with encryption key'
)
->setDescription('Prints a cache entry');
}
@@ -91,10 +114,18 @@ class ViewCommand extends AbstractMagentoCommand
return Command::FAILURE;
}
if ($input->getOption('unserialize')) {
if ($input->getOption('unserialize') && !$input->getOption('decrypt')) {
$cacheData = $this->decorateSerialized($cacheData);
}
if ($input->getOption('decrypt')) {
$cacheData = $this->decorateDecrypt($cacheData);
if ($input->getOption('unserialize')) {
$cacheData = $this->decorateSerialized($cacheData);
}
}
$output->writeln($cacheData);
return Command::SUCCESS;
@@ -106,10 +137,10 @@ class ViewCommand extends AbstractMagentoCommand
*/
private function decorateSerialized($serialized)
{
if (version_compare(phpversion(), '7.0', '>=')) {
$unserialized = \unserialize($serialized, false);
} else {
$unserialized = \unserialize($serialized);
try {
$unserialized = $this->serializer->unserialize($serialized);
} catch (\Exception $e) {
$unserialized = \unserialize($serialized, ['allowed_classes' => false]);
}
if ($unserialized === false) {
@@ -120,4 +151,13 @@ class ViewCommand extends AbstractMagentoCommand
return $buffer;
}
/**
* @param string $encrypted
* @return string
*/
private function decorateDecrypt($encrypted)
{
return $this->encryptor->decrypt($encrypted);
}
}