]> source.dussan.org Git - nextcloud-server.git/commitdiff
Merge branch 'master' into remove_unused_vars
authorFlorin Peter <github@florin-peter.de>
Wed, 29 May 2013 07:21:00 +0000 (09:21 +0200)
committerFlorin Peter <github@florin-peter.de>
Wed, 29 May 2013 07:21:00 +0000 (09:21 +0200)
Conflicts:
apps/files_encryption/hooks/hooks.php
apps/files_encryption/lib/proxy.php
apps/files_encryption/lib/session.php
apps/files_encryption/lib/stream.php

1  2 
apps/files_encryption/hooks/hooks.php
apps/files_encryption/lib/proxy.php
apps/files_encryption/lib/session.php
apps/files_encryption/lib/stream.php
apps/files_encryption/lib/util.php
apps/files_encryption/tests/crypt.php

index 6bac7debea27e703f67b3d9d323e596562418275,0ef796dbaef2b5451bf8e32d8c8cb6dff4a1dd3f..955425595ba523dedc7e41e39b6d58f3177554b1
@@@ -37,51 -37,51 +37,51 @@@ class Hooks 
         * @brief Startup encryption backend upon user login\r
         * @note This method should never be called for users using client side encryption\r
         */\r
 -      public static function login( $params ) {\r
 -      \r
 +      public static function login($params) {\r
 +\r
                // Manually initialise Filesystem{} singleton with correct \r
                // fake root path, in order to avoid fatal webdav errors\r
 -        // NOTE: disabled because this give errors on webdav!\r
 +              // NOTE: disabled because this give errors on webdav!\r
                //\OC\Files\Filesystem::init( $params['uid'], '/' . 'files' . '/' );\r
 -      \r
 -              $view = new \OC_FilesystemView( '/' );\r
  \r
 -              $util = new Util( $view, $params['uid'] );\r
 +              $view = new \OC_FilesystemView('/');\r
 +\r
 +              $util = new Util($view, $params['uid']);\r
 +\r
 +              // setup user, if user not ready force relogin\r
 +              if (Helper::setupUser($util, $params['password']) === false) {\r
 +                      return false;\r
 +              }\r
 +\r
 +              $encryptedKey = Keymanager::getPrivateKey($view, $params['uid']);\r
  \r
 -        // setup user, if user not ready force relogin\r
 -              if(Helper::setupUser($util, $params['password']) === false) {\r
 -            return false;\r
 -        }\r
 +              $privateKey = Crypt::symmetricDecryptFileContent($encryptedKey, $params['password']);\r
  \r
-               $session = new Session($view);\r
 -              $encryptedKey = Keymanager::getPrivateKey( $view, $params['uid'] );\r
 -              \r
 -              $privateKey = Crypt::symmetricDecryptFileContent( $encryptedKey, $params['password'] );\r
++              $session = new \OCA\Encryption\Session($view);\r
 +\r
 +              $session->setPrivateKey($privateKey, $params['uid']);\r
  \r
 -              $session = new \OCA\Encryption\Session( $view );\r
 -              \r
 -              $session->setPrivateKey( $privateKey, $params['uid'] );\r
 -              \r
                // Check if first-run file migration has already been performed\r
                $migrationCompleted = $util->getMigrationStatus();\r
 -              \r
 +\r
                // If migration not yet done\r
 -              if ( ! $migrationCompleted ) {\r
 -              \r
 -                      $userView = new \OC_FilesystemView( '/' . $params['uid'] );\r
 -                      \r
 +              if (!$migrationCompleted) {\r
 +\r
 +                      $userView = new \OC_FilesystemView('/' . $params['uid']);\r
 +\r
                        // Set legacy encryption key if it exists, to support \r
                        // depreciated encryption system\r
                        if (\r
 -                              $userView->file_exists( 'encryption.key' )\r
 -                              && $encLegacyKey = $userView->file_get_contents( 'encryption.key' )\r
 +                              $userView->file_exists('encryption.key')\r
 +                              && $encLegacyKey = $userView->file_get_contents('encryption.key')\r
                        ) {\r
 -                      \r
 -                              $plainLegacyKey = Crypt::legacyBlockDecrypt( $encLegacyKey, $params['password'] );\r
 -                              \r
 -                              $session->setLegacyKey( $plainLegacyKey );\r
--                      \r
++\r
 +                              $plainLegacyKey = Crypt::legacyBlockDecrypt($encLegacyKey, $params['password']);\r
-                               \r
++\r
 +                              $session->setLegacyKey($plainLegacyKey);\r
-                       \r
++\r
                        }\r
--                      \r
++\r
                        // Encrypt existing user files:\r
                        // This serves to upgrade old versions of the encryption\r
                        // app (see appinfo/spec.txt)\r
  \r
                }\r
        }\r
 -      \r
 +\r
        /**\r
 -     * @brief after a file is renamed, rename its keyfile and share-keys also fix the file size and fix also the sharing\r
 -     * @param array with oldpath and newpath\r
 -     *\r
 -     * This function is connected to the rename signal of OC_Filesystem and adjust the name and location\r
 -     * of the stored versions along the actual file\r
 -     */\r
 -    public static function postRename($params) {\r
 -        // Disable encryption proxy to prevent recursive calls\r
 -        $proxyStatus = \OC_FileProxy::$enabled;\r
 -        \OC_FileProxy::$enabled = false;\r
 -\r
 -        $view = new \OC_FilesystemView('/');\r
 -        $session = new \OCA\Encryption\Session($view);\r
 -        $userId = \OCP\User::getUser();\r
 -        $util = new Util( $view, $userId );\r
 -\r
 -        // Format paths to be relative to user files dir\r
 -        $oldKeyfilePath = \OC\Files\Filesystem::normalizePath($userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['oldpath']);\r
 -        $newKeyfilePath = \OC\Files\Filesystem::normalizePath($userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['newpath']);\r
 -\r
 -        // add key ext if this is not an folder\r
 -        if (!$view->is_dir($oldKeyfilePath)) {\r
 -            $oldKeyfilePath .= '.key';\r
 -            $newKeyfilePath .= '.key';\r
 -\r
 -            // handle share-keys\r
 -            $localKeyPath = $view->getLocalFile($userId.'/files_encryption/share-keys/'.$params['oldpath']);\r
 -            $matches = glob(preg_quote($localKeyPath).'*.shareKey');\r
 -            foreach ($matches as $src) {\r
 -                $dst = \OC\Files\Filesystem::normalizePath(str_replace($params['oldpath'], $params['newpath'], $src));\r
 -\r
 -                // create destination folder if not exists\r
 -                if(!file_exists(dirname($dst))) {\r
 -                    mkdir(dirname($dst), 0750, true);\r
 -                }\r
 -\r
 -                rename($src, $dst);\r
 -            }\r
 -\r
 -        } else {\r
 -            // handle share-keys folders\r
 -            $oldShareKeyfilePath = \OC\Files\Filesystem::normalizePath($userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['oldpath']);\r
 -            $newShareKeyfilePath = \OC\Files\Filesystem::normalizePath($userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['newpath']);\r
 -\r
 -            // create destination folder if not exists\r
 -            if(!$view->file_exists(dirname($newShareKeyfilePath))) {\r
 -                $view->mkdir(dirname($newShareKeyfilePath), 0750, true);\r
 -            }\r
 -\r
 -            $view->rename($oldShareKeyfilePath, $newShareKeyfilePath);\r
 -        }\r
 -\r
 -        // Rename keyfile so it isn't orphaned\r
 -        if($view->file_exists($oldKeyfilePath)) {\r
 -\r
 -            // create destination folder if not exists\r
 -            if(!$view->file_exists(dirname($newKeyfilePath))) {\r
 -                $view->mkdir(dirname($newKeyfilePath), 0750, true);\r
 -            }\r
 -\r
 -            $view->rename($oldKeyfilePath, $newKeyfilePath);\r
 -        }\r
 -\r
 -        // build the path to the file\r
 -        $newPath = '/' . $userId . '/files' .$params['newpath'];\r
 -        $newPathRelative = $params['newpath'];\r
 -\r
 -        if($util->fixFileSize($newPath)) {\r
 -            // get sharing app state\r
 -            $sharingEnabled = \OCP\Share::isEnabled();\r
 -\r
 -            // get users\r
 -            $usersSharing = $util->getSharingUsersArray($sharingEnabled, $newPathRelative);\r
 -\r
 -            // update sharing-keys\r
 -            $util->setSharedFileKeyfiles($session, $usersSharing, $newPathRelative);\r
 -        }\r
 -\r
 -        \OC_FileProxy::$enabled = $proxyStatus;\r
 -    }\r
 +       * @brief after a file is renamed, rename its keyfile and share-keys also fix the file size and fix also the sharing\r
 +       * @param array with oldpath and newpath\r
 +       *\r
 +       * This function is connected to the rename signal of OC_Filesystem and adjust the name and location\r
 +       * of the stored versions along the actual file\r
 +       */\r
 +      public static function postRename($params) {\r
 +              // Disable encryption proxy to prevent recursive calls\r
 +              $proxyStatus = \OC_FileProxy::$enabled;\r
 +              \OC_FileProxy::$enabled = false;\r
 +\r
 +              $view = new \OC_FilesystemView('/');\r
-               $session = new Session($view);\r
++              $session = new \OCA\Encryption\Session($view);\r
 +              $userId = \OCP\User::getUser();\r
 +              $util = new Util($view, $userId);\r
 +\r
 +              // Format paths to be relative to user files dir\r
 +              $oldKeyfilePath = \OC\Files\Filesystem::normalizePath(\r
 +                      $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['oldpath']);\r
 +              $newKeyfilePath = \OC\Files\Filesystem::normalizePath(\r
 +                      $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['newpath']);\r
 +\r
 +              // add key ext if this is not an folder\r
 +              if (!$view->is_dir($oldKeyfilePath)) {\r
 +                      $oldKeyfilePath .= '.key';\r
 +                      $newKeyfilePath .= '.key';\r
 +\r
 +                      // handle share-keys\r
 +                      $localKeyPath = $view->getLocalFile($userId . '/files_encryption/share-keys/' . $params['oldpath']);\r
 +                      $matches = glob(preg_quote($localKeyPath) . '*.shareKey');\r
 +                      foreach ($matches as $src) {\r
 +                              $dst = \OC\Files\Filesystem::normalizePath(str_replace($params['oldpath'], $params['newpath'], $src));\r
 +\r
 +                              // create destination folder if not exists\r
 +                              if (!file_exists(dirname($dst))) {\r
 +                                      mkdir(dirname($dst), 0750, true);\r
 +                              }\r
 +\r
 +                              rename($src, $dst);\r
 +                      }\r
 +\r
 +              } else {\r
 +                      // handle share-keys folders\r
 +                      $oldShareKeyfilePath = \OC\Files\Filesystem::normalizePath(\r
 +                              $userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['oldpath']);\r
 +                      $newShareKeyfilePath = \OC\Files\Filesystem::normalizePath(\r
 +                              $userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['newpath']);\r
 +\r
 +                      // create destination folder if not exists\r
 +                      if (!$view->file_exists(dirname($newShareKeyfilePath))) {\r
 +                              $view->mkdir(dirname($newShareKeyfilePath), 0750, true);\r
 +                      }\r
 +\r
 +                      $view->rename($oldShareKeyfilePath, $newShareKeyfilePath);\r
 +              }\r
 +\r
 +              // Rename keyfile so it isn't orphaned\r
 +              if ($view->file_exists($oldKeyfilePath)) {\r
 +\r
 +                      // create destination folder if not exists\r
 +                      if (!$view->file_exists(dirname($newKeyfilePath))) {\r
 +                              $view->mkdir(dirname($newKeyfilePath), 0750, true);\r
 +                      }\r
 +\r
 +                      $view->rename($oldKeyfilePath, $newKeyfilePath);\r
 +              }\r
 +\r
 +              // build the path to the file\r
 +              $newPath = '/' . $userId . '/files' . $params['newpath'];\r
 +              $newPathRelative = $params['newpath'];\r
 +\r
 +              if ($util->fixFileSize($newPath)) {\r
 +                      // get sharing app state\r
 +                      $sharingEnabled = \OCP\Share::isEnabled();\r
 +\r
 +                      // get users\r
 +                      $usersSharing = $util->getSharingUsersArray($sharingEnabled, $newPathRelative);\r
 +\r
 +                      // update sharing-keys\r
 +                      $util->setSharedFileKeyfiles($session, $usersSharing, $newPathRelative);\r
 +              }\r
 +\r
 +              \OC_FileProxy::$enabled = $proxyStatus;\r
 +      }\r
  }\r
index 5ccf0d94d371a7eb9dcd7c9615d8379585dc6f8a,e381ecab5c311051f400350986662ed2e60eb5e5..11308612daf62edd88d77f5d1d3f0c1024ebdeb3
@@@ -100,21 -101,21 +100,21 @@@ class Proxy extends \OC_FileProxy 
         * @param $data
         * @return bool
         */
 -      public function preFile_put_contents( $path, &$data ) {
 +      public function preFile_put_contents($path, &$data) {
  
 -              if ( self::shouldEncrypt( $path ) ) {
 +              if (self::shouldEncrypt($path)) {
  
                        // Stream put contents should have been converted to fopen
 -                      if ( !is_resource( $data ) ) {
 +                      if (!is_resource($data)) {
  
                                $userId = \OCP\USER::getUser();
 -                              $view = new \OC_FilesystemView( '/' );
 -                              $util = new Util( $view, $userId );
 -                              $session = new \OCA\Encryption\Session( $view );
 +                              $view = new \OC_FilesystemView('/');
 +                              $util = new Util($view, $userId);
-                               $session = new Session($view);
++                              $session = new \OCA\Encryption\Session($view);
                                $privateKey = $session->getPrivateKey();
 -                              $filePath = $util->stripUserFilesPath( $path );
 +                              $filePath = $util->stripUserFilesPath($path);
                                // Set the filesize for userland, before encrypting
 -                              $size = strlen( $data );
 +                              $size = strlen($data);
  
                                // Disable encryption proxy to prevent recursive calls
                                $proxyStatus = \OC_FileProxy::$enabled;
                \OC_FileProxy::$enabled = false;
  
                // init session
-               $session = new Session($view);
 -              $session = new \OCA\Encryption\Session( $view );
++              $session = new \OCA\Encryption\Session($view);
  
                // If data is a catfile
                if (
 -                      Crypt::mode() == 'server'
 -                      && Crypt::isCatfileContent( $data )
 +                      Crypt::mode() === 'server'
 +                      && Crypt::isCatfileContent($data)
                ) {
  
 -                      $privateKey = $session->getPrivateKey( $userId );
 +                      $privateKey = $session->getPrivateKey($userId);
  
                        // Get the encrypted keyfile
 -                      $encKeyfile = Keymanager::getFileKey( $view, $userId, $relPath );
 +                      $encKeyfile = Keymanager::getFileKey($view, $userId, $relPath);
  
                        // Attempt to fetch the user's shareKey
 -                      $shareKey = Keymanager::getShareKey( $view, $userId, $relPath );
 +                      $shareKey = Keymanager::getShareKey($view, $userId, $relPath);
  
                        // Decrypt keyfile with shareKey
 -                      $plainKeyfile = Crypt::multiKeyDecrypt( $encKeyfile, $shareKey, $privateKey );
 +                      $plainKeyfile = Crypt::multiKeyDecrypt($encKeyfile, $shareKey, $privateKey);
  
 -                      $plainData = Crypt::symmetricDecryptFileContent( $data, $plainKeyfile );
 +                      $plainData = Crypt::symmetricDecryptFileContent($data, $plainKeyfile);
  
                } elseif (
-                       Crypt::mode() === 'server'
-                       && isset($_SESSION['legacyenckey'])
+                       Crypt::mode() == 'server'
 -                      &&\OC::$session->exists('legacyenckey')
 -                      && Crypt::isEncryptedMeta( $path )
++                      && \OC::$session->exists('legacyenckey')
 +                      && Crypt::isEncryptedMeta($path)
                ) {
 -                      $plainData = Crypt::legacyBlockDecrypt( $data, $session->getLegacyKey() );
 +                      $plainData = Crypt::legacyBlockDecrypt($data, $session->getLegacyKey());
                }
  
                \OC_FileProxy::$enabled = $proxyStatus;
                $proxyStatus = \OC_FileProxy::$enabled;
                \OC_FileProxy::$enabled = false;
  
 -              $view = new \OC_FilesystemView( '/' );
 -              $session = new \OCA\Encryption\Session( $view );
 +              $view = new \OC_FilesystemView('/');
-               $session = new Session($view);
++              $session = new \OCA\Encryption\Session($view);
                $userId = \OCP\User::getUser();
 -              $util = new Util( $view, $userId );
 +              $util = new Util($view, $userId);
  
                // Reformat path for use with OC_FSV
 -              $path_split = explode( '/', $path );
 -              $path_f = implode( '/', array_slice( $path_split, 3 ) );
 +              $path_split = explode('/', $path);
 +              $path_f = implode('/', array_slice($path_split, 3));
  
                // only if file is on 'files' folder fix file size and sharing
 -              if ( count($path_split) >= 2 && $path_split[2] == 'files' && $util->fixFileSize( $path ) ) {
 +              if (isset($path_split) && $path_split[2] === 'files' && $util->fixFileSize($path)) {
  
                        // get sharing app state
                        $sharingEnabled = \OCP\Share::isEnabled();
index dbf9a487995f2154d48cee2db476054cb9f4df69,d60c386fb1cb7d84b6418c9c9536cf7c8f293a4f..bff1737554b4bea7a231135ec6affc4d341a7fef
@@@ -103,9 -103,9 +103,9 @@@ class Session 
         *
         * @note this should only be set on login
         */
 -      public function setPrivateKey( $privateKey ) {
 +      public function setPrivateKey($privateKey) {
  
-               $_SESSION['privateKey'] = $privateKey;
+               \OC::$session->set('privateKey', $privateKey);
  
                return true;
  
         * @param $legacyKey
         * @return bool
         */
 -      public function setLegacyKey( $legacyKey ) {
 +      public function setLegacyKey($legacyKey) {
  
-               $_SESSION['legacyKey'] = $legacyKey;
+               \OC::$session->set('legacyKey', $legacyKey);
  
                return true;
        }
index 49e93730cd527cee748d5907aad40806446e7bd0,da8c2494139c5134644efe318583a7d5b2bd5983..072c52866445e91f7157a739ca2e939ccdc846b7
@@@ -223,18 -223,18 +223,18 @@@ 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->userId, $this->relPath);
  
                // If a keyfile already exists
 -              if ( $this->encKeyfile ) {
 +              if ($this->encKeyfile) {
  
-                       $session = new Session($this->rootView);
+                       $session = new \OCA\Encryption\Session( $this->rootView );
  
 -                      $privateKey = $session->getPrivateKey( $this->userId );
 +                      $privateKey = $session->getPrivateKey($this->userId);
  
 -                      $shareKey = Keymanager::getShareKey( $this->rootView, $this->userId, $this->relPath );
 +                      $shareKey = Keymanager::getShareKey($this->rootView, $this->userId, $this->relPath);
  
 -                      $this->plainKey = Crypt::multiKeyDecrypt( $this->encKeyfile, $shareKey, $privateKey );
 +                      $this->plainKey = Crypt::multiKeyDecrypt($this->encKeyfile, $shareKey, $privateKey);
  
                        return true;
  
index 840e37ddb26955cd08d19c5d34e62acb9696d0ad,6ffe31c9bb4fc61085f82e8de20a0b8ee9ab0e76..16a5e8d7653719f4a6996fa3a1bc36009b074266
@@@ -1417,10 -1417,10 +1417,10 @@@ class Util 
                foreach ($dirContent as $item) {
                        // get relative path from files_encryption/keyfiles/
                        $filePath = substr($item['path'], strlen('files_encryption/keyfiles'));
 -                      if ($item['type'] == 'dir') {
 +                      if ($item['type'] === 'dir') {
                                $this->addRecoveryKeys($filePath . '/');
                        } else {
-                               $session = new Session(new \OC_FilesystemView('/'));
+                               $session = new \OCA\Encryption\Session(new \OC_FilesystemView('/'));
                                $sharingEnabled = \OCP\Share::isEnabled();
                                $file = substr($filePath, 0, -4);
                                $usersSharing = $this->getSharingUsersArray($sharingEnabled, $file);
Simple merge