Skip to content

Commit

Permalink
Transfer ownership work with masterkey
Browse files Browse the repository at this point in the history
This change helps users to get transfer-ownership
command work when masterkey is enabled as mode
of encryption.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
  • Loading branch information
sharidas committed Jul 10, 2017
1 parent 8ab6a13 commit 5bd426b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
3 changes: 3 additions & 0 deletions apps/encryption/lib/Crypto/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
8 changes: 8 additions & 0 deletions apps/files/lib/Command/TransferOwnership.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Files/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 7 additions & 0 deletions lib/private/Files/Storage/Wrapper/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 13 additions & 21 deletions tests/integration/features/transfer-ownership.feature
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -224,23 +219,20 @@ 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"
When transfering ownership of path "sub" 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
And User "user0" created a folder "/sub"
When transfering ownership of path "sub" 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 fails with invalid path
Given user "user0" exists
And user "user1" exists
Expand Down

0 comments on commit 5bd426b

Please sign in to comment.