Skip to content
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

[stable13] reset encryptionVersion to '1' if a file was stream copied #9064

Merged
merged 1 commit into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/private/Files/Storage/Wrapper/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,21 +651,22 @@ public function copyFromStorage(Storage\IStorage $sourceStorage, $sourceInternal
* @param string $sourceInternalPath
* @param string $targetInternalPath
* @param bool $isRename
* @param bool $keepEncryptionVersion
*/
private function updateEncryptedVersion(Storage\IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename) {
$isEncrypted = $this->encryptionManager->isEnabled() && $this->shouldEncrypt($targetInternalPath) ? 1 : 0;
private function updateEncryptedVersion(Storage\IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename, $keepEncryptionVersion) {
$isEncrypted = $this->encryptionManager->isEnabled() && $this->shouldEncrypt($targetInternalPath);
$cacheInformation = [
'encrypted' => (bool)$isEncrypted,
'encrypted' => $isEncrypted,
];
if($isEncrypted === 1) {
if($isEncrypted) {
$encryptedVersion = $sourceStorage->getCache()->get($sourceInternalPath)['encryptedVersion'];

// In case of a move operation from an unencrypted to an encrypted
// storage the old encrypted version would stay with "0" while the
// correct value would be "1". Thus we manually set the value to "1"
// for those cases.
// See also https://github.com/owncloud/core/issues/23078
if($encryptedVersion === 0) {
if($encryptedVersion === 0 || !$keepEncryptionVersion) {
$encryptedVersion = 1;
}

Expand Down Expand Up @@ -713,7 +714,7 @@ private function copyBetweenStorage(Storage\IStorage $sourceStorage, $sourceInte
$info['size']
);
}
$this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename);
$this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename, true);
}
return $result;
}
Expand Down Expand Up @@ -756,7 +757,7 @@ private function copyBetweenStorage(Storage\IStorage $sourceStorage, $sourceInte
if ($preserveMtime) {
$this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
}
$this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename);
$this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename, false);
} else {
// delete partially written target file
$this->unlink($targetInternalPath);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Files/Storage/Wrapper/EncryptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryption
'encrypted' => $expectedEncrypted,
];
if($expectedEncrypted === true) {
$expectedCachePut['encryptedVersion'] = 12345;
$expectedCachePut['encryptedVersion'] = 1;
}

$this->arrayCache->expects($this->never())->method('set');
Expand Down