From 0c24c7c4203071542d1f1acc447bb6c6b18148db Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 20 Nov 2013 11:02:22 +0100 Subject: only check if the key file exists to decide if it is an encrypted file or not. This solves problems with external storage which doesn't support fseek --- apps/files_encryption/lib/keymanager.php | 3 +-- apps/files_encryption/lib/stream.php | 2 +- apps/files_encryption/lib/util.php | 23 ++++++++--------------- 3 files changed, 10 insertions(+), 18 deletions(-) (limited to 'apps/files_encryption/lib') diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 6dadd12a62e..3427e8a963a 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -172,14 +172,13 @@ class Keymanager { /** * @brief retrieve keyfile for an encrypted file * @param \OC_FilesystemView $view - * @param $userId * @param $filePath * @internal param \OCA\Encryption\file $string name * @return string file key or false * @note The keyfile returned is asymmetrically encrypted. Decryption * of the keyfile must be performed by client code */ - public static function getFileKey(\OC_FilesystemView $view, $userId, $filePath) { + public static function getFileKey(\OC_FilesystemView $view, $filePath) { $util = new Util($view, \OCP\User::getUser()); diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 1738955d1aa..206e3469023 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -250,7 +250,7 @@ class Stream { // Fetch and decrypt keyfile // Fetch existing keyfile - $this->encKeyfile = Keymanager::getFileKey($this->rootView, $this->userId, $this->relPath); + $this->encKeyfile = Keymanager::getFileKey($this->rootView, $this->relPath); // If a keyfile already exists if ($this->encKeyfile) { diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index f9beb9de670..4f27c2b00fb 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -367,7 +367,7 @@ class Util { // scanning every file like this // will eat server resources :( if ( - Keymanager::getFileKey($this->view, $this->userId, $relPath) + Keymanager::getFileKey($this->view, $relPath) && $isEncryptedPath ) { @@ -472,22 +472,15 @@ class Util { */ public function isEncryptedPath($path) { - // Disable encryption proxy so data retrieved is in its - // original form - $proxyStatus = \OC_FileProxy::$enabled; - \OC_FileProxy::$enabled = false; + $relPath = Helper::stripUserFilesPath($path); - // we only need 24 byte from the last chunk - $data = ''; - $handle = $this->view->fopen($path, 'r'); - if (is_resource($handle) && !fseek($handle, -24, SEEK_END)) { - $data = fgets($handle); - } + $fileKey = Keymanager::getFileKey($this->view, $relPath); - // re-enable proxy - \OC_FileProxy::$enabled = $proxyStatus; + if ($fileKey === false) { + return false; + } - return Crypt::isCatfileContent($data); + return true; } @@ -1059,7 +1052,7 @@ class Util { private function decryptKeyfile($filePath, $privateKey) { // Get the encrypted keyfile - $encKeyfile = Keymanager::getFileKey($this->view, $this->userId, $filePath); + $encKeyfile = Keymanager::getFileKey($this->view, $filePath); // The file has a shareKey and must use it for decryption $shareKey = Keymanager::getShareKey($this->view, $this->userId, $filePath); -- cgit v1.2.3 From f3e2a63712e3306c5bb1cad1921da4a3ff542474 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 20 Nov 2013 12:34:23 +0100 Subject: check if it is a cached file or a version to resolve the correct path to the file key --- apps/files_encryption/lib/util.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'apps/files_encryption/lib') diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 4f27c2b00fb..b208a808bac 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -472,7 +472,11 @@ class Util { */ public function isEncryptedPath($path) { - $relPath = Helper::stripUserFilesPath($path); + $relPath = Helper::getPathToRealFile($path); + + if ($relPath === false) { + $relPath = Helper::stripUserFilesPath($path); + } $fileKey = Keymanager::getFileKey($this->view, $relPath); -- cgit v1.2.3 From fe440248683fb74d758dd257272efcffb7e3c325 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 20 Nov 2013 16:20:21 +0100 Subject: Fix for extstorage + encryption where unencrypted size is not kept Fix for external storage with encryption where the unencrypted size is first written in the DB, then set back to zero, causing performance issue because the file needs to be reopened every time to find out the unencrypted size (and potentially needs a full redownload) --- apps/files_encryption/lib/proxy.php | 3 +++ apps/files_encryption/lib/stream.php | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'apps/files_encryption/lib') diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 54c3b9caa15..a8c74bd9dd4 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -349,7 +349,10 @@ class Proxy extends \OC_FileProxy { $fileInfo = false; // get file info from database/cache if not .part file if (!Helper::isPartialFilePath($path)) { + $proxyState = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; $fileInfo = $view->getFileInfo($path); + \OC_FileProxy::$enabled = $proxyState; } // if file is encrypted return real file size diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 1738955d1aa..1f4f14d7fe5 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -491,7 +491,8 @@ class Stream { if ( $this->meta['mode'] !== 'r' && $this->meta['mode'] !== 'rb' && - $this->size > 0 + $this->size > 0 && + $this->unencryptedSize > 0 ) { // only write keyfiles if it was a new file -- cgit v1.2.3