Skip to content

Commit

Permalink
Merge pull request #163 from nextcloud/feature/noid/ocs_ua_check
Browse files Browse the repository at this point in the history
Add Middleware to check whether UA is E2E compatible
  • Loading branch information
georgehrke authored Jul 16, 2020
2 parents d3471e1 + 0bec278 commit 93618dc
Show file tree
Hide file tree
Showing 14 changed files with 2,288 additions and 770 deletions.
30 changes: 15 additions & 15 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@

return [
'ocs' => [
['name' => 'RequestHandler#setPrivateKey', 'url' => '/api/v1/private-key', 'verb' => 'POST'],
['name' => 'RequestHandler#getPrivateKey', 'url' => '/api/v1/private-key', 'verb' => 'GET'],
['name' => 'RequestHandler#deletePrivateKey', 'url' => '/api/v1/private-key', 'verb' => 'DELETE'],
['name' => 'RequestHandler#createPublicKey', 'url' => '/api/v1/public-key', 'verb' => 'POST'],
['name' => 'RequestHandler#getPublicKeys', 'url' => '/api/v1/public-key', 'verb' => 'GET'],
['name' => 'RequestHandler#deletePublicKey', 'url' => '/api/v1/public-key', 'verb' => 'DELETE'],
['name' => 'RequestHandler#getPublicServerKey', 'url' => '/api/v1/server-key', 'verb' => 'GET'],
['name' => 'RequestHandler#setMetaData', 'url' => '/api/v1/meta-data/{id}', 'verb' => 'POST'],
['name' => 'RequestHandler#getMetaData', 'url' => '/api/v1/meta-data/{id}', 'verb' => 'GET'],
['name' => 'RequestHandler#updateMetaData', 'url' => '/api/v1/meta-data/{id}', 'verb' => 'PUT'],
['name' => 'RequestHandler#deleteMetaData', 'url' => '/api/v1/meta-data/{id}', 'verb' => 'DELETE'],
['name' => 'RequestHandler#setEncryptionFlag', 'url' => '/api/v1/encrypted/{id}', 'verb' => 'PUT'],
['name' => 'RequestHandler#removeEncryptionFlag', 'url' => '/api/v1/encrypted/{id}', 'verb' => 'DELETE'],
['name' => 'RequestHandler#lockFolder', 'url' => '/api/v1/lock/{id}', 'verb' => 'POST'],
['name' => 'RequestHandler#unlockFolder', 'url' => '/api/v1/lock/{id}', 'verb' => 'DELETE'],
['name' => 'Key#setPrivateKey', 'url' => '/api/v1/private-key', 'verb' => 'POST'],
['name' => 'Key#getPrivateKey', 'url' => '/api/v1/private-key', 'verb' => 'GET'],
['name' => 'Key#deletePrivateKey', 'url' => '/api/v1/private-key', 'verb' => 'DELETE'],
['name' => 'Key#createPublicKey', 'url' => '/api/v1/public-key', 'verb' => 'POST'],
['name' => 'Key#getPublicKeys', 'url' => '/api/v1/public-key', 'verb' => 'GET'],
['name' => 'Key#deletePublicKey', 'url' => '/api/v1/public-key', 'verb' => 'DELETE'],
['name' => 'Key#getPublicServerKey', 'url' => '/api/v1/server-key', 'verb' => 'GET'],
['name' => 'MetaData#setMetaData', 'url' => '/api/v1/meta-data/{id}', 'verb' => 'POST'],
['name' => 'MetaData#getMetaData', 'url' => '/api/v1/meta-data/{id}', 'verb' => 'GET'],
['name' => 'MetaData#updateMetaData', 'url' => '/api/v1/meta-data/{id}', 'verb' => 'PUT'],
['name' => 'MetaData#deleteMetaData', 'url' => '/api/v1/meta-data/{id}', 'verb' => 'DELETE'],
['name' => 'Encryption#setEncryptionFlag', 'url' => '/api/v1/encrypted/{id}', 'verb' => 'PUT'],
['name' => 'Encryption#removeEncryptionFlag', 'url' => '/api/v1/encrypted/{id}', 'verb' => 'DELETE'],
['name' => 'Locking#lockFolder', 'url' => '/api/v1/lock/{id}', 'verb' => 'POST'],
['name' => 'Locking#unlockFolder', 'url' => '/api/v1/lock/{id}', 'verb' => 'DELETE'],
],
];
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCA\EndToEndEncryption\IMetaDataStorage;
use OCA\EndToEndEncryption\KeyStorage;
use OCA\EndToEndEncryption\MetaDataStorage;
use OCA\EndToEndEncryption\Middleware\UserAgentCheckMiddleware;
use OCA\EndToEndEncryption\UserManager;
use OCA\Files_Trashbin\Events\MoveToTrashEvent;
use OCA\Files_Versions\Events\CreateVersionEvent;
Expand All @@ -55,6 +56,7 @@ public function __construct(array $urlParams = []) {
$container->registerAlias(IMetaDataStorage::class, MetaDataStorage::class);

$container->registerCapability(Capabilities::class);
$container->registerMiddleWare(UserAgentCheckMiddleware::class);
}

public function registerEvents():void {
Expand Down
132 changes: 132 additions & 0 deletions lib/Controller/EncryptionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

declare(strict_types=1);
/**
* SPDX-License-Identifier: AGPL-3.0+
*
* @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
* @copyright Copyright (c) 2020 Georg Ehrke <georg-nextcloud@ehrke.email>
*
* @author Bjoern Schiessle <bjoern@schiessle.org>
* @author Georg Ehrke <georg-nextcloud@ehrke.email>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\EndToEndEncryption\Controller;

use OCA\EndToEndEncryption\EncryptionManager;
use OCA\EndToEndEncryption\IMetaDataStorage;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\Files\NotFoundException;
use OCP\ILogger;
use OCP\IRequest;

/**
* Class EncryptionController
*
* @package OCA\EndToEndEncryption\Controller
*/
class EncryptionController extends OCSController {

/** @var string */
private $userId;

/** @var IMetaDataStorage */
private $metaDataStorage;

/** @var EncryptionManager */
private $manager;

/** @var ILogger */
private $logger;

/**
* RequestHandlerController constructor.
*
* @param string $AppName
* @param IRequest $request
* @param string $userId
* @param IMetaDataStorage $metaDataStorage
* @param EncryptionManager $manager
* @param ILogger $logger
*/
public function __construct($AppName,
IRequest $request,
$userId,
IMetaDataStorage $metaDataStorage,
EncryptionManager $manager,
ILogger $logger) {
parent::__construct($AppName, $request);
$this->userId = $userId;
$this->metaDataStorage = $metaDataStorage;
$this->manager = $manager;
$this->logger = $logger;
}

/**
* @NoAdminRequired
* @E2ERestrictUserAgent
*
* set encryption flag for folder
*
*
* @param int $id file ID
* @return DataResponse
*
* @throws OCSNotFoundException
*/
public function setEncryptionFlag(int $id): DataResponse {
try {
$this->manager->setEncryptionFlag($id);
} catch (NotFoundException $e) {
throw new OCSNotFoundException($e->getMessage());
}

return new DataResponse();
}

/**
* @NoAdminRequired
* @E2ERestrictUserAgent
*
* set encryption flag for folder
*
*
* @param int $id file ID
* @return DataResponse
*
* @throws OCSNotFoundException
*/
public function removeEncryptionFlag(int $id): DataResponse {
try {
$this->manager->removeEncryptionFlag($id);
} catch (NotFoundException $e) {
throw new OCSNotFoundException($e->getMessage());
}

try {
$this->metaDataStorage->deleteMetaData($this->userId, $id);
} catch (\Exception $e) {
$this->logger->logException($e, ['app' => $this->appName]);
}

return new DataResponse();
}
}
Loading

0 comments on commit 93618dc

Please sign in to comment.