<?php

OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
//encryption app needs to be loaded
OC_App::loadApp('files_encryption');
// init encryption app
$params = array('uid' => \OCP\User::getUser(), 'password' => (string) $_POST['password']);
$view = new OC\Files\View('/');
$util = new \OCA\Files_Encryption\Util($view, \OCP\User::getUser());
$l = \OC::$server->getL10N('settings');
$result = $util->initEncryption($params);
if ($result !== false) {
    try {
        $successful = $util->decryptAll();
    } catch (\Exception $ex) {
        \OCP\Util::writeLog('encryption library', "Decryption finished unexpected: " . $ex->getMessage(), \OCP\Util::ERROR);
        $successful = false;
    }
    $util->closeEncryptionSession();
    if ($successful === true) {
        \OCP\JSON::success(array('data' => array('message' => $l->t('Files decrypted successfully'))));
    } else {
        \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t decrypt your files, please check your owncloud.log or ask your administrator'))));
    }
} else {
    \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t decrypt your files, check your password and try again'))));
}
示例#2
0
 function testDescryptAllWithBrokenFiles()
 {
     $file1 = "/decryptAll1" . $this->getUniqueID() . ".txt";
     $file2 = "/decryptAll2" . $this->getUniqueID() . ".txt";
     $util = new \OCA\Files_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($fileInfoEncrypted1 instanceof \OC\Files\FileInfo);
     $this->assertTrue($fileInfoEncrypted2 instanceof \OC\Files\FileInfo);
     $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/keys/' . $file1 . '/fileKey', $this->userId . '/files_encryption/keys/' . $file1 . '/fileKey.moved');
     // need to reset key cache that we don't use the cached key
     $this->resetKeyCache();
     // decrypt all encrypted files
     $result = $util->decryptAll();
     $this->assertFalse($result);
     $fileInfoUnencrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
     $fileInfoUnencrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
     $this->assertTrue($fileInfoUnencrypted1 instanceof \OC\Files\FileInfo);
     $this->assertTrue($fileInfoUnencrypted2 instanceof \OC\Files\FileInfo);
     // 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/keys/'));
     $this->assertTrue($this->view->file_exists($this->userId . '/files_encryption/keys/' . $file1 . '/fileKey.moved'));
     $this->assertTrue($this->view->file_exists($this->userId . '/files_encryption/keys/' . $file1 . '/' . $this->userId . '.shareKey'));
     // rename the keyfile for file1 back
     $this->view->rename($this->userId . '/files_encryption/keys/' . $file1 . '/fileKey.moved', $this->userId . '/files_encryption/keys/' . $file1 . '/fileKey');
     // try again to decrypt all encrypted files
     $result = $util->decryptAll();
     $this->assertTrue($result);
     $fileInfoUnencrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
     $fileInfoUnencrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
     $this->assertTrue($fileInfoUnencrypted1 instanceof \OC\Files\FileInfo);
     $this->assertTrue($fileInfoUnencrypted2 instanceof \OC\Files\FileInfo);
     // 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/keys/'));
     //cleanup
     $backupPath = $this->getBackupPath('decryptAll');
     $this->view->unlink($this->userId . '/files/' . $file1);
     $this->view->unlink($this->userId . '/files/' . $file2);
     $this->view->deleteAll($backupPath);
 }