Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not also do the check on "useMasterKey" here for consistency ? please decide on one condition

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for not adding "useMasterKey" here is because we already do a check here: https://github.com/owncloud/core/pull/29072/files#diff-6f510adb432497f4f6a446f791729c79R93.
If "userSpecificKey" is enabled, then idea here is that we get the user and we pass it to method prepareEncryptionModules. For "userSpecificKey" the decryption was failing because we relied on https://github.com/owncloud/core/blob/master/lib/private/Encryption/DecryptAll.php#L93

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
5 changes: 5 additions & 0 deletions tests/lib/Encryption/DecryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ 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 +138,8 @@ public function testDecryptAll($prepareResult, $user, $userExistsChecked) {
}

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

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

/**
Expand Down