summaryrefslogtreecommitdiffstats
path: root/lib/private/Security
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Security')
-rw-r--r--lib/private/Security/Crypto.php17
-rw-r--r--lib/private/Security/Hasher.php9
-rw-r--r--lib/private/Security/VerificationToken/VerificationToken.php9
3 files changed, 31 insertions, 4 deletions
diff --git a/lib/private/Security/Crypto.php b/lib/private/Security/Crypto.php
index e9ef4417925..aeeafcc271c 100644
--- a/lib/private/Security/Crypto.php
+++ b/lib/private/Security/Crypto.php
@@ -122,9 +122,22 @@ 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) {
+ 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;
}
+ }
+
+ private function decryptWithoutSecret(string $authenticatedCiphertext, string $password = ''): string {
$hmacKey = $encryptionKey = $password;
$parts = explode('|', $authenticatedCiphertext);
diff --git a/lib/private/Security/Hasher.php b/lib/private/Security/Hasher.php
index 5b3fc2b47a9..4731ba96bd3 100644
--- a/lib/private/Security/Hasher.php
+++ b/lib/private/Security/Hasher.php
@@ -137,6 +137,15 @@ class Hasher implements IHasher {
return true;
}
+ // Verify whether it matches a legacy PHPass or SHA1 string
+ // Retry with empty passwordsalt for cases where it was not set
+ $hashLength = \strlen($hash);
+ if (($hashLength === 60 && password_verify($message, $hash)) ||
+ ($hashLength === 40 && hash_equals($hash, sha1($message)))) {
+ $newHash = $this->hash($message);
+ return true;
+ }
+
return false;
}
diff --git a/lib/private/Security/VerificationToken/VerificationToken.php b/lib/private/Security/VerificationToken/VerificationToken.php
index c85e0e7b5a1..2d3f902b622 100644
--- a/lib/private/Security/VerificationToken/VerificationToken.php
+++ b/lib/private/Security/VerificationToken/VerificationToken.php
@@ -84,10 +84,15 @@ class VerificationToken implements IVerificationToken {
try {
$decryptedToken = $this->crypto->decrypt($encryptedToken, $passwordPrefix.$this->config->getSystemValue('secret'));
} catch (\Exception $e) {
- $this->throwInvalidTokenException(InvalidTokenException::TOKEN_DECRYPTION_ERROR);
+ // Retry with empty secret as a fallback for instances where the secret might not have been set by accident
+ try {
+ $decryptedToken = $this->crypto->decrypt($encryptedToken, $passwordPrefix);
+ } catch (\Exception $e2) {
+ $this->throwInvalidTokenException(InvalidTokenException::TOKEN_DECRYPTION_ERROR);
+ }
}
- $splitToken = explode(':', $decryptedToken ?? '');
+ $splitToken = explode(':', $decryptedToken);
if (count($splitToken) !== 2) {
$this->throwInvalidTokenException(InvalidTokenException::TOKEN_INVALID_FORMAT);
}