diff options
author | Vincent Petry <pvince81@owncloud.com> | 2013-11-20 07:32:43 -0800 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2013-11-20 07:32:43 -0800 |
commit | c221e8272cacc198b963e9dd38463aa0f3d8897c (patch) | |
tree | 1ba77b2830ad6b2e1fce436bf5c4e1b8d6e15fe7 | |
parent | 30b8f4ec8e3dbf8e2d5d3627e0447bc20da50335 (diff) | |
parent | b4e7258a04f9b634031984aea655ed964aa003d3 (diff) | |
download | nextcloud-server-c221e8272cacc198b963e9dd38463aa0f3d8897c.tar.gz nextcloud-server-c221e8272cacc198b963e9dd38463aa0f3d8897c.zip |
Merge pull request #5959 from owncloud/encryption_check_if_file_is_encrypted
only check if the key file exists to decide if it is an encrypted file or not
-rwxr-xr-x | apps/files_encryption/lib/keymanager.php | 3 | ||||
-rw-r--r-- | apps/files_encryption/lib/stream.php | 2 | ||||
-rw-r--r-- | apps/files_encryption/lib/util.php | 25 | ||||
-rwxr-xr-x | apps/files_encryption/tests/crypt.php | 14 |
4 files changed, 20 insertions, 24 deletions
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..b208a808bac 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,19 @@ 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::getPathToRealFile($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); + if ($relPath === false) { + $relPath = Helper::stripUserFilesPath($path); } - // re-enable proxy - \OC_FileProxy::$enabled = $proxyStatus; + $fileKey = Keymanager::getFileKey($this->view, $relPath); - return Crypt::isCatfileContent($data); + if ($fileKey === false) { + return false; + } + + return true; } @@ -1059,7 +1056,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); diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php index 5146613e252..9c32ee06453 100755 --- a/apps/files_encryption/tests/crypt.php +++ b/apps/files_encryption/tests/crypt.php @@ -176,7 +176,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase { $this->assertNotEquals($this->dataShort, $retreivedCryptedFile); // Get the encrypted keyfile - $encKeyfile = Encryption\Keymanager::getFileKey($this->view, $this->userId, $filename); + $encKeyfile = Encryption\Keymanager::getFileKey($this->view, $filename); // Attempt to fetch the user's shareKey $shareKey = Encryption\Keymanager::getShareKey($this->view, $this->userId, $filename); @@ -244,13 +244,13 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase { $i = 0; while ($i < count($r)-1) { $e[] = $r[$i] . $r[$i+1]; - $i = $i + 2; + $i = $i + 2; } //print_r($e); // Get the encrypted keyfile - $encKeyfile = Encryption\Keymanager::getFileKey($this->view, $this->userId, $filename); + $encKeyfile = Encryption\Keymanager::getFileKey($this->view, $filename); // Attempt to fetch the user's shareKey $shareKey = Encryption\Keymanager::getShareKey($this->view, $this->userId, $filename); @@ -387,7 +387,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase { * @brief test decryption using legacy blowfish method */ function testLegacyDecryptShort() { - + $crypted = $this->legacyEncrypt($this->dataShort, $this->pass); $decrypted = Encryption\Crypt::legacyBlockDecrypt($crypted, $this->pass); @@ -401,7 +401,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase { * @brief test decryption using legacy blowfish method */ function testLegacyDecryptLong() { - + $crypted = $this->legacyEncrypt($this->dataLong, $this->pass); $decrypted = Encryption\Crypt::legacyBlockDecrypt($crypted, $this->pass); @@ -653,8 +653,8 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase { // tear down $view->unlink($filename); } - - + + /** * @brief encryption using legacy blowfish method * @param $data string data to encrypt |