Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/Controller/KeyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
Expand Down Expand Up @@ -185,20 +186,23 @@ public function createPublicKey(string $csr): DataResponse {

try {
$subject = openssl_csr_get_subject($csr);

$cn = isset($subject['CN']) ? $subject['CN'] : '';
if ($cn !== $this->userId) {
throw new OCSForbiddenException($this->l10n->t('Common name (CN) does not match the current user'));
}

$publicKey = $this->signatureHandler->sign($csr);
} catch (BadMethodCallException $e) {
$this->logger->critical($e->getMessage(), ['exception' => $e, 'app' => $this->appName]);
throw new OCSBadRequestException($e->getMessage());
} catch (OCSException $e) {
throw $e;
} catch (Exception $e) {
$this->logger->critical($e->getMessage(), ['exception' => $e, 'app' => $this->appName]);
throw new OCSBadRequestException($this->l10n->t('Internal error'));
}

$cn = isset($subject['CN']) ? $subject['CN'] : '';
if ($cn !== $this->userId) {
throw new OCSForbiddenException($this->l10n->t('Common name (CN) does not match the current user'));
}

$this->keyStorage->setPublicKey($publicKey, $this->userId);

return new DataResponse(['public-key' => $publicKey]);
Expand Down
Loading