Skip to content

Commit

Permalink
Merge pull request #29189 from owncloud/decryptall-fix-stable10
Browse files Browse the repository at this point in the history
[stable10] Fix for decrypting user specific keys
  • Loading branch information
sharidas authored Oct 10, 2017
2 parents 2c9c7be + 352ce66 commit 1194518
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/private/Encryption/DecryptAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ public function decryptAll(InputInterface $input, OutputInterface $output, $user
}

$this->output->writeln('prepare encryption modules...');
if ($this->prepareEncryptionModules($user) === false) {
return false;
if (\OC::$server->getAppConfig()->getValue('encryption', 'useMasterKey', '0') !== '0') {
if ($this->prepareEncryptionModules($user) === false) {
return false;
}
}
$this->output->writeln(' done.');

Expand Down Expand Up @@ -183,6 +185,11 @@ protected function decryptAllUsersFiles($user = '') {
$userNo = 1;
foreach ($userList as $uid) {
$userCount = "$uid ($userNo of $numberOfUsers)";
if (\OC::$server->getAppConfig()->getValue('encryption', 'userSpecificKey', '0') !== '0') {
if ($this->prepareEncryptionModules($uid) === false) {
return false;
}
}
$this->decryptUsersFiles($uid, $progress, $userCount);
$userNo++;
}
Expand Down Expand Up @@ -255,7 +262,9 @@ protected function decryptFile($path) {
$target = $path . '.decrypted.' . $this->getTimestamp();

try {
\OC\Files\Storage\Wrapper\Encryption::setDisableWriteEncryption(true);
$this->rootView->copy($source, $target);
\OC\Files\Storage\Wrapper\Encryption::setDisableWriteEncryption(false);
$this->rootView->rename($target, $source);
} catch (DecryptionFailedException $e) {
if ($this->rootView->file_exists($target)) {
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/Encryption/DecryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public function testDecryptAll($prepareResult, $user, $userExistsChecked) {
->setMethods(['prepareEncryptionModules', 'decryptAllUsersFiles'])
->getMock();

\OC::$server->getAppConfig()->setValue('encryption', 'useMasterKey', '1');

$instance->expects($this->once())
->method('prepareEncryptionModules')
->with($user)
Expand All @@ -135,6 +137,8 @@ public function testDecryptAll($prepareResult, $user, $userExistsChecked) {
}

$instance->decryptAll($this->inputInterface, $this->outputInterface, $user);

\OC::$server->getAppConfig()->deleteKey('encryption', 'useMasterKey');
}

/**
Expand Down

0 comments on commit 1194518

Please sign in to comment.