summaryrefslogtreecommitdiffstats
path: root/lib/private/Authentication/Token/PublicKeyTokenProvider.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Authentication/Token/PublicKeyTokenProvider.php')
-rw-r--r--lib/private/Authentication/Token/PublicKeyTokenProvider.php55
1 files changed, 32 insertions, 23 deletions
diff --git a/lib/private/Authentication/Token/PublicKeyTokenProvider.php b/lib/private/Authentication/Token/PublicKeyTokenProvider.php
index 0f1767e845b..249f9bd411f 100644
--- a/lib/private/Authentication/Token/PublicKeyTokenProvider.php
+++ b/lib/private/Authentication/Token/PublicKeyTokenProvider.php
@@ -34,14 +34,18 @@ use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Exceptions\TokenPasswordExpiredException;
use OC\Authentication\Exceptions\PasswordlessTokenException;
use OC\Authentication\Exceptions\WipeTokenException;
+use OCP\AppFramework\Db\TTransactional;
use OCP\Cache\CappedMemoryCache;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\Security\ICrypto;
use Psr\Log\LoggerInterface;
class PublicKeyTokenProvider implements IProvider {
+ use TTransactional;
+
/** @var PublicKeyTokenMapper */
private $mapper;
@@ -51,6 +55,8 @@ class PublicKeyTokenProvider implements IProvider {
/** @var IConfig */
private $config;
+ private IDBConnection $db;
+
/** @var LoggerInterface */
private $logger;
@@ -63,11 +69,13 @@ class PublicKeyTokenProvider implements IProvider {
public function __construct(PublicKeyTokenMapper $mapper,
ICrypto $crypto,
IConfig $config,
+ IDBConnection $db,
LoggerInterface $logger,
ITimeFactory $time) {
$this->mapper = $mapper;
$this->crypto = $crypto;
$this->config = $config;
+ $this->db = $db;
$this->logger = $logger;
$this->time = $time;
@@ -158,31 +166,32 @@ class PublicKeyTokenProvider implements IProvider {
public function renewSessionToken(string $oldSessionId, string $sessionId): IToken {
$this->cache->clear();
- $token = $this->getToken($oldSessionId);
-
- if (!($token instanceof PublicKeyToken)) {
- throw new InvalidTokenException("Invalid token type");
- }
+ return $this->atomic(function () use ($oldSessionId, $sessionId) {
+ $token = $this->getToken($oldSessionId);
- $password = null;
- if (!is_null($token->getPassword())) {
- $privateKey = $this->decrypt($token->getPrivateKey(), $oldSessionId);
- $password = $this->decryptPassword($token->getPassword(), $privateKey);
- }
-
- $newToken = $this->generateToken(
- $sessionId,
- $token->getUID(),
- $token->getLoginName(),
- $password,
- $token->getName(),
- IToken::TEMPORARY_TOKEN,
- $token->getRemember()
- );
-
- $this->mapper->delete($token);
+ if (!($token instanceof PublicKeyToken)) {
+ throw new InvalidTokenException("Invalid token type");
+ }
- return $newToken;
+ $password = null;
+ if (!is_null($token->getPassword())) {
+ $privateKey = $this->decrypt($token->getPrivateKey(), $oldSessionId);
+ $password = $this->decryptPassword($token->getPassword(), $privateKey);
+ }
+ $newToken = $this->generateToken(
+ $sessionId,
+ $token->getUID(),
+ $token->getLoginName(),
+ $password,
+ $token->getName(),
+ IToken::TEMPORARY_TOKEN,
+ $token->getRemember()
+ );
+
+ $this->mapper->delete($token);
+
+ return $newToken;
+ }, $this->db);
}
public function invalidateToken(string $token) {