From 38f8f2837e81f23eb12a005b7cf89efaf08a0fd3 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 15 Mar 2016 11:23:49 +0100 Subject: allow group shares, even if not all public keys are available --- apps/encryption/lib/crypto/encryption.php | 6 +++- .../encryption/tests/lib/crypto/encryptionTest.php | 38 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) (limited to 'apps') diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php index 1a05277e20d..85b1a781e89 100644 --- a/apps/encryption/lib/crypto/encryption.php +++ b/apps/encryption/lib/crypto/encryption.php @@ -349,7 +349,11 @@ class Encryption implements IEncryptionModule { $publicKeys[$this->keyManager->getMasterKeyId()] = $this->keyManager->getPublicMasterKey(); } else { foreach ($accessList['users'] as $user) { - $publicKeys[$user] = $this->keyManager->getPublicKey($user); + try { + $publicKeys[$user] = $this->keyManager->getPublicKey($user); + } catch (PublicKeyMissingException $e) { + $this->logger->warning('Could not encrypt file for ' . $user . ': ' . $e->getMessage()); + } } } diff --git a/apps/encryption/tests/lib/crypto/encryptionTest.php b/apps/encryption/tests/lib/crypto/encryptionTest.php index f76bdfb6d61..1652b578855 100644 --- a/apps/encryption/tests/lib/crypto/encryptionTest.php +++ b/apps/encryption/tests/lib/crypto/encryptionTest.php @@ -296,7 +296,6 @@ class EncryptionTest extends TestCase { $this->assertSame($expected, $this->instance->update('path', 'user1', ['users' => ['user1']]) ); - } public function dataTestUpdate() { @@ -306,6 +305,43 @@ class EncryptionTest extends TestCase { ); } + /** + * Test case if the public key is missing. ownCloud should still encrypt + * the file for the remaining users + */ + public function testUpdateMissingPublicKey() { + $this->keyManagerMock->expects($this->once()) + ->method('getFileKey')->willReturn('fileKey'); + + $this->keyManagerMock->expects($this->any()) + ->method('getPublicKey')->willReturnCallback( + function($user) { + throw new PublicKeyMissingException($user); + } + ); + + $this->keyManagerMock->expects($this->any()) + ->method('addSystemKeys') + ->willReturnCallback(function($accessList, $publicKeys) { + return $publicKeys; + }); + + $this->cryptMock->expects($this->once())->method('multiKeyEncrypt') + ->willReturnCallback( + function($fileKey, $publicKeys) { + $this->assertEmpty($publicKeys); + $this->assertSame('fileKey', $fileKey); + } + ); + + $this->keyManagerMock->expects($this->never())->method('getVersion'); + $this->keyManagerMock->expects($this->never())->method('setVersion'); + + $this->assertTrue( + $this->instance->update('path', 'user1', ['users' => ['user1']]) + ); + } + /** * by default the encryption module should encrypt regular files, files in * files_versions and files in files_trashbin -- cgit v1.2.3