From 878bd4e41cbca724a2ebf30b9598a04f4ef3a5e1 Mon Sep 17 00:00:00 2001 From: Sujith H Date: Thu, 21 Sep 2017 19:14:57 +0530 Subject: [PATCH] Fix for decrypting user specific keys This change helps users to decrypt user specific keys. Signed-off-by: Sujith H --- lib/private/Encryption/DecryptAll.php | 13 +++++++++++-- tests/lib/Encryption/DecryptAllTest.php | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/private/Encryption/DecryptAll.php b/lib/private/Encryption/DecryptAll.php index 651b7ed436f0..b29ed08724c4 100644 --- a/lib/private/Encryption/DecryptAll.php +++ b/lib/private/Encryption/DecryptAll.php @@ -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.'); @@ -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++; } @@ -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)) { diff --git a/tests/lib/Encryption/DecryptAllTest.php b/tests/lib/Encryption/DecryptAllTest.php index aaa29a3738d6..73bffc8587e2 100644 --- a/tests/lib/Encryption/DecryptAllTest.php +++ b/tests/lib/Encryption/DecryptAllTest.php @@ -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) @@ -135,6 +138,8 @@ public function testDecryptAll($prepareResult, $user, $userExistsChecked) { } $instance->decryptAll($this->inputInterface, $this->outputInterface, $user); + + \OC::$server->getAppConfig()->deleteKey('encryption', 'useMasterKey'); } /**