From d86f8ba5f8718329fb0742be3e18f229c1f56a34 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 2 Mar 2016 11:27:29 +0100 Subject: [PATCH] if we don't have a encrypted file key we can return a empty string right away --- apps/encryption/lib/keymanager.php | 13 ++++---- .../tests/lib/crypto/encryptalltest.php | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/apps/encryption/lib/keymanager.php b/apps/encryption/lib/keymanager.php index 5cce760fa5..4f22c3def6 100644 --- a/apps/encryption/lib/keymanager.php +++ b/apps/encryption/lib/keymanager.php @@ -394,17 +394,20 @@ class KeyManager { public function getFileKey($path, $uid) { $encryptedFileKey = $this->keyStorage->getFileKey($path, $this->fileKeyId, Encryption::ID); + if (empty($encryptedFileKey)) { + return ''; + } + + if ($this->util->isMasterKeyEnabled()) { + $uid = $this->getMasterKeyId(); + } + if (is_null($uid)) { $uid = $this->getPublicShareKeyId(); $shareKey = $this->getShareKey($path, $uid); $privateKey = $this->keyStorage->getSystemUserKey($this->publicShareKeyId . '.privateKey', Encryption::ID); $privateKey = $this->crypt->decryptPrivateKey($privateKey); } else { - - if ($this->util->isMasterKeyEnabled()) { - $uid = $this->getMasterKeyId(); - } - $shareKey = $this->getShareKey($path, $uid); $privateKey = $this->session->getPrivateKey(); } diff --git a/apps/encryption/tests/lib/crypto/encryptalltest.php b/apps/encryption/tests/lib/crypto/encryptalltest.php index 837883fded..d31f58377c 100644 --- a/apps/encryption/tests/lib/crypto/encryptalltest.php +++ b/apps/encryption/tests/lib/crypto/encryptalltest.php @@ -153,6 +153,36 @@ class EncryptAllTest extends TestCase { } + public function testEncryptAllWithMasterKey() { + /** @var EncryptAll | \PHPUnit_Framework_MockObject_MockObject $encryptAll */ + $encryptAll = $this->getMockBuilder('OCA\Encryption\Crypto\EncryptAll') + ->setConstructorArgs( + [ + $this->setupUser, + $this->userManager, + $this->view, + $this->keyManager, + $this->util, + $this->config, + $this->mailer, + $this->l, + $this->questionHelper, + $this->secureRandom + ] + ) + ->setMethods(['createKeyPairs', 'encryptAllUsersFiles', 'outputPasswords']) + ->getMock(); + + $this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(true); + $encryptAll->expects($this->never())->method('createKeyPairs'); + $this->keyManager->expects($this->once())->method('validateMasterKey'); + $encryptAll->expects($this->at(0))->method('encryptAllUsersFiles')->with(); + $encryptAll->expects($this->never())->method('outputPasswords'); + + $encryptAll->encryptAll($this->inputInterface, $this->outputInterface); + + } + public function testCreateKeyPairs() { /** @var EncryptAll | \PHPUnit_Framework_MockObject_MockObject $encryptAll */ $encryptAll = $this->getMockBuilder('OCA\Encryption\Crypto\EncryptAll')