From b024db9f989098b6adea42fb5bde4a49bf7ec5de Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Sun, 6 Jan 2013 13:56:45 +0000 Subject: [PATCH] Made Keymanager::getFileKey() dependencies explicit, fixed client code and tests accordingly --- apps/files_encryption/lib/keymanager.php | 6 +++--- apps/files_encryption/lib/proxy.php | 6 +++++- apps/files_encryption/lib/stream.php | 2 +- apps/files_encryption/tests/crypt.php | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 818cd1a154d..e6c08ee2b7f 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -149,7 +149,7 @@ class Keymanager { * @note The keyfile returned is asymmetrically encrypted. Decryption * of the keyfile must be performed by client code */ - public static function getFileKey( $view, $userId, $filePath ) { + public static function getFileKey( \OC_FilesystemView $view, $userId, $filePath ) { $filePath_f = ltrim( $filePath, '/' ); @@ -166,8 +166,8 @@ class Keymanager { // $keypath = str_replace( '/' . $userId . '/files/', '', $keypath ); // // } - - return $this->view->file_get_contents( '/' . $userId . '/files_encryption/keyfiles/' . $filePath_f ); +// trigger_error(var_export($view, 1)); + return $view->file_get_contents( '/' . $userId . '/files_encryption/keyfiles/' . $filePath_f . '.key' ); } diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 272d0a5509f..0084af94c77 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -156,7 +156,11 @@ class Proxy extends \OC_FileProxy { //$cached = \OC_FileCache_Cached::get( $path, '' ); - $encryptedKeyfile = Keymanager::getFileKey( $filePath ); + $view = new \OC_FilesystemView( '' ); + + $userId = \OCP\USER::getUser(); + + $encryptedKeyfile = Keymanager::getFileKey( $view, $userId, $filePath ); $session = new Session(); diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index fc1b9808cc5..a98f5bec833 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -267,7 +267,7 @@ class Stream { # TODO: add error handling for when file exists but no keyfile // Fetch existing keyfile - $this->encKeyfile = Keymanager::getFileKey( $this->rawPath ); + $this->encKeyfile = Keymanager::getFileKey( $this->rootView, $this->userId, $this->rawPath ); $this->getUser(); diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php index 446af7cfa09..4ac53a646b1 100755 --- a/apps/files_encryption/tests/crypt.php +++ b/apps/files_encryption/tests/crypt.php @@ -242,7 +242,7 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase { // Get keyfile - $encryptedKeyfile = Encryption\Keymanager::getFileKey( $filename ); + $encryptedKeyfile = Encryption\Keymanager::getFileKey( $this->view, $this->userId, $filename ); $decryptedKeyfile = Encryption\Crypt::keyDecrypt( $encryptedKeyfile, $decryptedPrivateKey ); @@ -298,7 +298,7 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase { // Get keyfile - $encryptedKeyfile = Encryption\Keymanager::getFileKey( $filename ); + $encryptedKeyfile = Encryption\Keymanager::getFileKey( $this->view, $this->userId, $filename ); $decryptedKeyfile = Encryption\Crypt::keyDecrypt( $encryptedKeyfile, $decryptedPrivateKey ); -- 2.39.5