Пример #1
0
 /**
  * notify encryption module about added/removed users from a file/folder
  *
  * @param string $path relative to data/
  * @throws Exceptions\ModuleDoesNotExistsException
  */
 public function update($path)
 {
     // if a folder was shared, get a list of all (sub-)folders
     if ($this->view->is_dir($path)) {
         $allFiles = $this->util->getAllFiles($path);
     } else {
         $allFiles = array($path);
     }
     $encryptionModule = $this->encryptionManager->getEncryptionModule();
     foreach ($allFiles as $file) {
         $usersSharing = $this->file->getAccessList($file);
         $encryptionModule->update($file, $this->uid, $usersSharing);
     }
 }
Пример #2
0
 /**
  * prepare encryption modules to perform the decrypt all function
  *
  * @param $user
  * @return bool
  */
 protected function prepareEncryptionModules($user)
 {
     // prepare all encryption modules for decrypt all
     $encryptionModules = $this->encryptionManager->getEncryptionModules();
     foreach ($encryptionModules as $moduleDesc) {
         /** @var IEncryptionModule $module */
         $module = call_user_func($moduleDesc['callback']);
         if ($module->prepareDecryptAll($this->input, $this->output, $user) === false) {
             $this->output->writeln('Module "' . $moduleDesc['displayName'] . '" does not support the functionality to decrypt all files again or the initialization of the module failed!');
             return false;
         }
     }
     return true;
 }
Пример #3
0
 /**
  * read encryption module needed to read/write the file located at $path
  *
  * @param string $path
  * @return null|\OCP\Encryption\IEncryptionModule
  * @throws ModuleDoesNotExistsException
  * @throws \Exception
  */
 protected function getEncryptionModule($path)
 {
     $encryptionModule = null;
     $header = $this->getHeader($path);
     $encryptionModuleId = $this->util->getEncryptionModuleId($header);
     if (!empty($encryptionModuleId)) {
         try {
             $encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId);
         } catch (ModuleDoesNotExistsException $e) {
             $this->logger->critical('Encryption module defined in "' . $path . '" not loaded!');
             throw $e;
         }
     }
     return $encryptionModule;
 }
Пример #4
0
 /**
  * update keyfiles and share keys recursively
  *
  * @param int $fileSource file source id
  */
 private function update($fileSource)
 {
     $path = \OC\Files\Filesystem::getPath($fileSource);
     $info = \OC\Files\Filesystem::getFileInfo($path);
     $owner = \OC\Files\Filesystem::getOwner($path);
     $view = new \OC\Files\View('/' . $owner . '/files');
     $ownerPath = $view->getPath($info->getId());
     $absPath = '/' . $owner . '/files' . $ownerPath;
     $mount = $this->mountManager->find($path);
     $mountPoint = $mount->getMountPoint();
     // if a folder was shared, get a list of all (sub-)folders
     if ($this->view->is_dir($absPath)) {
         $allFiles = $this->util->getAllFiles($absPath, $mountPoint);
     } else {
         $allFiles = array($absPath);
     }
     $encryptionModule = $this->encryptionManager->getDefaultEncryptionModule();
     foreach ($allFiles as $path) {
         $usersSharing = $this->file->getAccessList($path);
         $encryptionModule->update($path, $this->uid, $usersSharing);
     }
 }
Пример #5
0
	protected function addNewEncryptionModule(Manager $manager, $id) {
		$encryptionModule = $this->getMock('\OCP\Encryption\IEncryptionModule');
		$encryptionModule->expects($this->any())
			->method('getId')
			->willReturn('ID' . $id);
		$encryptionModule->expects($this->any())
			->method('getDisplayName')
			->willReturn('TestDummyModule' . $id);
		/** @var \OCP\Encryption\IEncryptionModule $encryptionModule */
		$manager->registerEncryptionModule('ID' . $id, 'TestDummyModule' . $id, function() use ($encryptionModule) {
			return $encryptionModule;
		});
	}
Пример #6
0
 public function testGetDefaultEncryptionModule()
 {
     $config = $this->getMock('\\OCP\\IConfig');
     $config->expects($this->any())->method('getAppValue')->willReturn(true);
     $em = $this->getMock('\\OCP\\Encryption\\IEncryptionModule');
     $em->expects($this->any())->method('getId')->willReturn(0);
     $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
     $m = new Manager($config);
     $m->registerEncryptionModule($em);
     $this->assertSame(1, count($m->getEncryptionModules()));
     $en0 = $m->getEncryptionModule(0);
     $this->assertEquals(0, $en0->getId());
 }