summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-04-22 16:04:29 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-04-22 16:04:29 +0200
commit750f0bc4896dcc35695e535ae826da353d265daf (patch)
treefb3b557b9ef296277597fb49f7b9122e84583423 /lib
parent42d9ba0f83f3e4b1d0eaa4aa60cddc89f239dda7 (diff)
parent0042bdd2e758f8b514acc86c3c72c3b1e5f5911b (diff)
downloadnextcloud-server-750f0bc4896dcc35695e535ae826da353d265daf.tar.gz
nextcloud-server-750f0bc4896dcc35695e535ae826da353d265daf.zip
Merge pull request #15799 from owncloud/fix-enc-folder-move
Fix enc folder move
Diffstat (limited to 'lib')
-rw-r--r--lib/private/encryption/keys/factory.php50
-rw-r--r--lib/private/encryption/keys/storage.php143
-rw-r--r--lib/private/encryption/manager.php3
-rw-r--r--lib/private/files/storage/wrapper/encryption.php30
-rw-r--r--lib/private/server.php25
-rw-r--r--lib/public/encryption/keys/istorage.php33
-rw-r--r--lib/public/iservercontainer.php4
7 files changed, 94 insertions, 194 deletions
diff --git a/lib/private/encryption/keys/factory.php b/lib/private/encryption/keys/factory.php
deleted file mode 100644
index 0e2b0292a68..00000000000
--- a/lib/private/encryption/keys/factory.php
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-/**
- * @author Björn Schießle <schiessle@owncloud.com>
- *
- * @copyright Copyright (c) 2015, 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\Keys;
-
-use OC\Encryption\Util;
-use OC\Files\View;
-use OC\User;
-
-/**
- * Factory provides KeyStorage for different encryption modules
- */
-class Factory {
- /** @var array */
- protected $instances = array();
-
- /**
- * get a KeyStorage instance
- *
- * @param string $encryptionModuleId
- * @param View $view
- * @param Util $util
- * @return Storage
- */
- public function get($encryptionModuleId,View $view, Util $util) {
- if (!isset($this->instances[$encryptionModuleId])) {
- $this->instances[$encryptionModuleId] = new Storage($encryptionModuleId, $view, $util);
- }
- return $this->instances[$encryptionModuleId];
- }
-
-}
diff --git a/lib/private/encryption/keys/storage.php b/lib/private/encryption/keys/storage.php
index 925c20c74c8..e34d7370ef1 100644
--- a/lib/private/encryption/keys/storage.php
+++ b/lib/private/encryption/keys/storage.php
@@ -23,10 +23,12 @@
namespace OC\Encryption\Keys;
use OC\Encryption\Util;
+use OC\Files\Filesystem;
use OC\Files\View;
use OCP\Encryption\Exceptions\GenericEncryptionException;
+use OCP\Encryption\Keys\IStorage;
-class Storage implements \OCP\Encryption\Keys\IStorage {
+class Storage implements IStorage {
/** @var View */
private $view;
@@ -35,171 +37,123 @@ class Storage implements \OCP\Encryption\Keys\IStorage {
private $util;
// base dir where all the file related keys are stored
+ /** @var string */
private $keys_base_dir;
- private $encryption_base_dir;
-
- private $keyCache = array();
/** @var string */
- private $encryptionModuleId;
+ private $encryption_base_dir;
+
+ /** @var array */
+ private $keyCache = [];
/**
- * @param string $encryptionModuleId
* @param View $view
* @param Util $util
*/
- public function __construct($encryptionModuleId, View $view, Util $util) {
+ public function __construct(View $view, Util $util) {
$this->view = $view;
$this->util = $util;
- $this->encryptionModuleId = $encryptionModuleId;
$this->encryption_base_dir = '/files_encryption';
$this->keys_base_dir = $this->encryption_base_dir .'/keys';
}
/**
- * get user specific key
- *
- * @param string $uid ID if the user for whom we want the key
- * @param string $keyId id of the key
- *
- * @return mixed key
+ * @inheritdoc
*/
- public function getUserKey($uid, $keyId) {
- $path = $this->constructUserKeyPath($keyId, $uid);
+ public function getUserKey($uid, $keyId, $encryptionModuleId) {
+ $path = $this->constructUserKeyPath($encryptionModuleId, $keyId, $uid);
return $this->getKey($path);
}
/**
- * get file specific key
- *
- * @param string $path path to file
- * @param string $keyId id of the key
- *
- * @return mixed key
+ * @inheritdoc
*/
- public function getFileKey($path, $keyId) {
- $keyDir = $this->getFileKeyDir($path);
+ public function getFileKey($path, $keyId, $encryptionModuleId) {
+ $keyDir = $this->getFileKeyDir($encryptionModuleId, $path);
return $this->getKey($keyDir . $keyId);
}
/**
- * get system-wide encryption keys not related to a specific user,
- * e.g something like a key for public link shares
- *
- * @param string $keyId id of the key
- *
- * @return mixed key
+ * @inheritdoc
*/
- public function getSystemUserKey($keyId) {
- $path = $this->constructUserKeyPath($keyId);
+ public function getSystemUserKey($keyId, $encryptionModuleId) {
+ $path = $this->constructUserKeyPath($encryptionModuleId, $keyId, null);
return $this->getKey($path);
}
/**
- * set user specific key
- *
- * @param string $uid ID if the user for whom we want the key
- * @param string $keyId id of the key
- * @param mixed $key
+ * @inheritdoc
*/
- public function setUserKey($uid, $keyId, $key) {
- $path = $this->constructUserKeyPath($keyId, $uid);
+ public function setUserKey($uid, $keyId, $key, $encryptionModuleId) {
+ $path = $this->constructUserKeyPath($encryptionModuleId, $keyId, $uid);
return $this->setKey($path, $key);
}
/**
- * set file specific key
- *
- * @param string $path path to file
- * @param string $keyId id of the key
- * @param boolean
+ * @inheritdoc
*/
- public function setFileKey($path, $keyId, $key) {
- $keyDir = $this->getFileKeyDir($path);
+ public function setFileKey($path, $keyId, $key, $encryptionModuleId) {
+ $keyDir = $this->getFileKeyDir($encryptionModuleId, $path);
return $this->setKey($keyDir . $keyId, $key);
}
/**
- * set system-wide encryption keys not related to a specific user,
- * e.g something like a key for public link shares
- *
- * @param string $keyId id of the key
- * @param mixed $key
- *
- * @return mixed key
+ * @inheritdoc
*/
- public function setSystemUserKey($keyId, $key) {
- $path = $this->constructUserKeyPath($keyId);
+ public function setSystemUserKey($keyId, $key, $encryptionModuleId) {
+ $path = $this->constructUserKeyPath($encryptionModuleId, $keyId, null);
return $this->setKey($path, $key);
}
/**
- * delete user specific key
- *
- * @param string $uid ID if the user for whom we want to delete the key
- * @param string $keyId id of the key
- *
- * @return boolean False when the key could not be deleted
+ * @inheritdoc
*/
- public function deleteUserKey($uid, $keyId) {
- $path = $this->constructUserKeyPath($keyId, $uid);
+ public function deleteUserKey($uid, $keyId, $encryptionModuleId) {
+ $path = $this->constructUserKeyPath($encryptionModuleId, $keyId, $uid);
return !$this->view->file_exists($path) || $this->view->unlink($path);
}
/**
- * delete file specific key
- *
- * @param string $path path to file
- * @param string $keyId id of the key
- *
- * @return boolean False when the key could not be deleted
+ * @inheritdoc
*/
- public function deleteFileKey($path, $keyId) {
- $keyDir = $this->getFileKeyDir($path);
+ public function deleteFileKey($path, $keyId, $encryptionModuleId) {
+ $keyDir = $this->getFileKeyDir($encryptionModuleId, $path);
return !$this->view->file_exists($keyDir . $keyId) || $this->view->unlink($keyDir . $keyId);
}
/**
- * delete all file keys for a given file
- *
- * @param string $path to the file
- * @return boolean False when the key could not be deleted
+ * @inheritdoc
*/
- public function deleteAllFileKeys($path) {
- $keyDir = $this->getFileKeyDir($path);
+ public function deleteAllFileKeys($path, $encryptionModuleId) {
+ $keyDir = $this->getFileKeyDir($encryptionModuleId, $path);
$path = dirname($keyDir);
return !$this->view->file_exists($path) || $this->view->deleteAll($path);
}
/**
- * delete system-wide encryption keys not related to a specific user,
- * e.g something like a key for public link shares
- *
- * @param string $keyId id of the key
- *
- * @return boolean False when the key could not be deleted
+ * @inheritdoc
*/
- public function deleteSystemUserKey($keyId) {
- $path = $this->constructUserKeyPath($keyId);
+ public function deleteSystemUserKey($keyId, $encryptionModuleId) {
+ $path = $this->constructUserKeyPath($encryptionModuleId, $keyId, null);
return !$this->view->file_exists($path) || $this->view->unlink($path);
}
-
/**
* construct path to users key
*
+ * @param string $encryptionModuleId
* @param string $keyId
* @param string $uid
* @return string
*/
- protected function constructUserKeyPath($keyId, $uid = null) {
+ protected function constructUserKeyPath($encryptionModuleId, $keyId, $uid) {
if ($uid === null) {
- $path = $this->encryption_base_dir . '/' . $this->encryptionModuleId . '/' . $keyId;
+ $path = $this->encryption_base_dir . '/' . $encryptionModuleId . '/' . $keyId;
} else {
$path = '/' . $uid . $this->encryption_base_dir . '/'
- . $this->encryptionModuleId . '/' . $uid . '.' . $keyId;
+ . $encryptionModuleId . '/' . $uid . '.' . $keyId;
}
return $path;
@@ -251,12 +205,13 @@ class Storage implements \OCP\Encryption\Keys\IStorage {
/**
* get path to key folder for a given file
*
+ * @param string $encryptionModuleId
* @param string $path path to the file, relative to data/
* @return string
* @throws GenericEncryptionException
* @internal param string $keyId
*/
- private function getFileKeyDir($path) {
+ private function getFileKeyDir($encryptionModuleId, $path) {
if ($this->view->is_dir($path)) {
throw new GenericEncryptionException("file was expected but directory was given: $path");
@@ -272,7 +227,7 @@ class Storage implements \OCP\Encryption\Keys\IStorage {
$keyPath = '/' . $owner . $this->keys_base_dir . $filename . '/';
}
- return \OC\Files\Filesystem::normalizePath($keyPath . $this->encryptionModuleId . '/', false);
+ return Filesystem::normalizePath($keyPath . $encryptionModuleId . '/', false);
}
/**
@@ -280,8 +235,6 @@ class Storage implements \OCP\Encryption\Keys\IStorage {
*
* @param string $source
* @param string $target
- * @param string $owner
- * @param bool $systemWide
*/
public function renameKeys($source, $target) {
@@ -308,8 +261,6 @@ class Storage implements \OCP\Encryption\Keys\IStorage {
*
* @param string $source
* @param string $target
- * @param string $owner
- * @param bool $systemWide
*/
public function copyKeys($source, $target) {
@@ -332,7 +283,7 @@ class Storage implements \OCP\Encryption\Keys\IStorage {
}
/**
- * Make preparations to filesystem for saving a keyfile
+ * Make preparations to filesystem for saving a key file
*
* @param string $path relative to the views root
*/
diff --git a/lib/private/encryption/manager.php b/lib/private/encryption/manager.php
index 7a3f17519fc..97203b7756d 100644
--- a/lib/private/encryption/manager.php
+++ b/lib/private/encryption/manager.php
@@ -221,7 +221,8 @@ class Manager implements IManager {
$logger = \OC::$server->getLogger();
$uid = $user ? $user->getUID() : null;
$fileHelper = \OC::$server->getEncryptionFilesHelper();
- return new Encryption($parameters, $manager, $util, $logger, $fileHelper, $uid);
+ $keyStorage = \OC::$server->getEncryptionKeyStorage();
+ return new Encryption($parameters, $manager, $util, $logger, $fileHelper, $uid, $keyStorage);
} else {
return $storage;
}
diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php
index e5c96286f09..0a9e6d61d2e 100644
--- a/lib/private/files/storage/wrapper/encryption.php
+++ b/lib/private/files/storage/wrapper/encryption.php
@@ -56,6 +56,9 @@ class Encryption extends Wrapper {
/** @var IMountPoint */
private $mount;
+ /** @var \OCP\Encryption\Keys\IStorage */
+ private $keyStorage;
+
/**
* @param array $parameters
* @param \OC\Encryption\Manager $encryptionManager
@@ -70,7 +73,8 @@ class Encryption extends Wrapper {
\OC\Encryption\Util $util = null,
\OC\Log $logger = null,
File $fileHelper = null,
- $uid = null
+ $uid = null,
+ $keyStorage = null
) {
$this->mountPoint = $parameters['mountPoint'];
@@ -80,6 +84,7 @@ class Encryption extends Wrapper {
$this->logger = $logger;
$this->uid = $uid;
$this->fileHelper = $fileHelper;
+ $this->keyStorage = $keyStorage;
$this->unencryptedSize = array();
parent::__construct($parameters);
}
@@ -187,8 +192,8 @@ class Encryption extends Wrapper {
$encryptionModule = $this->getEncryptionModule($path);
if ($encryptionModule) {
- $keyStorage = $this->getKeyStorage($encryptionModule->getId());
- $keyStorage->deleteAllFileKeys($this->getFullPath($path));
+ $this->keyStorage->deleteAllFileKeys($this->getFullPath($path),
+ $encryptionModule->getId());
}
return $this->storage->unlink($path);
@@ -214,11 +219,7 @@ class Encryption extends Wrapper {
if (isset($this->unencryptedSize[$source])) {
$this->unencryptedSize[$target] = $this->unencryptedSize[$source];
}
- $encryptionModule = $this->getEncryptionModule($path2);
- if ($encryptionModule) {
- $keyStorage = $this->getKeyStorage($encryptionModule->getId());
- $keyStorage->renameKeys($source, $target);
- }
+ $this->keyStorage->renameKeys($source, $target);
}
return $result;
@@ -243,8 +244,7 @@ class Encryption extends Wrapper {
$target = $this->getFullPath($path2);
$encryptionModule = $this->getEncryptionModule($path2);
if ($encryptionModule) {
- $keyStorage = $this->getKeyStorage($encryptionModule->getId());
- $keyStorage->copyKeys($source, $target);
+ $this->keyStorage->copyKeys($source, $target);
}
}
@@ -431,14 +431,4 @@ class Encryption extends Wrapper {
public function updateUnencryptedSize($path, $unencryptedSize) {
$this->unencryptedSize[$path] = $unencryptedSize;
}
-
- /**
- * @param string $encryptionModuleId
- * @return \OCP\Encryption\Keys\IStorage
- */
- protected function getKeyStorage($encryptionModuleId) {
- $keyStorage = \OC::$server->getEncryptionKeyStorage($encryptionModuleId);
- return $keyStorage;
- }
-
}
diff --git a/lib/private/server.php b/lib/private/server.php
index d321ecb68bd..8fdeec5281c 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -97,8 +97,16 @@ class Server extends SimpleContainer implements IServerContainer {
return new Encryption\File($util);
});
- $this->registerService('EncryptionKeyStorageFactory', function ($c) {
- return new Encryption\Keys\Factory();
+ $this->registerService('EncryptionKeyStorage', function (Server $c) {
+ $view = new \OC\Files\View();
+ $util = new \OC\Encryption\Util(
+ $view,
+ $c->getUserManager(),
+ $c->getGroupManager(),
+ $c->getConfig()
+ );
+
+ return new Encryption\Keys\Storage($view, $util);
});
$this->registerService('TagMapper', function(Server $c) {
return new TagMapper($c->getDatabaseConnection());
@@ -436,19 +444,10 @@ class Server extends SimpleContainer implements IServerContainer {
}
/**
- * @param string $encryptionModuleId encryption module ID
- *
* @return \OCP\Encryption\Keys\IStorage
*/
- public function getEncryptionKeyStorage($encryptionModuleId) {
- $view = new \OC\Files\View();
- $util = new \OC\Encryption\Util(
- $view,
- \OC::$server->getUserManager(),
- \OC::$server->getGroupManager(),
- \OC::$server->getConfig()
- );
- return $this->query('EncryptionKeyStorageFactory')->get($encryptionModuleId, $view, $util);
+ public function getEncryptionKeyStorage() {
+ return $this->query('EncryptionKeyStorage');
}
/**
diff --git a/lib/public/encryption/keys/istorage.php b/lib/public/encryption/keys/istorage.php
index 3e497ed2c75..696d5373310 100644
--- a/lib/public/encryption/keys/istorage.php
+++ b/lib/public/encryption/keys/istorage.php
@@ -35,33 +35,36 @@ interface IStorage {
*
* @param string $uid ID if the user for whom we want the key
* @param string $keyId id of the key
+ * @param string $encryptionModuleId
*
* @return mixed key
* @since 8.1.0
*/
- public function getUserKey($uid, $keyId);
+ public function getUserKey($uid, $keyId, $encryptionModuleId);
/**
* get file specific key
*
* @param string $path path to file
* @param string $keyId id of the key
+ * @param string $encryptionModuleId
*
* @return mixed key
* @since 8.1.0
*/
- public function getFileKey($path, $keyId);
+ public function getFileKey($path, $keyId, $encryptionModuleId);
/**
* get system-wide encryption keys not related to a specific user,
* e.g something like a key for public link shares
*
* @param string $keyId id of the key
+ * @param string $encryptionModuleId
*
* @return mixed key
* @since 8.1.0
*/
- public function getSystemUserKey($keyId);
+ public function getSystemUserKey($keyId, $encryptionModuleId);
/**
* set user specific key
@@ -69,19 +72,21 @@ interface IStorage {
* @param string $uid ID if the user for whom we want the key
* @param string $keyId id of the key
* @param mixed $key
+ * @param string $encryptionModuleId
* @since 8.1.0
*/
- public function setUserKey($uid, $keyId, $key);
+ public function setUserKey($uid, $keyId, $key, $encryptionModuleId);
/**
* set file specific key
*
* @param string $path path to file
* @param string $keyId id of the key
- * @param boolean
+ * @param mixed $key
+ * @param string $encryptionModuleId
* @since 8.1.0
*/
- public function setFileKey($path, $keyId, $key);
+ public function setFileKey($path, $keyId, $key, $encryptionModuleId);
/**
* set system-wide encryption keys not related to a specific user,
@@ -89,53 +94,59 @@ interface IStorage {
*
* @param string $keyId id of the key
* @param mixed $key
+ * @param string $encryptionModuleId
*
* @return mixed key
* @since 8.1.0
*/
- public function setSystemUserKey($keyId, $key);
+ public function setSystemUserKey($keyId, $key, $encryptionModuleId);
/**
* delete user specific key
*
* @param string $uid ID if the user for whom we want to delete the key
* @param string $keyId id of the key
+ * @param string $encryptionModuleId
*
* @return boolean False when the key could not be deleted
* @since 8.1.0
*/
- public function deleteUserKey($uid, $keyId);
+ public function deleteUserKey($uid, $keyId, $encryptionModuleId);
/**
* delete file specific key
*
* @param string $path path to file
* @param string $keyId id of the key
+ * @param string $encryptionModuleId
*
* @return boolean False when the key could not be deleted
* @since 8.1.0
*/
- public function deleteFileKey($path, $keyId);
+ public function deleteFileKey($path, $keyId, $encryptionModuleId);
/**
* delete all file keys for a given file
*
* @param string $path to the file
+ * @param string $encryptionModuleId
+ *
* @return boolean False when the keys could not be deleted
* @since 8.1.0
*/
- public function deleteAllFileKeys($path);
+ public function deleteAllFileKeys($path, $encryptionModuleId);
/**
* delete system-wide encryption keys not related to a specific user,
* e.g something like a key for public link shares
*
* @param string $keyId id of the key
+ * @param string $encryptionModuleId
*
* @return boolean False when the key could not be deleted
* @since 8.1.0
*/
- public function deleteSystemUserKey($keyId);
+ public function deleteSystemUserKey($keyId, $encryptionModuleId);
/**
* copy keys if a file was renamed
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index 9af1582dae9..428c91429ef 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -211,12 +211,10 @@ interface IServerContainer {
public function getEncryptionFilesHelper();
/**
- * @param string $encryptionModuleId encryption module ID
- *
* @return \OCP\Encryption\Keys\IStorage
* @since 8.1.0
*/
- public function getEncryptionKeyStorage($encryptionModuleId);
+ public function getEncryptionKeyStorage();
/**
* Returns the URL generator