예제 #1
0
 /**
  * @param $path
  * @param $size
  * @return bool
  */
 public function postFileSize($path, $size)
 {
     $view = new \OC_FilesystemView('/');
     // if path is a folder do nothing
     if ($view->is_dir($path)) {
         return $size;
     }
     // get relative path
     $relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path);
     // if path is empty we cannot resolve anything
     if (empty($relativePath)) {
         return $size;
     }
     $fileInfo = false;
     // get file info from database/cache if not .part file
     if (!Keymanager::isPartialFilePath($path)) {
         $fileInfo = $view->getFileInfo($path);
     }
     // if file is encrypted return real file size
     if (is_array($fileInfo) && $fileInfo['encrypted'] === true) {
         $size = $fileInfo['unencrypted_size'];
     } else {
         // self healing if file was removed from file cache
         if (!is_array($fileInfo)) {
             $fileInfo = array();
         }
         $userId = \OCP\User::getUser();
         $util = new Util($view, $userId);
         $fixSize = $util->getFileSize($path);
         if ($fixSize > 0) {
             $size = $fixSize;
             $fileInfo['encrypted'] = true;
             $fileInfo['unencrypted_size'] = $size;
             // put file info if not .part file
             if (!Keymanager::isPartialFilePath($relativePath)) {
                 $view->putFileInfo($path, $fileInfo);
             }
         }
     }
     return $size;
 }
예제 #2
0
파일: proxy.php 프로젝트: hjimmy/owncloud
 /**
  * @param $path
  * @param $size
  * @return bool
  */
 public function postFileSize($path, $size, $fileInfo = null)
 {
     $view = new \OC_FilesystemView('/');
     $userId = Helper::getUser($path);
     $util = new Util($view, $userId);
     // if encryption is no longer enabled or if the files aren't migrated yet
     // we return the default file size
     if (!\OCP\App::isEnabled('files_encryption') || $util->getMigrationStatus() !== Util::MIGRATION_COMPLETED) {
         return $size;
     }
     // if path is a folder do nothing
     if ($view->is_dir($path)) {
         $proxyState = \OC_FileProxy::$enabled;
         \OC_FileProxy::$enabled = false;
         $fileInfo = $view->getFileInfo($path);
         \OC_FileProxy::$enabled = $proxyState;
         if (isset($fileInfo['unencrypted_size']) && $fileInfo['unencrypted_size'] > 0) {
             return $fileInfo['unencrypted_size'];
         }
         return $size;
     }
     // get relative path
     $relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path);
     // if path is empty we cannot resolve anything
     if (empty($relativePath)) {
         return $size;
     }
     // get file info from database/cache if not .part file
     if (empty($fileInfo) && !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
     if (isset($fileInfo['encrypted']) && $fileInfo['encrypted'] === true) {
         // try to fix unencrypted file size if it doesn't look plausible
         if ((int) $fileInfo['size'] > 0 && (int) $fileInfo['unencrypted_size'] === 0) {
             $fixSize = $util->getFileSize($path);
             $fileInfo['unencrypted_size'] = $fixSize;
             // put file info if not .part file
             if (!Helper::isPartialFilePath($relativePath)) {
                 $view->putFileInfo($path, $fileInfo);
             }
         }
         $size = $fileInfo['unencrypted_size'];
     } else {
         // self healing if file was removed from file cache
         if (!is_array($fileInfo)) {
             $fileInfo = array();
         }
         $fixSize = $util->getFileSize($path);
         if ($fixSize > 0) {
             $size = $fixSize;
             $fileInfo['encrypted'] = true;
             $fileInfo['unencrypted_size'] = $size;
             // put file info if not .part file
             if (!Helper::isPartialFilePath($relativePath)) {
                 $view->putFileInfo($path, $fileInfo);
             }
         }
     }
     return $size;
 }
예제 #3
0
파일: util.php 프로젝트: hjimmy/owncloud
 /**
  * @large
  */
 function testEncryptLegacyFiles()
 {
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER);
     $userView = new \OC_FilesystemView('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER);
     $view = new \OC_FilesystemView('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER . '/files');
     // Disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     $encryptionKeyContent = file_get_contents($this->legacyEncryptedDataKey);
     $userView->file_put_contents('/encryption.key', $encryptionKeyContent);
     $legacyEncryptedData = file_get_contents($this->legacyEncryptedData);
     $view->mkdir('/test/');
     $view->mkdir('/test/subtest/');
     $view->file_put_contents('/test/subtest/legacy-encrypted-text.txt', $legacyEncryptedData);
     $fileInfo = $view->getFileInfo('/test/subtest/legacy-encrypted-text.txt');
     $fileInfo['encrypted'] = true;
     $view->putFileInfo('/test/subtest/legacy-encrypted-text.txt', $fileInfo);
     \OC_FileProxy::$enabled = $proxyStatus;
     $params['uid'] = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER;
     $params['password'] = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER;
     $util = new Encryption\Util($this->view, \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER);
     $this->setMigrationStatus(0, \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER);
     $this->assertTrue(OCA\Encryption\Hooks::login($params));
     $this->assertEquals($this->legacyKey, \OC::$session->get('legacyKey'));
     $files = $util->findEncFiles('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER . '/files/');
     $this->assertTrue(is_array($files));
     $found = false;
     foreach ($files['encrypted'] as $encryptedFile) {
         if ($encryptedFile['name'] === 'legacy-encrypted-text.txt') {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found);
 }