From c694b9d52b375158790f1c95c0804073dcab57f4 Mon Sep 17 00:00:00 2001 From: J0WI Date: Thu, 24 Jun 2021 01:58:08 +0200 Subject: [PATCH] Remember current cipher Signed-off-by: J0WI --- apps/encryption/lib/Crypto/Crypt.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/apps/encryption/lib/Crypto/Crypt.php b/apps/encryption/lib/Crypto/Crypt.php index a7d7c024cbbcd..8a6be4d38093a 100644 --- a/apps/encryption/lib/Crypto/Crypt.php +++ b/apps/encryption/lib/Crypto/Crypt.php @@ -89,6 +89,9 @@ class Crypt { /** @var IL10N */ private $l; + /** @var string|null */ + private $currentCipher; + /** @var bool */ private $supportLegacy; @@ -248,12 +251,17 @@ private function encrypt($plainContent, $iv, $passPhrase = '', $cipher = self::D } /** - * return Cipher either from config.php or the default cipher defined in + * return cipher either from config.php or the default cipher defined in * this class * * @return string */ - public function getCipher() { + private function getCachedCipher() { + if (isset($this->currentCipher)) { + return $this->currentCipher; + } + + // Get cipher either from config.php or the default cipher defined in this class $cipher = $this->config->getSystemValue('cipher', self::DEFAULT_CIPHER); if (!isset(self::SUPPORTED_CIPHERS_AND_KEY_SIZE[$cipher])) { $this->logger->warning( @@ -267,7 +275,18 @@ public function getCipher() { $cipher = self::DEFAULT_CIPHER; } - return $cipher; + // Remember current cipher to avoid frequent lookups + $this->currentCipher = $cipher; + return $this->currentCipher; + } + + /** + * return current encryption cipher + * + * @return string + */ + public function getCipher() { + return $this->getCachedCipher(); } /** @@ -577,7 +596,7 @@ private function hasSignature($catFile, $cipher) { throw new GenericEncryptionException('Missing Signature', $this->l->t('Missing Signature')); } - // enforce signature for the new 'CTR' ciphers + // Enforce signature for the new 'CTR' ciphers if (!$skipSignatureCheck && $signaturePosition === false && stripos($cipher, 'ctr') !== false) { throw new GenericEncryptionException('Missing Signature', $this->l->t('Missing Signature')); }