From 810ca9105ca7b25c98d7bc265dfb4c8e37b9b8e8 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 26 Mar 2015 09:24:28 +0100 Subject: [PATCH] implement rename and delete of encryption keys --- lib/private/encryption/keys/storage.php | 34 +++++++++++++++++++ .../files/storage/wrapper/encryption.php | 1 + 2 files changed, 35 insertions(+) diff --git a/lib/private/encryption/keys/storage.php b/lib/private/encryption/keys/storage.php index 8f1822ca492..c8afcbbd213 100644 --- a/lib/private/encryption/keys/storage.php +++ b/lib/private/encryption/keys/storage.php @@ -161,6 +161,17 @@ class Storage implements \OCP\Encryption\Keys\IStorage { return $this->view->unlink($keyDir . $keyId); } + /** + * delete all file keys for a given file + * + * @param string $path to the file + * @return boolean + */ + public function deleteAllFileKeys($path) { + $keyDir = $this->getFileKeyDir($path); + return $this->view->deleteAll(dirname($keyDir)); + } + /** * delete system-wide encryption keys not related to a specific user, * e.g something like a key for public link shares @@ -264,6 +275,29 @@ class Storage implements \OCP\Encryption\Keys\IStorage { return \OC\Files\Filesystem::normalizePath($keyPath . $this->encryptionModuleId . '/', false); } + /** + * move keys if a file was renamed + * + * @param string $source + * @param string $target + * @param string $owner + * @param bool $systemWide + */ + public function renameKeys($source, $target, $owner, $systemWide) { + if ($systemWide) { + $sourcePath = $this->keys_base_dir . $source . '/'; + $targetPath = $this->keys_base_dir . $target . '/'; + } else { + $sourcePath = '/' . $owner . $this->keys_base_dir . $source . '/'; + $targetPath = '/' . $owner . $this->keys_base_dir . $target . '/'; + } + + if ($this->view->file_exists($sourcePath)) { + $this->keySetPreparation(dirname($targetPath)); + $this->view->rename($sourcePath, $targetPath); + } + } + /** * Make preparations to filesystem for saving a keyfile * diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index 0e70c99c8d7..2a5b9926f68 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -62,6 +62,7 @@ class Encryption extends Wrapper { $this->mountPoint = $parameters['mountPoint']; $this->encryptionManager = $encryptionManager; + $this->keyStorage = $keyStorage; $this->util = $util; $this->logger = $logger; $this->uid = $uid; -- 2.39.5