-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transfer ownership work with masterkey #28107
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is one solution I found to get rid of the fatal error thrown by symfony. Any suggestions how to improve this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
when exactly is this happening ? when running CI ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When integration test is executed. |
||
} | ||
return self::$defaultInstance->getPath($id); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,7 +246,7 @@ public function unlink($path) { | |
return $this->storage->unlink($path); | ||
} | ||
|
||
$encryptionModule = $this->getEncryptionModule($path); | ||
$encryptionModule = ($this->encryptionManager->isEnabled()) ? $this->getEncryptionModule($path) : ""; | ||
if ($encryptionModule) { | ||
$this->keyStorage->deleteAllFileKeys($this->getFullPath($path)); | ||
} | ||
|
@@ -358,11 +358,12 @@ public function copy($path1, $path2) { | |
* | ||
* @param string $path | ||
* @param string $mode | ||
* @param string|null $sourceFileOfRename | ||
* @return resource|bool | ||
* @throws GenericEncryptionException | ||
* @throws ModuleDoesNotExistsException | ||
*/ | ||
public function fopen($path, $mode) { | ||
public function fopen($path, $mode, $sourceFileOfRename = null) { | ||
|
||
// check if the file is stored in the array cache, this means that we | ||
// copy a file over to the versions folder, in this case we don't want to | ||
|
@@ -378,7 +379,7 @@ public function fopen($path, $mode) { | |
$header = $this->getHeader($path); | ||
$signed = (isset($header['signed']) && $header['signed'] === 'true') ? true : false; | ||
$fullPath = $this->getFullPath($path); | ||
$encryptionModuleId = $this->util->getEncryptionModuleId($header); | ||
$encryptionModuleId = ($encryptionEnabled) ? $this->util->getEncryptionModuleId($header): ""; | ||
|
||
if ($this->util->isExcluded($fullPath) === false) { | ||
|
||
|
@@ -457,7 +458,7 @@ public function fopen($path, $mode) { | |
} | ||
$handle = \OC\Files\Stream\Encryption::wrap($source, $path, $fullPath, $header, | ||
$this->uid, $encryptionModule, $this->storage, $this, $this->util, $this->fileHelper, $mode, | ||
$size, $unencryptedSize, $headerSize, $signed); | ||
$size, $unencryptedSize, $headerSize, $signed, $sourceFileOfRename); | ||
return $handle; | ||
} | ||
|
||
|
@@ -569,7 +570,7 @@ protected function fixUnencryptedSize($path, $size, $unencryptedSize) { | |
fclose($stream); | ||
|
||
// we have to decrypt the last chunk to get it actual size | ||
$encryptionModule->begin($this->getFullPath($path), $this->uid, 'r', $header, []); | ||
$encryptionModule->begin($this->getFullPath($path), $this->uid, 'r', $header, [], null); | ||
$decryptedLastChunk = $encryptionModule->decrypt($lastChunkContentEncrypted, $lastChunkNr . 'end'); | ||
$decryptedLastChunk .= $encryptionModule->end($this->getFullPath($path), $lastChunkNr . 'end'); | ||
|
||
|
@@ -672,6 +673,12 @@ 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. Here we try to use the | ||
* incremented version of source file, for the destination file. | ||
*/ | ||
$encryptedVersion = $sourceStorage->getCache()->get($sourceInternalPath)['encryptedVersion']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modified this change. Trivial change. There was failure in couple of tests : apps/files_trashbin/tests/StorageTest.php and apps/files_trashbin/tests/TrashbinTest.php |
||
$cacheInformation['encryptedVersion'] = $encryptedVersion + 1; | ||
$sourceStorage->getCache()->put($sourceInternalPath, $cacheInformation); | ||
} else { | ||
$this->getCache()->put($targetInternalPath, $cacheInformation); | ||
|
@@ -690,7 +697,6 @@ private function updateEncryptedVersion(Storage $sourceStorage, $sourceInternalP | |
* @throws \Exception | ||
*/ | ||
private function copyBetweenStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename) { | ||
|
||
// for versions we have nothing to do, because versions should always use the | ||
// key from the original file. Just create a 1:1 copy and done | ||
if ($this->isVersion($targetInternalPath) || | ||
|
@@ -740,7 +746,12 @@ private function copyBetweenStorage(Storage $sourceStorage, $sourceInternalPath, | |
} else { | ||
try { | ||
$source = $sourceStorage->fopen($sourceInternalPath, 'r'); | ||
$target = $this->fopen($targetInternalPath, 'w'); | ||
if ($isRename) { | ||
$absSourcePath = Filesystem::normalizePath($sourceStorage->getOwner($sourceInternalPath). '/' . $sourceInternalPath); | ||
$target = $this->fopen($targetInternalPath, 'w', $absSourcePath); | ||
} else { | ||
$target = $this->fopen($targetInternalPath, 'w'); | ||
} | ||
list(, $result) = \OC_Helper::streamCopy($source, $target); | ||
fclose($source); | ||
fclose($target); | ||
|
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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intention behind this test is:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the file updated three times. All you do is upload three separate pieces of the file. This doesn't increase the encryption version of the final file. You need to upload 3 times. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. Will upload the same file 3 times. And then check the value in the file after download. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated the feature by uploading same file 4 times. Before doing this, I had verified in the UI. When tried to update same file multiple times, the encrypted version was incremented. |
||
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 chunk file "1" of "3" with "AA" to "/PARENT/textfile0.txt" | ||
And user "user0" uploads chunk file "2" of "3" with "BB" to "/PARENT/textfile0.txt" | ||
And user "user0" uploads chunk file "3" of "3" with "CC" to "/PARENT/textfile0.txt" | ||
When transfering ownership from "user0" to "user1" | ||
Then 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-5" should be "AABBCC" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This 'Then' has to be 'And'. (there can be only one then) |
||
|
||
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,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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that in general the transfer ownership app isn't supposed to know about specific encryption implementations.
Some people might implement their own custom encryption schemes, so would need a better abstraction.
But as we likely don't have time for better abstractions let's merge this.