Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
pull/9485/head
Roeland Jago Douma 7 years ago
parent 970dea9264
commit 82959ca93e
No known key found for this signature in database
GPG Key ID: F941078878347C0C
  1. 3
      lib/private/Authentication/Token/DefaultTokenProvider.php
  2. 17
      lib/private/Authentication/Token/Manager.php
  3. 3
      lib/private/Authentication/Token/PublicKeyToken.php
  4. 2
      lib/private/Authentication/Token/PublicKeyTokenMapper.php
  5. 1
      lib/private/Authentication/Token/PublicKeyTokenProvider.php

@ -35,7 +35,6 @@ use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
use OCP\Security\ICrypto;
class DefaultTokenProvider implements IProvider {
@ -299,7 +298,7 @@ class DefaultTokenProvider implements IProvider {
* @param string $token
* @return string
*/
private function hashToken(string $token) {
private function hashToken(string $token): string {
$secret = $this->config->getSystemValue('secret');
return hash('sha512', $token . $secret);
}

@ -25,7 +25,6 @@ namespace OC\Authentication\Token;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Exceptions\PasswordlessTokenException;
use OCP\IUser;
class Manager implements IProvider {
@ -92,6 +91,10 @@ class Manager implements IProvider {
$provider->updateTokenActivity($token);
}
/**
* @param string $uid
* @return IToken[]
*/
public function getTokenByUser(string $uid): array {
$old = $this->defaultTokenProvider->getTokenByUser($uid);
$new = $this->publicKeyTokenProvider->getTokenByUser($uid);
@ -185,6 +188,13 @@ class Manager implements IProvider {
$this->publicKeyTokenProvider->invalidateOldTokens();
}
/**
* @param IToken $token
* @param string $oldTokenId
* @param string $newTokenId
* @return IToken
* @throws InvalidTokenException
*/
public function rotate(IToken $token, string $oldTokenId, string $newTokenId): IToken {
if ($token instanceof DefaultToken) {
try {
@ -203,6 +213,11 @@ class Manager implements IProvider {
throw new InvalidTokenException();
}
/**
* @param IToken $token
* @return IProvider
* @throws InvalidTokenException
*/
private function getProvider(IToken $token): IProvider {
if ($token instanceof DefaultToken) {
return $this->defaultTokenProvider;

@ -1,4 +1,5 @@
<?php
/** @noinspection ALL */
declare(strict_types=1);
/**
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
@ -180,7 +181,7 @@ class PublicKeyToken extends Entity implements IToken {
}
public function setScope($scope) {
if (\is_array($scope)) {
if (is_array($scope)) {
parent::setScope(json_encode($scope));
} else {
parent::setScope((string)$scope);

@ -115,7 +115,7 @@ class PublicKeyTokenMapper extends QBMapper {
* where a high number of (session) tokens is generated
*
* @param string $uid
* @return DefaultToken[]
* @return PublicKeyToken[]
*/
public function getTokenByUser(string $uid): array {
/* @var $qb IQueryBuilder */

@ -29,7 +29,6 @@ use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
use OCP\Security\ICrypto;
class PublicKeyTokenProvider implements IProvider {

Loading…
Cancel
Save