Fix decryption fallback after adding a secret

Signed-off-by: Julius Härtl <jus@bitgrid.net>
(cherry picked from commit a6796b4247)
This commit is contained in:
Julius Härtl 2022-03-10 11:38:14 +01:00 committed by Vincent Petry (Rebase PR Action)
parent 3ebf7b818b
commit 0f7260de03

View file

@ -122,14 +122,19 @@ class Crypto implements ICrypto {
* @throws Exception If the decryption failed
*/
public function decrypt(string $authenticatedCiphertext, string $password = ''): string {
if ($password === '') {
$password = $this->config->getSystemValue('secret');
}
$secret = $this->config->getSystemValue('secret');
try {
if ($password === '') {
return $this->decryptWithoutSecret($authenticatedCiphertext, $secret);
}
return $this->decryptWithoutSecret($authenticatedCiphertext, $password);
} catch (Exception $e) {
// Retry with empty secret as a fallback for instances where the secret might not have been set by accident
return $this->decryptWithoutSecret($authenticatedCiphertext, '');
if ($password === '') {
// Retry with empty secret as a fallback for instances where the secret might not have been set by accident
return $this->decryptWithoutSecret($authenticatedCiphertext, '');
}
throw $e;
}
}