diff --git a/appinfo/routes.php b/appinfo/routes.php index 1e7d0e50..0fb07f5f 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -30,6 +30,7 @@ ['name' => 'Key#setPrivateKey', 'url' => '/api/v{apiVersion}/private-key', 'verb' => 'POST', 'requirements' => ['apiVersion' => '[1-2]']], ['name' => 'Key#getPrivateKey', 'url' => '/api/v{apiVersion}/private-key', 'verb' => 'GET', 'requirements' => ['apiVersion' => '[1-2]']], ['name' => 'Key#deletePrivateKey', 'url' => '/api/v{apiVersion}/private-key', 'verb' => 'DELETE', 'requirements' => ['apiVersion' => '[1-2]']], + ['name' => 'Key#setPublicKey', 'url' => '/api/v{apiVersion}/public-key', 'verb' => 'PUT', 'requirements' => ['apiVersion' => '[1-2]']], ['name' => 'Key#createPublicKey', 'url' => '/api/v{apiVersion}/public-key', 'verb' => 'POST', 'requirements' => ['apiVersion' => '[1-2]']], ['name' => 'Key#getPublicKeys', 'url' => '/api/v{apiVersion}/public-key', 'verb' => 'GET', 'requirements' => ['apiVersion' => '[1-2]']], ['name' => 'Key#deletePublicKey', 'url' => '/api/v{apiVersion}/public-key', 'verb' => 'DELETE', 'requirements' => ['apiVersion' => '[1-2]']], diff --git a/lib/Controller/KeyController.php b/lib/Controller/KeyController.php index 6694963f..541bc45c 100644 --- a/lib/Controller/KeyController.php +++ b/lib/Controller/KeyController.php @@ -205,6 +205,26 @@ public function createPublicKey(string $csr): DataResponse { return new DataResponse(['public-key' => $publicKey]); } + /** + * Set public key + * + * @NoAdminRequired + * @E2ERestrictUserAgent + * @throws OCSBadRequestException + */ + public function setPublicKey(string $publicKey): DataResponse { + try { + $this->keyStorage->setPublicKey($publicKey, $this->userId); + } catch (KeyExistsException $e) { + return new DataResponse([], Http::STATUS_CONFLICT); + } catch (Exception $e) { + $this->logger->error("Fail to set user public key", ['exception' => $e, 'app' => $this->appName]); + throw new OCSBadRequestException($this->l10n->t('Internal error')); + } + + return new DataResponse(['public-key' => $publicKey]); + } + /** * Delete the users public key *