|
@@ -101,19 +101,19 @@ discard block |
|
|
block discarded – undo |
|
101
|
101
|
int $type = IToken::TEMPORARY_TOKEN, |
|
102
|
102
|
int $remember = IToken::DO_NOT_REMEMBER): IToken { |
|
103
|
103
|
if (strlen($token) < self::TOKEN_MIN_LENGTH) { |
|
104
|
|
- $exception = new InvalidTokenException('Token is too short, minimum of ' . self::TOKEN_MIN_LENGTH . ' characters is required, ' . strlen($token) . ' characters given'); |
|
|
104
|
+ $exception = new InvalidTokenException('Token is too short, minimum of '.self::TOKEN_MIN_LENGTH.' characters is required, '.strlen($token).' characters given'); |
|
105
|
105
|
$this->logger->error('Invalid token provided when generating new token', ['exception' => $exception]); |
|
106
|
106
|
throw $exception; |
|
107
|
107
|
} |
|
108
|
108
|
|
|
109
|
109
|
if (mb_strlen($name) > 128) { |
|
110
|
|
- $name = mb_substr($name, 0, 120) . '…'; |
|
|
110
|
+ $name = mb_substr($name, 0, 120).'…'; |
|
111
|
111
|
} |
|
112
|
112
|
|
|
113
|
113
|
// We need to check against one old token to see if there is a password |
|
114
|
114
|
// hash that we can reuse for detecting outdated passwords |
|
115
|
115
|
$randomOldToken = $this->mapper->getFirstTokenForUser($uid); |
|
116
|
|
- $oldTokenMatches = $randomOldToken && $this->hasher->verify(sha1($password) . $password, $randomOldToken->getPasswordHash()); |
|
|
116
|
+ $oldTokenMatches = $randomOldToken && $this->hasher->verify(sha1($password).$password, $randomOldToken->getPasswordHash()); |
|
117
|
117
|
|
|
118
|
118
|
$dbToken = $this->newToken($token, $uid, $loginName, $password, $name, $type, $remember); |
|
119
|
119
|
|
|
@@ -160,7 +160,7 @@ discard block |
|
|
block discarded – undo |
|
160
|
160
|
if (isset($this->cache[$tokenHash])) { |
|
161
|
161
|
if ($this->cache[$tokenHash] instanceof DoesNotExistException) { |
|
162
|
162
|
$ex = $this->cache[$tokenHash]; |
|
163
|
|
- throw new InvalidTokenException("Token does not exist: " . $ex->getMessage(), 0, $ex); |
|
|
163
|
+ throw new InvalidTokenException("Token does not exist: ".$ex->getMessage(), 0, $ex); |
|
164
|
164
|
} |
|
165
|
165
|
$token = $this->cache[$tokenHash]; |
|
166
|
166
|
} else { |
|
@@ -174,12 +174,12 @@ discard block |
|
|
block discarded – undo |
|
174
|
174
|
$this->rotate($token, $tokenId, $tokenId); |
|
175
|
175
|
} catch (DoesNotExistException $ex2) { |
|
176
|
176
|
$this->cache[$tokenHash] = $ex2; |
|
177
|
|
- throw new InvalidTokenException("Token does not exist: " . $ex->getMessage(), 0, $ex); |
|
|
177
|
+ throw new InvalidTokenException("Token does not exist: ".$ex->getMessage(), 0, $ex); |
|
178
|
178
|
} |
|
179
|
179
|
} |
|
180
|
180
|
} |
|
181
|
181
|
|
|
182
|
|
- if ((int)$token->getExpires() !== 0 && $token->getExpires() < $this->time->getTime()) { |
|
|
182
|
+ if ((int) $token->getExpires() !== 0 && $token->getExpires() < $this->time->getTime()) { |
|
183
|
183
|
throw new ExpiredTokenException($token); |
|
184
|
184
|
} |
|
185
|
185
|
|
|
@@ -199,10 +199,10 @@ discard block |
|
|
block discarded – undo |
|
199
|
199
|
try { |
|
200
|
200
|
$token = $this->mapper->getTokenById($tokenId); |
|
201
|
201
|
} catch (DoesNotExistException $ex) { |
|
202
|
|
- throw new InvalidTokenException("Token with ID $tokenId does not exist: " . $ex->getMessage(), 0, $ex); |
|
|
202
|
+ throw new InvalidTokenException("Token with ID $tokenId does not exist: ".$ex->getMessage(), 0, $ex); |
|
203
|
203
|
} |
|
204
|
204
|
|
|
205
|
|
- if ((int)$token->getExpires() !== 0 && $token->getExpires() < $this->time->getTime()) { |
|
|
205
|
+ if ((int) $token->getExpires() !== 0 && $token->getExpires() < $this->time->getTime()) { |
|
206
|
206
|
throw new ExpiredTokenException($token); |
|
207
|
207
|
} |
|
208
|
208
|
|
|
@@ -221,7 +221,7 @@ discard block |
|
|
block discarded – undo |
|
221
|
221
|
public function renewSessionToken(string $oldSessionId, string $sessionId): IToken { |
|
222
|
222
|
$this->cache->clear(); |
|
223
|
223
|
|
|
224
|
|
- return $this->atomic(function () use ($oldSessionId, $sessionId) { |
|
|
224
|
+ return $this->atomic(function() use ($oldSessionId, $sessionId) { |
|
225
|
225
|
$token = $this->getToken($oldSessionId); |
|
226
|
226
|
|
|
227
|
227
|
if (!($token instanceof PublicKeyToken)) { |
|
@@ -266,10 +266,10 @@ discard block |
|
|
block discarded – undo |
|
266
|
266
|
$this->cache->clear(); |
|
267
|
267
|
|
|
268
|
268
|
$olderThan = $this->time->getTime() - (int) $this->config->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
269
|
|
- $this->logger->debug('Invalidating session tokens older than ' . date('c', $olderThan), ['app' => 'cron']); |
|
|
269
|
+ $this->logger->debug('Invalidating session tokens older than '.date('c', $olderThan), ['app' => 'cron']); |
|
270
|
270
|
$this->mapper->invalidateOld($olderThan, IToken::DO_NOT_REMEMBER); |
|
271
|
271
|
$rememberThreshold = $this->time->getTime() - (int) $this->config->getSystemValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15); |
|
272
|
|
- $this->logger->debug('Invalidating remembered session tokens older than ' . date('c', $rememberThreshold), ['app' => 'cron']); |
|
|
272
|
+ $this->logger->debug('Invalidating remembered session tokens older than '.date('c', $rememberThreshold), ['app' => 'cron']); |
|
273
|
273
|
$this->mapper->invalidateOld($rememberThreshold, IToken::REMEMBER); |
|
274
|
274
|
} |
|
275
|
275
|
|
|
@@ -342,7 +342,7 @@ discard block |
|
|
block discarded – undo |
|
342
|
342
|
} |
|
343
|
343
|
|
|
344
|
344
|
private function hashPassword(string $password): string { |
|
345
|
|
- return $this->hasher->hash(sha1($password) . $password); |
|
|
345
|
+ return $this->hasher->hash(sha1($password).$password); |
|
346
|
346
|
} |
|
347
|
347
|
|
|
348
|
348
|
public function rotate(IToken $token, string $oldTokenId, string $newTokenId): IToken { |
|
@@ -365,7 +365,7 @@ discard block |
|
|
block discarded – undo |
|
365
|
365
|
|
|
366
|
366
|
private function encrypt(string $plaintext, string $token): string { |
|
367
|
367
|
$secret = $this->config->getSystemValue('secret'); |
|
368
|
|
- return $this->crypto->encrypt($plaintext, $token . $secret); |
|
|
368
|
+ return $this->crypto->encrypt($plaintext, $token.$secret); |
|
369
|
369
|
} |
|
370
|
370
|
|
|
371
|
371
|
/** |
|
@@ -374,7 +374,7 @@ discard block |
|
|
block discarded – undo |
|
374
|
374
|
private function decrypt(string $cipherText, string $token): string { |
|
375
|
375
|
$secret = $this->config->getSystemValue('secret'); |
|
376
|
376
|
try { |
|
377
|
|
- return $this->crypto->decrypt($cipherText, $token . $secret); |
|
|
377
|
+ return $this->crypto->decrypt($cipherText, $token.$secret); |
|
378
|
378
|
} catch (\Exception $ex) { |
|
379
|
379
|
// Retry with empty secret as a fallback for instances where the secret might not have been set by accident |
|
380
|
380
|
try { |
|
@@ -382,7 +382,7 @@ discard block |
|
|
block discarded – undo |
|
382
|
382
|
} catch (\Exception $ex2) { |
|
383
|
383
|
// Delete the invalid token |
|
384
|
384
|
$this->invalidateToken($token); |
|
385
|
|
- throw new InvalidTokenException("Could not decrypt token password: " . $ex->getMessage(), 0, $ex2); |
|
|
385
|
+ throw new InvalidTokenException("Could not decrypt token password: ".$ex->getMessage(), 0, $ex2); |
|
386
|
386
|
} |
|
387
|
387
|
} |
|
388
|
388
|
} |
|
@@ -403,7 +403,7 @@ discard block |
|
|
block discarded – undo |
|
403
|
403
|
|
|
404
|
404
|
private function hashToken(string $token): string { |
|
405
|
405
|
$secret = $this->config->getSystemValue('secret'); |
|
406
|
|
- return hash('sha512', $token . $secret); |
|
|
406
|
+ return hash('sha512', $token.$secret); |
|
407
|
407
|
} |
|
408
|
408
|
|
|
409
|
409
|
/** |
|
@@ -505,7 +505,7 @@ discard block |
|
|
block discarded – undo |
|
505
|
505
|
if (!isset($hashNeedsUpdate[$t->getPasswordHash()])) { |
|
506
|
506
|
if ($t->getPasswordHash() === null) { |
|
507
|
507
|
$hashNeedsUpdate[$t->getPasswordHash() ?: ''] = true; |
|
508
|
|
- } elseif (!$this->hasher->verify(sha1($password) . $password, $t->getPasswordHash())) { |
|
|
508
|
+ } elseif (!$this->hasher->verify(sha1($password).$password, $t->getPasswordHash())) { |
|
509
|
509
|
$hashNeedsUpdate[$t->getPasswordHash() ?: ''] = true; |
|
510
|
510
|
} else { |
|
511
|
511
|
$hashNeedsUpdate[$t->getPasswordHash() ?: ''] = false; |
|
@@ -539,6 +539,6 @@ discard block |
|
|
block discarded – undo |
|
539
|
539
|
while ($error = openssl_error_string()) { |
|
540
|
540
|
$errors[] = $error; |
|
541
|
541
|
} |
|
542
|
|
- $this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors)); |
|
|
542
|
+ $this->logger->critical('Something is wrong with your openssl setup: '.implode(', ', $errors)); |
|
543
|
543
|
} |
|
544
|
544
|
} |