Exemple #1
0
 function testDescryptAllWithBrokenFiles()
 {
     $file1 = "/decryptAll1" . uniqid() . ".txt";
     $file2 = "/decryptAll2" . uniqid() . ".txt";
     $util = new Encryption\Util($this->view, $this->userId);
     $this->view->file_put_contents($this->userId . '/files/' . $file1, $this->dataShort);
     $this->view->file_put_contents($this->userId . '/files/' . $file2, $this->dataShort);
     $fileInfoEncrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
     $fileInfoEncrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
     $this->assertTrue(is_array($fileInfoEncrypted1));
     $this->assertTrue(is_array($fileInfoEncrypted2));
     $this->assertEquals($fileInfoEncrypted1['encrypted'], 1);
     $this->assertEquals($fileInfoEncrypted2['encrypted'], 1);
     // rename keyfile for file1 so that the decryption for file1 fails
     // Expected behaviour: decryptAll() returns false, file2 gets decrypted anyway
     $this->view->rename($this->userId . '/files_encryption/keyfiles/' . $file1 . '.key', $this->userId . '/files_encryption/keyfiles/' . $file1 . '.key.moved');
     // decrypt all encrypted files
     $result = $util->decryptAll('/' . $this->userId . '/' . 'files');
     $this->assertFalse($result);
     $fileInfoUnencrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
     $fileInfoUnencrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
     $this->assertTrue(is_array($fileInfoUnencrypted1));
     $this->assertTrue(is_array($fileInfoUnencrypted2));
     // file1 should be still encrypted; file2 should be decrypted
     $this->assertEquals(1, $fileInfoUnencrypted1['encrypted']);
     $this->assertEquals(0, $fileInfoUnencrypted2['encrypted']);
     // keyfiles and share keys should still exist
     $this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/keyfiles/'));
     $this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/share-keys/'));
     // rename the keyfile for file1 back
     $this->view->rename($this->userId . '/files_encryption/keyfiles/' . $file1 . '.key.moved', $this->userId . '/files_encryption/keyfiles/' . $file1 . '.key');
     // try again to decrypt all encrypted files
     $result = $util->decryptAll('/' . $this->userId . '/' . 'files');
     $this->assertTrue($result);
     $fileInfoUnencrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
     $fileInfoUnencrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
     $this->assertTrue(is_array($fileInfoUnencrypted1));
     $this->assertTrue(is_array($fileInfoUnencrypted2));
     // now both files should be decrypted
     $this->assertEquals(0, $fileInfoUnencrypted1['encrypted']);
     $this->assertEquals(0, $fileInfoUnencrypted2['encrypted']);
     // keyfiles and share keys should be deleted
     $this->assertFalse($this->view->is_dir($this->userId . '/files_encryption/keyfiles/'));
     $this->assertFalse($this->view->is_dir($this->userId . '/files_encryption/share-keys/'));
     $this->view->unlink($this->userId . '/files/' . $file1);
     $this->view->unlink($this->userId . '/files/' . $file2);
 }
Exemple #2
0
 function testDecryptAll()
 {
     $filename = "/decryptAll" . time() . ".txt";
     $util = new Encryption\Util($this->view, $this->userId);
     $this->view->file_put_contents($this->userId . '/files/' . $filename, $this->dataShort);
     $fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
     $this->assertTrue(is_array($fileInfoEncrypted));
     // encrypt all unencrypted files
     $util->decryptAll('/' . $this->userId . '/' . 'files');
     $fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
     $this->assertTrue(is_array($fileInfoUnencrypted));
     // check if mtime and etags unchanged
     $this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
     $this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
     $this->view->unlink($this->userId . '/files/' . $filename);
 }