Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions apps/encryption/lib/Crypto/Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class Crypt {
/** @var IL10N */
private $l;

/** @var string|null */
private $currentCipher;

/** @var bool */
private $supportLegacy;

Expand Down Expand Up @@ -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(
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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'));
}
Expand Down