]> source.dussan.org Git - nextcloud-server.git/commitdiff
delete recovery keys on disable
authorBjoern Schiessle <schiessle@owncloud.com>
Tue, 31 Mar 2015 17:24:52 +0000 (19:24 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 7 Apr 2015 11:30:29 +0000 (13:30 +0200)
apps/encryption/lib/keymanager.php
apps/encryption/lib/recovery.php

index 9aae6fb2d9d4b69ec4dade9f1f79eb14e1180d04..e8e92cd549aafabe9faca80d68505da6d48ab786 100644 (file)
@@ -352,6 +352,18 @@ class KeyManager {
                return $key;
        }
 
+       /**
+        * delete file key
+        *
+        * @param string $path
+        * @param string $keyId
+        * @return boolean
+        */
+       public function deleteFileKey($path, $keyId) {
+               return $this->keyStorage->deleteFileKey($path, $keyId);
+       }
+
+
        /**
         * @param $path
         * @param $uid
index b3da82a3cc5e35a4fbc7078119b0479b7046ebcf..00711e3bfab70d29cfbb9175165443d974b88778 100644 (file)
@@ -182,7 +182,7 @@ class Recovery {
                        if ($value === '1') {
                                $this->addRecoveryKeys('/' . $this->user->getUID() . '/files/');
                        } else {
-                               $this->removeRecoveryKeys();
+                               $this->removeRecoveryKeys('/' . $this->user->getUID() . '/files/');
                        }
 
                        return true;
@@ -194,10 +194,9 @@ class Recovery {
        /**
         * add recovery key to all encrypted files
         */
-       private function addRecoveryKeys($path = '/') {
+       private function addRecoveryKeys($path) {
                $dirContent = $this->view->getDirectoryContent($path);
                foreach ($dirContent as $item) {
-                       // get relative path from files_encryption/keyfiles/
                        $filePath = $item->getPath();
                        if ($item['type'] === 'dir') {
                                $this->addRecoveryKeys($filePath . '/');
@@ -222,18 +221,14 @@ class Recovery {
        /**
         * remove recovery key to all encrypted files
         */
-       private function removeRecoveryKeys($path = '/') {
-               return true;
-               $dirContent = $this->view->getDirectoryContent($this->keyfilesPath . $path);
+       private function removeRecoveryKeys($path) {
+               $dirContent = $this->view->getDirectoryContent($path);
                foreach ($dirContent as $item) {
-                       // get relative path from files_encryption/keyfiles
-                       $filePath = substr($item['path'], strlen('files_encryption/keyfiles'));
+                       $filePath = $item->getPath();
                        if ($item['type'] === 'dir') {
                                $this->removeRecoveryKeys($filePath . '/');
                        } else {
-                               // remove '.key' extension from path e.g. 'file.txt.key' to 'file.txt'
-                               $file = substr($filePath, 0, -4);
-                               $this->view->unlink($this->shareKeysPath . '/' . $file . '.' . $this->recoveryKeyId . '.shareKey');
+                               $this->keyManager->deleteFileKey($filePath, $this->keyManager->getRecoveryKeyId() . '.shareKey');
                        }
                }
        }