aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-06-02 16:42:32 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-06-02 16:42:32 +0200
commit259937680b79044701331eed8bff98e3acd12e6c (patch)
tree0f084e5e9d6c62042c6a9fd624e8dbda33ca5b27 /lib
parent3ebc8f0564395fbb519fc4275e0f6f883df708b7 (diff)
parentbe1f319511b3faaf4552ec68a6697b4dda1f5c6c (diff)
downloadnextcloud-server-259937680b79044701331eed8bff98e3acd12e6c.tar.gz
nextcloud-server-259937680b79044701331eed8bff98e3acd12e6c.zip
Merge pull request #16667 from owncloud/issue-16510-fix-encryption-with-s2s-shares
Add tests for the storage wrapper and fix the wrapping
Diffstat (limited to 'lib')
-rw-r--r--lib/private/encryption/manager.php53
-rw-r--r--lib/private/encryption/util.php51
2 files changed, 61 insertions, 43 deletions
diff --git a/lib/private/encryption/manager.php b/lib/private/encryption/manager.php
index ecbb86993ec..eeddea26b1a 100644
--- a/lib/private/encryption/manager.php
+++ b/lib/private/encryption/manager.php
@@ -208,49 +208,16 @@ class Manager implements IManager {
return $this->config->getAppValue('core', 'default_encryption_module');
}
+ /**
+ * Add storage wrapper
+ */
public static function setupStorage() {
- \OC\Files\Filesystem::addStorageWrapper('oc_encryption', function ($mountPoint, $storage, IMountPoint $mount) {
- $parameters = [
- 'storage' => $storage,
- 'mountPoint' => $mountPoint,
- 'mount' => $mount];
-
- if (!($storage instanceof Shared)) {
- $manager = \OC::$server->getEncryptionManager();
- $util = new Util(
- new View(),
- \OC::$server->getUserManager(),
- \OC::$server->getGroupManager(),
- \OC::$server->getConfig()
- );
- $user = \OC::$server->getUserSession()->getUser();
- $logger = \OC::$server->getLogger();
- $mountManager = Filesystem::getMountManager();
- $uid = $user ? $user->getUID() : null;
- $fileHelper = \OC::$server->getEncryptionFilesHelper();
- $keyStorage = \OC::$server->getEncryptionKeyStorage();
- $update = new Update(
- new View(),
- $util,
- Filesystem::getMountManager(),
- $manager,
- $fileHelper,
- $uid
- );
- return new Encryption(
- $parameters,
- $manager,
- $util,
- $logger,
- $fileHelper,
- $uid,
- $keyStorage,
- $update,
- $mountManager
- );
- } else {
- return $storage;
- }
- }, 2);
+ $util = new Util(
+ new View(),
+ \OC::$server->getUserManager(),
+ \OC::$server->getGroupManager(),
+ \OC::$server->getConfig()
+ );
+ \OC\Files\Filesystem::addStorageWrapper('oc_encryption', array($util, 'wrapStorage'), 2);
}
}
diff --git a/lib/private/encryption/util.php b/lib/private/encryption/util.php
index b77672d2f6b..80499249561 100644
--- a/lib/private/encryption/util.php
+++ b/lib/private/encryption/util.php
@@ -26,8 +26,11 @@ use OC\Encryption\Exceptions\EncryptionHeaderKeyExistsException;
use OC\Encryption\Exceptions\EncryptionHeaderToLargeException;
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
use OC\Files\Filesystem;
+use OC\Files\Storage\Wrapper\Encryption;
use OC\Files\View;
use OCP\Encryption\IEncryptionModule;
+use OCP\Files\Mount\IMountPoint;
+use OCP\Files\Storage;
use OCP\IConfig;
class Util {
@@ -386,4 +389,52 @@ class Util {
return ($enabled === '1') ? true : false;
}
+ /**
+ * Wraps the given storage when it is not a shared storage
+ *
+ * @param string $mountPoint
+ * @param Storage $storage
+ * @param IMountPoint $mount
+ * @return Encryption|Storage
+ */
+ public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) {
+ $parameters = [
+ 'storage' => $storage,
+ 'mountPoint' => $mountPoint,
+ 'mount' => $mount];
+
+ if (!$storage->instanceOfStorage('OC\Files\Storage\Shared')
+ && !$storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')
+ && !$storage->instanceOfStorage('OC\Files\Storage\OwnCloud')) {
+
+ $manager = \OC::$server->getEncryptionManager();
+ $user = \OC::$server->getUserSession()->getUser();
+ $logger = \OC::$server->getLogger();
+ $mountManager = Filesystem::getMountManager();
+ $uid = $user ? $user->getUID() : null;
+ $fileHelper = \OC::$server->getEncryptionFilesHelper();
+ $keyStorage = \OC::$server->getEncryptionKeyStorage();
+ $update = new Update(
+ new View(),
+ $this,
+ Filesystem::getMountManager(),
+ $manager,
+ $fileHelper,
+ $uid
+ );
+ return new Encryption(
+ $parameters,
+ $manager,
+ $this,
+ $logger,
+ $fileHelper,
+ $uid,
+ $keyStorage,
+ $update,
+ $mountManager
+ );
+ } else {
+ return $storage;
+ }
+ }
}