aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/encryption
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/encryption')
-rw-r--r--lib/private/encryption/exceptions/decryptionfailedexception.php11
-rw-r--r--lib/private/encryption/hookmanager.php8
-rw-r--r--lib/private/encryption/keys/storage.php14
-rw-r--r--lib/private/encryption/update.php34
-rw-r--r--lib/private/encryption/util.php2
5 files changed, 56 insertions, 13 deletions
diff --git a/lib/private/encryption/exceptions/decryptionfailedexception.php b/lib/private/encryption/exceptions/decryptionfailedexception.php
index 406ae12968e..7e9fa21eaef 100644
--- a/lib/private/encryption/exceptions/decryptionfailedexception.php
+++ b/lib/private/encryption/exceptions/decryptionfailedexception.php
@@ -27,4 +27,15 @@ use OCP\Encryption\Exceptions\GenericEncryptionException;
class DecryptionFailedException extends GenericEncryptionException {
+ /**
+ * @param string $message
+ * @param int $code
+ * @param \Exception $previous
+ * @param string $hint
+ */
+ public function __construct($message = '', $code = 0, \Exception $previous = null, $hint = '') {
+ parent::__construct($message, $code, $previous, $hint);
+
+}
+
}
diff --git a/lib/private/encryption/hookmanager.php b/lib/private/encryption/hookmanager.php
index c62583b4b47..31ecb2fbcf6 100644
--- a/lib/private/encryption/hookmanager.php
+++ b/lib/private/encryption/hookmanager.php
@@ -37,6 +37,14 @@ class HookManager {
self::getUpdate()->postUnshared($params);
}
+ public static function postRename($params) {
+ self::getUpdate()->postRename($params);
+ }
+
+ public static function postRestore($params) {
+ self::getUpdate()->postRestore($params);
+ }
+
/**
* @return Update
*/
diff --git a/lib/private/encryption/keys/storage.php b/lib/private/encryption/keys/storage.php
index 118c8dc920d..6aa00c5b5ee 100644
--- a/lib/private/encryption/keys/storage.php
+++ b/lib/private/encryption/keys/storage.php
@@ -125,10 +125,9 @@ class Storage implements IStorage {
/**
* @inheritdoc
*/
- public function deleteAllFileKeys($path, $encryptionModuleId) {
- $keyDir = $this->getFileKeyDir($encryptionModuleId, $path);
- $path = dirname($keyDir);
- return !$this->view->file_exists($path) || $this->view->deleteAll($path);
+ public function deleteAllFileKeys($path) {
+ $keyDir = $this->getFileKeyDir('', $path);
+ return !$this->view->file_exists($keyDir) || $this->view->deleteAll($keyDir);
}
/**
@@ -208,17 +207,10 @@ class Storage implements IStorage {
* @param string $encryptionModuleId
* @param string $path path to the file, relative to data/
* @return string
- * @throws GenericEncryptionException
- * @internal param string $keyId
*/
private function getFileKeyDir($encryptionModuleId, $path) {
- if ($this->view->is_dir($path)) {
- throw new GenericEncryptionException("file was expected but directory was given: $path");
- }
-
list($owner, $filename) = $this->util->getUidAndFilename($path);
- $filename = $this->util->stripPartialFileExtension($filename);
// in case of system wide mount points the keys are stored directly in the data directory
if ($this->util->isSystemWideMountPoint($filename, $owner)) {
diff --git a/lib/private/encryption/update.php b/lib/private/encryption/update.php
index ddcee3bae93..02579fd9136 100644
--- a/lib/private/encryption/update.php
+++ b/lib/private/encryption/update.php
@@ -108,13 +108,45 @@ class Update {
}
/**
+ * inform encryption module that a file was restored from the trash bin,
+ * e.g. to update the encryption keys
+ *
+ * @param array $params
+ */
+ public function postRestore($params) {
+ if ($this->encryptionManager->isEnabled()) {
+ $path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']);
+ $this->update($path);
+ }
+ }
+
+ /**
+ * inform encryption module that a file was renamed,
+ * e.g. to update the encryption keys
+ *
+ * @param array $params
+ */
+ public function postRename($params) {
+ $source = $params['oldpath'];
+ $target = $params['newpath'];
+ if(
+ $this->encryptionManager->isEnabled() &&
+ dirname($source) !== dirname($target)
+ ) {
+ list($owner, $ownerPath) = $this->getOwnerPath($target);
+ $absPath = '/' . $owner . '/files/' . $ownerPath;
+ $this->update($absPath);
+ }
+ }
+
+ /**
* get owner and path relative to data/<owner>/files
*
* @param string $path path to file for current user
* @return array ['owner' => $owner, 'path' => $path]
* @throw \InvalidArgumentException
*/
- private function getOwnerPath($path) {
+ protected function getOwnerPath($path) {
$info = Filesystem::getFileInfo($path);
$owner = Filesystem::getOwner($path);
$view = new View('/' . $owner . '/files');
diff --git a/lib/private/encryption/util.php b/lib/private/encryption/util.php
index 5ea9b8bdeaf..b77672d2f6b 100644
--- a/lib/private/encryption/util.php
+++ b/lib/private/encryption/util.php
@@ -357,7 +357,7 @@ class Util {
public function isExcluded($path) {
$normalizedPath = \OC\Files\Filesystem::normalizePath($path);
$root = explode('/', $normalizedPath, 4);
- if (count($root) > 2) {
+ if (count($root) > 1) {
//detect system wide folders
if (in_array($root[1], $this->excludedPaths)) {