summaryrefslogtreecommitdiffstats
path: root/lib/private/encryption
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2016-03-30 23:20:37 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2016-03-31 19:24:47 +0200
commit93ed965cbb1952faafc1ca5e09ee0de84d122c05 (patch)
tree2631e5302305b9b59b25b006edca19650ca2a1bc /lib/private/encryption
parent8ef6c6c7bcf0b58561aee6ec1a18ea7a8643a773 (diff)
downloadnextcloud-server-93ed965cbb1952faafc1ca5e09ee0de84d122c05.tar.gz
nextcloud-server-93ed965cbb1952faafc1ca5e09ee0de84d122c05.zip
fix creation of versions of encrypted files on external storages
in order to create a 1:1 copy of a file if a version gets created we need to store this information on copyBetweenStorage(). This allows us to by-pass the encryption wrapper if we read the source file.
Diffstat (limited to 'lib/private/encryption')
-rw-r--r--lib/private/encryption/encryptionwrapper.php124
-rw-r--r--lib/private/encryption/manager.php19
-rw-r--r--lib/private/encryption/util.php50
3 files changed, 134 insertions, 59 deletions
diff --git a/lib/private/encryption/encryptionwrapper.php b/lib/private/encryption/encryptionwrapper.php
new file mode 100644
index 00000000000..11beb0cd6b1
--- /dev/null
+++ b/lib/private/encryption/encryptionwrapper.php
@@ -0,0 +1,124 @@
+<?php
+/**
+ * @author Björn Schießle <schiessle@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+
+namespace OC\Encryption;
+
+
+use OC\Memcache\ArrayCache;
+use OC\Files\Filesystem;
+use OC\Files\Storage\Wrapper\Encryption;
+use OCP\Files\Mount\IMountPoint;
+use OC\Files\View;
+use OCP\Files\Storage;
+use OCP\ILogger;
+
+/**
+ * Class EncryptionWrapper
+ *
+ * applies the encryption storage wrapper
+ *
+ * @package OC\Encryption
+ */
+class EncryptionWrapper {
+
+ /** @var ArrayCache */
+ private $arrayCache;
+
+ /** @var Manager */
+ private $manager;
+
+ /** @var ILogger */
+ private $logger;
+
+ /**
+ * EncryptionWrapper constructor.
+ *
+ * @param ArrayCache $arrayCache
+ * @param Manager $manager
+ * @param ILogger $logger
+ */
+ public function __construct(ArrayCache $arrayCache,
+ Manager $manager,
+ ILogger $logger
+ ) {
+ $this->arrayCache = $arrayCache;
+ $this->manager = $manager;
+ $this->logger = $logger;
+ }
+
+ /**
+ * 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')) {
+
+ $user = \OC::$server->getUserSession()->getUser();
+ $mountManager = Filesystem::getMountManager();
+ $uid = $user ? $user->getUID() : null;
+ $fileHelper = \OC::$server->getEncryptionFilesHelper();
+ $keyStorage = \OC::$server->getEncryptionKeyStorage();
+
+ $util = new Util(
+ new View(),
+ \OC::$server->getUserManager(),
+ \OC::$server->getGroupManager(),
+ \OC::$server->getConfig()
+ );
+ $update = new Update(
+ new View(),
+ $util,
+ Filesystem::getMountManager(),
+ $this->manager,
+ $fileHelper,
+ $uid
+ );
+ return new Encryption(
+ $parameters,
+ $this->manager,
+ $util,
+ $this->logger,
+ $fileHelper,
+ $uid,
+ $keyStorage,
+ $update,
+ $mountManager,
+ $this->arrayCache
+ );
+ } else {
+ return $storage;
+ }
+ }
+
+}
diff --git a/lib/private/encryption/manager.php b/lib/private/encryption/manager.php
index d1d17a92887..d45bbf07ee9 100644
--- a/lib/private/encryption/manager.php
+++ b/lib/private/encryption/manager.php
@@ -27,6 +27,7 @@ namespace OC\Encryption;
use OC\Encryption\Keys\Storage;
use OC\Files\Filesystem;
use OC\Files\View;
+use OC\Memcache\ArrayCache;
use OC\ServiceUnavailableException;
use OCP\Encryption\IEncryptionModule;
use OCP\Encryption\IManager;
@@ -54,20 +55,25 @@ class Manager implements IManager {
/** @var Util */
protected $util;
+ /** @var ArrayCache */
+ protected $arrayCache;
+
/**
* @param IConfig $config
* @param ILogger $logger
* @param IL10N $l10n
* @param View $rootView
* @param Util $util
+ * @param ArrayCache $arrayCache
*/
- public function __construct(IConfig $config, ILogger $logger, IL10N $l10n, View $rootView, Util $util) {
+ public function __construct(IConfig $config, ILogger $logger, IL10N $l10n, View $rootView, Util $util, ArrayCache $arrayCache) {
$this->encryptionModules = array();
$this->config = $config;
$this->logger = $logger;
$this->l = $l10n;
$this->rootView = $rootView;
$this->util = $util;
+ $this->arrayCache = $arrayCache;
}
/**
@@ -227,14 +233,9 @@ class Manager implements IManager {
/**
* Add storage wrapper
*/
- public static function setupStorage() {
- $util = new Util(
- new View(),
- \OC::$server->getUserManager(),
- \OC::$server->getGroupManager(),
- \OC::$server->getConfig()
- );
- Filesystem::addStorageWrapper('oc_encryption', array($util, 'wrapStorage'), 2);
+ public function setupStorage() {
+ $encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger);
+ Filesystem::addStorageWrapper('oc_encryption', array($encryptionWrapper, 'wrapStorage'), 2);
}
diff --git a/lib/private/encryption/util.php b/lib/private/encryption/util.php
index 860c541934a..9e0cfca830d 100644
--- a/lib/private/encryption/util.php
+++ b/lib/private/encryption/util.php
@@ -28,10 +28,8 @@ 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;
@@ -392,52 +390,4 @@ class Util {
return $this->config->getAppValue('core', 'encryption_key_storage_root', '');
}
- /**
- * 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;
- }
- }
}