Esempio n. 1
0
 public function testRecoverFile()
 {
     $this->keyManagerMock->expects($this->once())->method('getEncryptedFileKey')->willReturn(true);
     $this->keyManagerMock->expects($this->once())->method('getShareKey')->willReturn(true);
     $this->cryptMock->expects($this->once())->method('multiKeyDecrypt')->willReturn(true);
     $this->fileMock->expects($this->once())->method('getAccessList')->willReturn(['users' => ['admin']]);
     $this->keyManagerMock->expects($this->once())->method('getPublicKey')->willReturn('publicKey');
     $this->keyManagerMock->expects($this->once())->method('addSystemKeys')->with($this->anything(), $this->anything(), $this->equalTo('admin'))->willReturn(['admin' => 'publicKey']);
     $this->cryptMock->expects($this->once())->method('multiKeyEncrypt');
     $this->keyManagerMock->expects($this->once())->method('setAllFileKeys');
     $this->assertNull(self::invokePrivate($this->instance, 'recoverFile', ['/', 'testkey', 'admin']));
 }
Esempio n. 2
0
 /**
  * recover file
  *
  * @param string $path
  * @param string $privateKey
  * @param string $uid
  */
 private function recoverFile($path, $privateKey, $uid)
 {
     $encryptedFileKey = $this->keyManager->getEncryptedFileKey($path);
     $shareKey = $this->keyManager->getShareKey($path, $this->keyManager->getRecoveryKeyId());
     if ($encryptedFileKey && $shareKey && $privateKey) {
         $fileKey = $this->crypt->multiKeyDecrypt($encryptedFileKey, $shareKey, $privateKey);
     }
     if (!empty($fileKey)) {
         $accessList = $this->file->getAccessList($path);
         $publicKeys = array();
         foreach ($accessList['users'] as $user) {
             $publicKeys[$user] = $this->keyManager->getPublicKey($user);
         }
         $publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $uid);
         $encryptedKeyfiles = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys);
         $this->keyManager->setAllFileKeys($path, $encryptedKeyfiles);
     }
 }