Skip to content

Commit

Permalink
add a new API to allow user to upload an existing certificate
Browse files Browse the repository at this point in the history
is needed to be able to setup sharing when an user has an existing
certificate that may have been created outside of Nextcloud end-to-end
encryption app

that would for example apply when an external certificate authority is
in use to deliver user certificates for end-to-end encryption

Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Jul 31, 2024
1 parent e43a699 commit b9a70c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]']],
Expand Down
20 changes: 20 additions & 0 deletions lib/Controller/KeyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit b9a70c8

Please sign in to comment.