<?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 testDecryptAll()
 {
     $filename = "/decryptAll" . $this->getUniqueID() . ".txt";
     $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
     $userdir = $datadir . '/' . $this->userId . '/files/';
     $this->view->file_put_contents($this->userId . '/files/' . $filename, $this->dataShort);
     $fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
     $this->assertTrue($fileInfoEncrypted instanceof \OC\Files\FileInfo);
     $this->assertEquals($fileInfoEncrypted['encrypted'], 1);
     $encContent = file_get_contents($userdir . $filename);
     \OC_App::disable('files_encryption');
     $user = \OCP\User::getUser();
     $this->logoutHelper();
     $this->loginHelper($user, false, false, false);
     $content = file_get_contents($userdir . $filename);
     //content should be encrypted
     $this->assertSame($encContent, $content);
     // now we load the encryption app again
     \OC_App::loadApp('files_encryption');
     // init encryption app
     $params = array('uid' => \OCP\User::getUser(), 'password' => \OCP\User::getUser());
     $view = new \OC\Files\View('/');
     $util = new \OCA\Files_Encryption\Util($view, \OCP\User::getUser());
     $result = $util->initEncryption($params);
     $this->assertTrue($result instanceof \OCA\Files_Encryption\Session);
     $successful = $util->decryptAll();
     $this->assertTrue($successful);
     $this->logoutHelper();
     $this->loginHelper($user, false, false, false);
     // file should be unencrypted and fileInfo should contain the correct values
     $content = file_get_contents($userdir . $filename);
     // now we should get the plain data
     $this->assertSame($this->dataShort, $content);
     $fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
     $this->assertTrue($fileInfoUnencrypted instanceof \OC\Files\FileInfo);
     // check if mtime and etags unchanged
     $this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
     $this->assertSame($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
     // file should no longer be encrypted
     $this->assertEquals(0, $fileInfoUnencrypted['encrypted']);
     $backupPath = $this->getBackupPath('decryptAll');
     // check if the keys where moved to the backup location
     $this->assertTrue($this->view->is_dir($backupPath . '/keys'));
     $this->assertTrue($this->view->file_exists($backupPath . '/keys/' . $filename . '/fileKey'));
     $this->assertTrue($this->view->file_exists($backupPath . '/keys/' . $filename . '/' . $user . '.shareKey'));
     // cleanup
     $this->view->unlink($this->userId . '/files/' . $filename);
     $this->view->deleteAll($backupPath);
     \OC_App::enable('files_encryption');
 }