aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Authentication
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2022-03-09 10:52:27 +0100
committerJulius Härtl <jus@bitgrid.net>2022-03-10 14:01:21 +0100
commit81f8719cc0fdc2fc25a00ac1412ffc63cd62eabf (patch)
tree29a00c4a12ae2e27d7514dfbcb85cd54c1618b71 /lib/private/Authentication
parent0825c3ea34675b12bf14dc00354e0ab1c77ecf11 (diff)
downloadnextcloud-server-81f8719cc0fdc2fc25a00ac1412ffc63cd62eabf.tar.gz
nextcloud-server-81f8719cc0fdc2fc25a00ac1412ffc63cd62eabf.zip
Add fallback routines for empty secret cases
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/private/Authentication')
-rw-r--r--lib/private/Authentication/Token/PublicKeyTokenProvider.php19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/private/Authentication/Token/PublicKeyTokenProvider.php b/lib/private/Authentication/Token/PublicKeyTokenProvider.php
index d2ee47cf380..7f360b90b23 100644
--- a/lib/private/Authentication/Token/PublicKeyTokenProvider.php
+++ b/lib/private/Authentication/Token/PublicKeyTokenProvider.php
@@ -185,6 +185,7 @@ class PublicKeyTokenProvider implements IProvider {
$this->cache->clear();
$this->mapper->invalidate($this->hashToken($token));
+ $this->mapper->invalidate($this->hashTokenWithEmptySecret($token));
}
public function invalidateTokenById(string $uid, int $id) {
@@ -301,9 +302,14 @@ class PublicKeyTokenProvider implements IProvider {
try {
return $this->crypto->decrypt($cipherText, $token . $secret);
} catch (\Exception $ex) {
- // Delete the invalid token
- $this->invalidateToken($token);
- throw new InvalidTokenException("Could not decrypt token password: " . $ex->getMessage(), 0, $ex);
+ // Retry with empty secret as a fallback for instances where the secret might not have been set by accident
+ try {
+ return $this->crypto->decrypt($cipherText, $token);
+ } catch (\Exception $ex2) {
+ // Delete the invalid token
+ $this->invalidateToken($token);
+ throw new InvalidTokenException("Could not decrypt token password: " . $ex->getMessage(), 0, $ex2);
+ }
}
}
@@ -327,6 +333,13 @@ class PublicKeyTokenProvider implements IProvider {
}
/**
+ * @depreacted Fallback for instances where the secret might not have been set by accident
+ */
+ private function hashTokenWithEmptySecret(string $token): string {
+ return hash('sha512', $token);
+ }
+
+ /**
* @throws \RuntimeException when OpenSSL reports a problem
*/
private function newToken(string $token,