Skip to content

Feat/storage based encryption key location 2 10.9 #40893

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

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4e94ef8
Prevent encrypted files from being corrupted when overwriting them
JammingBen Dec 28, 2021
f65e6f0
Add changelog item for #39623
JammingBen Dec 28, 2021
b30ff05
Fix getHeader unit tests
JammingBen Dec 28, 2021
636258d
Move changelog item #39623 to the released folder
JammingBen Dec 28, 2021
92f779c
Bump version in version.php
micbar Dec 28, 2021
5627304
Update CHANGELOG
micbar Dec 29, 2021
35d97bf
Fix getting the file owner for share recipients
JammingBen Jan 10, 2022
6f651a0
Fix issue with wrong version authors being saved
JammingBen Jan 11, 2022
35261dd
Merge pull request #39670 from owncloud/issues/39662
JammingBen Jan 11, 2022
c1a7b23
Merge pull request #39673 from owncloud/issues/39672
JammingBen Jan 11, 2022
b1e97b8
bump version to 10.9.1 RC2
jnweiger Jan 11, 2022
99f5cb9
Rename the last changelog folder, so that calens gets the date right,…
jnweiger Jan 12, 2022
9ba23c2
bump version for final, update changelog via calens
jnweiger Jan 12, 2022
515d81b
updated CHANGELOG via calens
jnweiger Jan 12, 2022
faae8d8
feat: encryption keys location can be specified by the storage implem…
DeepDiver1975 Aug 3, 2021
9d0ea82
feat: decrypt the stream of a file version as returned by IVersionedS…
DeepDiver1975 Aug 26, 2021
254e793
fix: encryption storage wrapper will only delete keys if the storage …
DeepDiver1975 Oct 22, 2021
ff070d0
Add unit tests for versioned storage methods
JammingBen Oct 26, 2021
e9106fe
fix: handle encryption keys with trashbin
DeepDiver1975 Oct 26, 2021
b67b159
feat: add before_moveToTrash hook + add fileId to delete hook
DeepDiver1975 Oct 29, 2021
bad33e0
feat: adding new storage method getFileKey
DeepDiver1975 Oct 29, 2021
db2e52c
feat: adding new storage method setFileKey
DeepDiver1975 Nov 17, 2021
4da52be
fix: trashbin pre_restore hook and encryption version on move
DeepDiver1975 Nov 26, 2021
746b8e8
feat: versioned storages are expected to handle retainVersions themse…
DeepDiver1975 Dec 7, 2021
c8bf2da
fix: handle file rename properly
DeepDiver1975 Feb 14, 2022
4c17c69
feat: copy trashed items to all owner trash bins
DeepDiver1975 Mar 7, 2022
3bc27db
feat: detect collisions of mounts wit local files
DeepDiver1975 Mar 23, 2022
36d31a9
feat: add absolute paths to rename hook
DeepDiver1975 Jun 7, 2022
53543f1
fix: remove just uploaded files in case of error - also for storages …
DeepDiver1975 Jul 25, 2023
6ebf40b
fix: better error handling on file upload
DeepDiver1975 Jul 26, 2023
9f3069a
test: cleanup after failed upload
DeepDiver1975 Aug 1, 2023
2d6c6bf
fix: also cleanup file cache on failed uploads
DeepDiver1975 Aug 2, 2023
f9b76f6
fix: use empty() to check if header exists (port #40856)
DeepDiver1975 Aug 4, 2023
23ae2da
feat: make restore abortable from within pre_restore (#41316)
IljaN Sep 5, 2024
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
176 changes: 157 additions & 19 deletions CHANGELOG.html

Large diffs are not rendered by default.

43 changes: 42 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
Changelog for ownCloud Core [10.9.0] (2021-12-20)
Changelog for ownCloud Core [10.9.1] (2022-01-12)
=======================================
The following sections list the changes in ownCloud core 10.9.1 relevant to
ownCloud admins and users.

[10.9.1]: https://github.com/owncloud/core/compare/v10.9.0...v10.9.1

Summary
-------

* Bugfix - Prevent encrypted files from being corrupted when overwriting them: [#39623](https://github.com/owncloud/core/pull/39623)
* Bugfix - Getting the file owner for share recipients: [#39670](https://github.com/owncloud/core/pull/39670)
* Bugfix - Prevent version author from being overwritten with wrong uid: [#39673](https://github.com/owncloud/core/pull/39673)

Details
-------

* Bugfix - Prevent encrypted files from being corrupted when overwriting them: [#39623](https://github.com/owncloud/core/pull/39623)

Fixed an issue where overwriting an encrypted file by a share recipient would corrupt it. This
is a regression which was introduced by #39516.

https://github.com/owncloud/encryption/issues/315
https://github.com/owncloud/core/pull/39623

* Bugfix - Getting the file owner for share recipients: [#39670](https://github.com/owncloud/core/pull/39670)

Fixed a bug where a wrong file owner was retrieved when saving version authors. This scenario
happened for share recipients if they had a file with the same name as the shared file.

https://github.com/owncloud/core/issues/39662
https://github.com/owncloud/core/pull/39670

* Bugfix - Prevent version author from being overwritten with wrong uid: [#39673](https://github.com/owncloud/core/pull/39673)

Fixed an issue where restoring a previous version could lead to a wrong version author being
saved, basically overwriting the correct author.

https://github.com/owncloud/core/issues/39672
https://github.com/owncloud/core/pull/39673

Changelog for ownCloud Core [10.9.0] (2021-12-09)
=======================================
The following sections list the changes in ownCloud core 10.9.0 relevant to
ownCloud admins and users.
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ changelog:
@echo This file is autogenerated on the master branch.
@echo Committing changes to this file will result in merge conflicts.
@echo ======================================================================
docker run --rm -v $(work_dir):$(work_dir) -w $(work_dir) toolhippie/calens >| CHANGELOG.md
docker run --rm -v $(work_dir):$(work_dir) -w $(work_dir) toolhippie/calens -t changelog/CHANGELOG-html.tmpl >| CHANGELOG.html
docker run --rm -v $(work_dir):$(work_dir) -w $(work_dir) toolhippie/calens calens >| CHANGELOG.md
docker run --rm -v $(work_dir):$(work_dir) -w $(work_dir) toolhippie/calens calens -t changelog/CHANGELOG-html.tmpl >| CHANGELOG.html

#
# Dependency management
Expand Down
36 changes: 24 additions & 12 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ public function put($data) {
try {
$this->changeLock(ILockingProvider::LOCK_EXCLUSIVE);
} catch (LockedException $e) {
if ($usePartFile) {
$partStorage->unlink($internalPartPath);
}
$this->cleanFailedUpload($partStorage, $internalPartPath);
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
}

Expand Down Expand Up @@ -237,9 +235,7 @@ public function put($data) {
}
}
} catch (\Exception $e) {
if ($usePartFile) {
$partStorage->unlink($internalPartPath);
}
$this->cleanFailedUpload($partStorage, $internalPartPath);
$this->convertToSabreException($e);
}

Expand All @@ -258,9 +254,7 @@ public function put($data) {
try {
$this->changeLock(ILockingProvider::LOCK_EXCLUSIVE);
} catch (LockedException $e) {
if ($usePartFile) {
$partStorage->unlink($internalPartPath);
}
$this->cleanFailedUpload($partStorage, $internalPartPath);
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
}

Expand Down Expand Up @@ -604,9 +598,7 @@ private function createFileChunked($data) {
}
return $etag;
} catch (\Exception $e) {
if ($partFile !== null) {
$targetStorage->unlink($targetInternalPath);
}
$this->cleanFailedUpload($targetStorage, $targetInternalPath);
$this->convertToSabreException($e);
}
}
Expand Down Expand Up @@ -738,4 +730,24 @@ protected function header($string) {
public function getNode() {
return \OC::$server->getRootFolder()->get($this->getFileInfo()->getPath());
}

private function cleanFailedUpload(Storage $partStorage, $internalPartPath): void {
if ($partStorage->file_exists($internalPartPath)) {
try {
# broken/uncompleted uploaded files shall not go into trash-bin
if (class_exists(\OCA\Files_Trashbin\Storage::class)) {
\OCA\Files_Trashbin\Storage::$disableTrash = true;
}
# delete file from storage
$partStorage->unlink($internalPartPath);
# delete file from cache
$partStorage->getCache()->remove($internalPartPath);

} finally {
if (class_exists(\OCA\Files_Trashbin\Storage::class)) {
\OCA\Files_Trashbin\Storage::$disableTrash = false;
}
}
}
}
}
73 changes: 73 additions & 0 deletions apps/dav/tests/unit/Upload/FailedUploadTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @copyright Copyright (c) 2023, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\DAV\Tests\unit\Upload;

use OC\Files\FileInfo;
use OC\Files\View;
use OCA\DAV\Connector\Sabre\File;
use OCP\Lock\ILockingProvider;
use Sabre\DAV\Exception\BadRequest;
use Test\TestCase;
use Test\Traits\UserTrait;

/**
* @group DB
*/
class FailedUploadTest extends TestCase {
use UserTrait;

public function test(): void {
# init
$user = $this->createUser('user');
$folder = \OC::$server->getUserFolder($user->getUID());

# fake request
$_SERVER['CONTENT_LENGTH'] = 12;
$_SERVER['REQUEST_METHOD'] = 'PUT';
unset($_SERVER['HTTP_OC_CHUNKED']);

# perform the request
$path = '/test.txt';
$info = new FileInfo("user/files/$path", null, null, [], null);
$view = new View();
$file = new File($view, $info);
$file->acquireLock(ILockingProvider::LOCK_SHARED);
$stream = fopen('data://text/plain,' . '123456', 'rb');
try {
$file->put($stream);
} catch (BadRequest $e) {
self::assertEquals('expected filesize 12 got 6', $e->getMessage());
}

# assert file does not exist
self::assertFalse($folder->nodeExists($path));
# ensure folder can ge listed
$children = $folder->getDirectoryListing();
self::assertCount(0, $children);

# assert there is no file on disk
$internalPath = $folder->getInternalPath();
self::assertFalse($folder->getStorage()->file_exists($internalPath.'/test.txt'));

# assert file is not in cache
self::assertFalse($folder->getStorage()->getCache()->inCache($internalPath.'/test.txt'));
}
}
3 changes: 2 additions & 1 deletion apps/files/js/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -1291,8 +1291,9 @@ OC.Uploader.prototype = _.extend({
var message = '';
if (upload) {
var response = upload.getResponse();
message = response.message;
message = t('files', 'Failed to upload the file "{fileName}": {error}', {fileName: upload.getFileName(), error: response.message});
}

OC.Notification.show(message || data.errorThrown, {type: 'error'});
}

Expand Down
2 changes: 2 additions & 0 deletions apps/files_sharing/lib/Controller/Share20OcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ protected function formatShare(IShare $share, $received = false) {
* Get a specific share by id
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $id
* @return Result
Expand Down Expand Up @@ -664,6 +665,7 @@ private function getSharedWithMe($node = null, $includeTags, $requestedShareType
* the function will return an empty list.
*
* @NoAdminRequired
* @NoCSRFRequired
*
* - Get shares by the current user
* - Get shares by the current user and reshares (?reshares=true)
Expand Down
5 changes: 4 additions & 1 deletion apps/files_trashbin/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ class Storage extends Wrapper {
/**
* Disable trash logic
*
* NOTE: this public for a very specific purpose to handle broken uploads.
* Don't touch this property unless you know what this is doing! :dancers:
*
* @var bool
*/
private static $disableTrash = false;
public static $disableTrash = false;

/** @var IUserManager */
private $userManager;
Expand Down
Loading