From e79cc5fe0cfb68ebf3744522652039c29d46855a Mon Sep 17 00:00:00 2001 From: Sujith H Date: Thu, 8 Jun 2017 21:06:58 +0530 Subject: [PATCH] Transfer ownership work with masterkey This change helps users to get transfer-ownership command work when masterkey is enabled as mode of encryption. Signed-off-by: Sujith H --- apps/encryption/lib/Crypto/Encryption.php | 3 ++ apps/files/lib/Command/TransferOwnership.php | 8 +++++ lib/private/Files/Filesystem.php | 3 ++ .../Files/Storage/Wrapper/Encryption.php | 7 ++++ .../features/transfer-ownership.feature | 34 +++++++------------ 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/apps/encryption/lib/Crypto/Encryption.php b/apps/encryption/lib/Crypto/Encryption.php index 7f33e1d9a65e..ee8de0e8c145 100644 --- a/apps/encryption/lib/Crypto/Encryption.php +++ b/apps/encryption/lib/Crypto/Encryption.php @@ -558,6 +558,9 @@ protected function stripPartFileExtension($path) { * @since 9.1.0 */ public function isReadyForUser($user) { + if ($this->util->isMasterKeyEnabled() === true) { + return true; + } return $this->keyManager->userHasKeys($user); } } diff --git a/apps/files/lib/Command/TransferOwnership.php b/apps/files/lib/Command/TransferOwnership.php index 4adb24d8637c..85c5f898f894 100644 --- a/apps/files/lib/Command/TransferOwnership.php +++ b/apps/files/lib/Command/TransferOwnership.php @@ -194,6 +194,14 @@ function (FileInfo $fileInfo) use ($progress, $self) { $progress->advance(); $this->allFiles[] = $fileInfo; if ($fileInfo->isEncrypted()) { + if (\OC::$server->getAppConfig()->getValue('encryption', 'useMasterKey', 0) !== 0) { + /** + * We are not going to add this to encryptedFiles array. + * Because its encrypted with masterKey and hence it doesn't + * require user's specific password. + */ + return true; + } $this->encryptedFiles[] = $fileInfo; } return true; diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php index ba31bf53c818..f37816bc2bf6 100644 --- a/lib/private/Files/Filesystem.php +++ b/lib/private/Files/Filesystem.php @@ -944,6 +944,9 @@ public static function getDirectoryContent($directory, $mimetype_filter = '') { * @return string */ public static function getPath($id) { + if (self::$defaultInstance === null) { + throw new NotFoundException("defaultInstance is null"); + } return self::$defaultInstance->getPath($id); } diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 0bbe9e67d345..3b103979075f 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -672,6 +672,13 @@ private function updateEncryptedVersion(Storage $sourceStorage, $sourceInternalP // in case of a rename we need to manipulate the source cache because // this information will be kept for the new target if ($isRename) { + /* + * Rename is a process of creating a new file. So the version has to be 1. + * Instead of the reusing old version, we stick with version 1. This helps + * the data viewed in UI and helps resolve "Bad Signature". + */ + $encryptedVersion = 1; + $cacheInformation['encryptedVersion'] = $encryptedVersion; $sourceStorage->getCache()->put($sourceInternalPath, $cacheInformation); } else { $this->getCache()->put($targetInternalPath, $cacheInformation); diff --git a/tests/integration/features/transfer-ownership.feature b/tests/integration/features/transfer-ownership.feature index 686b74fb9b11..4a1d0490f820 100644 --- a/tests/integration/features/transfer-ownership.feature +++ b/tests/integration/features/transfer-ownership.feature @@ -1,7 +1,6 @@ Feature: transfer-ownership # TODO: change to @no_default_encryption once all this works with master key - @no_encryption Scenario: transfering ownership of a file Given user "user0" exists And user "user1" exists @@ -12,7 +11,19 @@ Feature: transfer-ownership And using received transfer folder of "user1" as dav path Then Downloaded content when downloading file "/somefile.txt" with range "bytes=0-6" should be "This is" - @no_encryption + Scenario: transfering ownership of a file after updating the file + Given user "user0" exists + And user "user1" exists + And User "user0" uploads file "data/file_to_overwrite.txt" to "/PARENT/textfile0.txt" + And User "user0" uploads file "data/file_to_overwrite.txt" to "/PARENT/textfile0.txt" + And User "user0" uploads file "data/file_to_overwrite.txt" to "/PARENT/textfile0.txt" + And User "user0" uploads file "data/file_to_overwrite.txt" to "/PARENT/textfile0.txt" + When transfering ownership from "user0" to "user1" + And the command was successful + And As an "user1" + And using received transfer folder of "user1" as dav path + Then Downloaded content when downloading file "/PARENT/textfile0.txt" with range "bytes=0-8" should be "BLABLABLA" + Scenario: transfering ownership of a folder Given user "user0" exists And user "user1" exists @@ -24,7 +35,6 @@ Feature: transfer-ownership And using received transfer folder of "user1" as dav path Then Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is" - @no_encryption Scenario: transfering ownership of file shares Given user "user0" exists And user "user1" exists @@ -36,7 +46,6 @@ Feature: transfer-ownership And As an "user2" Then Downloaded content when downloading file "/somefile.txt" with range "bytes=0-6" should be "This is" - @no_encryption Scenario: transfering ownership of folder shared with third user Given user "user0" exists And user "user1" exists @@ -49,7 +58,6 @@ Feature: transfer-ownership And As an "user2" Then Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is" - @no_encryption Scenario: transfering ownership of folder shared with transfer recipient Given user "user0" exists And user "user1" exists @@ -63,7 +71,6 @@ Feature: transfer-ownership And using received transfer folder of "user1" as dav path And Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is" - @no_encryption Scenario: transfering ownership of folder doubly shared with third user Given group "group1" exists And user "user0" exists @@ -79,7 +86,6 @@ Feature: transfer-ownership And As an "user2" Then Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is" - @no_encryption Scenario: transfering ownership does not transfer received shares Given user "user0" exists And user "user1" exists @@ -92,7 +98,6 @@ Feature: transfer-ownership And using received transfer folder of "user1" as dav path Then as "user1" the folder "/test" does not exist - @no_encryption @local_storage Scenario: transfering ownership does not transfer external storage Given user "user0" exists @@ -103,7 +108,6 @@ Feature: transfer-ownership And using received transfer folder of "user1" as dav path Then as "user1" the folder "/local_storage" does not exist - @no_encryption Scenario: transfering ownership does not fail with shared trashed files Given user "user0" exists And user "user1" exists @@ -115,21 +119,18 @@ Feature: transfer-ownership When transfering ownership from "user0" to "user1" Then the command was successful - @no_encryption Scenario: transfering ownership fails with invalid source user Given user "user0" exists When transfering ownership from "invalid_user" to "user0" Then the command error output contains the text "Unknown source user" And the command failed with exit code 1 - @no_encryption Scenario: transfering ownership fails with invalid target user Given user "user0" exists When transfering ownership from "user0" to "invalid_user" Then the command error output contains the text "Unknown target user" And the command failed with exit code 1 - @no_encryption Scenario: transfering ownership of a folder Given user "user0" exists And user "user1" exists @@ -141,7 +142,6 @@ Feature: transfer-ownership And using received transfer folder of "user1" as dav path Then Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is" - @no_encryption Scenario: transfering ownership of file shares Given user "user0" exists And user "user1" exists @@ -154,7 +154,6 @@ Feature: transfer-ownership And As an "user2" Then Downloaded content when downloading file "/somefile.txt" with range "bytes=0-6" should be "This is" - @no_encryption Scenario: transfering ownership of folder shared with third user Given user "user0" exists And user "user1" exists @@ -167,7 +166,6 @@ Feature: transfer-ownership And As an "user2" Then Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is" - @no_encryption Scenario: transfering ownership of folder shared with transfer recipient Given user "user0" exists And user "user1" exists @@ -181,7 +179,6 @@ Feature: transfer-ownership And using received transfer folder of "user1" as dav path And Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is" - @no_encryption Scenario: transfering ownership of folder doubly shared with third user Given group "group1" exists And user "user0" exists @@ -197,7 +194,6 @@ Feature: transfer-ownership And As an "user2" Then Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is" - @no_encryption Scenario: transfering ownership does not transfer received shares Given user "user0" exists And user "user1" exists @@ -212,7 +208,6 @@ Feature: transfer-ownership And using received transfer folder of "user1" as dav path Then as "user1" the folder "/sub/test" does not exist - @no_encryption @local_storage Scenario: transfering ownership does not transfer external storage Given user "user0" exists @@ -224,7 +219,6 @@ Feature: transfer-ownership And using received transfer folder of "user1" as dav path Then as "user1" the folder "/local_storage" does not exist - @no_encryption Scenario: transfering ownership fails with invalid source user Given user "user0" exists And User "user0" created a folder "/sub" @@ -232,7 +226,6 @@ Feature: transfer-ownership Then the command error output contains the text "Unknown source user" And the command failed with exit code 1 - @no_encryption Scenario: transfering ownership fails with invalid target user Given user "user0" exists And User "user0" created a folder "/sub" @@ -240,7 +233,6 @@ Feature: transfer-ownership Then the command error output contains the text "Unknown target user" And the command failed with exit code 1 - @no_encryption Scenario: transfering ownership fails with invalid path Given user "user0" exists And user "user1" exists