aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/DirectEditing
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2020-08-25 17:12:27 +0200
committerJulius Härtl <jus@bitgrid.net>2020-09-01 11:40:27 +0200
commite0ae37745a85cb08fd24f178d588a8659726f907 (patch)
tree5c18a0eb72d840639d94a0edb1233b1f59ec00ce /lib/private/DirectEditing
parent823f94bb0118d297df25ca9443e6c235a45bb5ab (diff)
downloadnextcloud-server-e0ae37745a85cb08fd24f178d588a8659726f907.tar.gz
nextcloud-server-e0ae37745a85cb08fd24f178d588a8659726f907.zip
Do not expose direct editing if no master key is available
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/private/DirectEditing')
-rw-r--r--lib/private/DirectEditing/Manager.php35
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php
index c3098fb1a97..3542aeed252 100644
--- a/lib/private/DirectEditing/Manager.php
+++ b/lib/private/DirectEditing/Manager.php
@@ -35,6 +35,7 @@ use OCP\DirectEditing\ACreateFromTemplate;
use OCP\DirectEditing\IEditor;
use \OCP\DirectEditing\IManager;
use OCP\DirectEditing\IToken;
+use OCP\Encryption\IManager as EncryptionManager;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
@@ -45,6 +46,7 @@ use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Security\ISecureRandom;
use OCP\Share\IShare;
+use Throwable;
use function array_key_exists;
use function in_array;
@@ -55,30 +57,33 @@ class Manager implements IManager {
/** @var IEditor[] */
private $editors = [];
-
/** @var IDBConnection */
private $connection;
- /**
- * @var ISecureRandom
- */
+ /** @var ISecureRandom */
private $random;
+ /** @var string|null */
private $userId;
+ /** @var IRootFolder */
private $rootFolder;
/** @var IL10N */
private $l10n;
+ /** @var EncryptionManager */
+ private $encryptionManager;
public function __construct(
ISecureRandom $random,
IDBConnection $connection,
IUserSession $userSession,
IRootFolder $rootFolder,
- IFactory $l10nFactory
+ IFactory $l10nFactory,
+ EncryptionManager $encryptionManager
) {
$this->random = $random;
$this->connection = $connection;
$this->userId = $userSession->getUser() ? $userSession->getUser()->getUID() : null;
$this->rootFolder = $rootFolder;
$this->l10n = $l10nFactory->get('core');
+ $this->encryptionManager = $encryptionManager;
}
public function registerDirectEditor(IEditor $directEditor): void {
@@ -171,7 +176,7 @@ class Manager implements IManager {
}
$editor = $this->getEditor($tokenObject->getEditor());
$this->accessToken($token);
- } catch (\Throwable $throwable) {
+ } catch (Throwable $throwable) {
$this->invalidateToken($token);
return new NotFoundResponse();
}
@@ -275,4 +280,22 @@ class Manager implements IManager {
}
return $files[0];
}
+
+ public function isEnabled(): bool {
+ if (!$this->encryptionManager->isEnabled()) {
+ return true;
+ }
+
+ try {
+ $moduleId = $this->encryptionManager->getDefaultEncryptionModuleId();
+ $module = $this->encryptionManager->getEncryptionModule($moduleId);
+ /** @var \OCA\Encryption\Util $util */
+ $util = \OC::$server->get(\OCA\Encryption\Util::class);
+ if ($module->isReadyForUser($this->userId) && $util->isMasterKeyEnabled()) {
+ return true;
+ }
+ } catch (Throwable $e) {
+ }
+ return false;
+ }
}