Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix decryption fallback after adding a secret
Signed-off-by: Julius Härtl <[email protected]>
(cherry picked from commit a6796b4)
  • Loading branch information
juliusknorr authored and PVince81 committed Dec 5, 2022
commit 0f7260de03b3fd5b1cf70cd79a1d6c77faeb56f5
15 changes: 10 additions & 5 deletions lib/private/Security/Crypto.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,19 @@ public function encrypt(string $plaintext, string $password = ''): string {
* @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;
}
}

Expand Down