Skip to content

Encryption - fix moving/copying files between storages - #15628

Merged
schiessle merged 3 commits into
masterfrom
enc_fix_rename
May 6, 2015
Merged

schiessle merged 3 commits into
masterfrom
enc_fix_rename

Conversation

@schiessle

Copy link
Copy Markdown
Contributor

Fix move/copy files between different storages.

fix #15963 (see the issue for concrete steps to test it)

cc @PVince81

Ignore the failing tests, Jenkins doesn't like this branch any more... passing tests are here: #16046

@schiessle schiessle added this to the 8.1-current milestone Apr 15, 2015
@schiessle schiessle changed the title Enc fix rename Encryption - fix moving/cvopying files between storages Apr 15, 2015
@schiessle schiessle changed the title Encryption - fix moving/cvopying files between storages Encryption - fix moving/copying files between storages Apr 15, 2015

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that you rewrote your own copyFromStorage ?
Does this operate only on keys or on the real storage ?

CC @icewind1991

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This operates on the real storage. We need this in order not to bypass the encryption wrapper for the target in line 355. Otherwise we will not write the file encrypted to the target.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to find a better way.
I'm worried not only about code duplication from https://github.com/owncloud/core/blob/master/lib/private/files/storage/common.php#L536 but also there's a risk that if someone fixes common.php, that this class here would be forgotten.

@icewind1991 can you advise on an alternative approach ?
We could move the copy logic into a separate utility method that can be called by both somehow ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is possible to call fopen here https://github.com/owncloud/core/blob/master/lib/private/files/storage/common.php#L548 in a way that it will go again through all wrappers? But I don't know how this could be done if you are already down at the storage level.

@PVince81

Copy link
Copy Markdown
Contributor
  • BUG: move file from non-encrypted ext storage to encrypted ext storage fails with WebDAV (works on master):
    1. Mount two SFTP storages, "/SFTP" and "/SFTP2"
    2. For "/SFTP2", disable encryption
    3. With cadaver, upload a picture to "/SFTP2"
    4. With cadaver, move the picture to "/SFTP"

Getting this:

{"reqId":"LLnalEMm4RCjGa9D12z9","remoteAddr":"127.0.0.1","app":"webdav","message":"Exception: {\"Message\":\"path needs to be relative to the system wide data folder and point to a user specific file\",\"Code\":0,\"Trace\":\"#0 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/encryption\\\/file.php(44): OC\\\\Encryption\\\\Util->getUidAndFilename('.')\\n#1 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/stream\\\/encryption.php(239): OC\\\\Encryption\\\\File->getAccessList('.')\\n#2 [internal function]: OC\\\\Files\\\\Stream\\\\Encryption->stream_open('ocencryption:\\\/\\\/', 'w', 0, NULL)\\n#3 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/stream\\\/encryption.php(178): fopen('ocencryption:\\\/\\\/', 'w', false, Resource id #437)\\n#4 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/stream\\\/encryption.php(160): OC\\\\Files\\\\Stream\\\\Encryption::wrapSource(Resource id #433, 'w', Resource id #437, 'ocencryption', 'OC\\\\\\\\Files\\\\\\\\Stream...')\\n#5 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/storage\\\/wrapper\\\/encryption.php(308): OC\\\\Files\\\\Stream\\\\Encryption::wrap(Resource id #433, 'Huoguo.jpg', '\\\/root\\\/files\\\/SFT...', Array, 'root', Object(OCA\\\\Encryption\\\\Crypto\\\\Encryption), Object(OCA\\\\Files_Trashbin\\\\Storage), Object(OC\\\\Files\\\\Storage\\\\Wrapper\\\\Encryption), Object(OC\\\\Encryption\\\\Util), Object(OC\\\\Encryption\\\\File), 'w', 0, 0)\\n#6 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/storage\\\/wrapper\\\/encryption.php(355): OC\\\\Files\\\\Storage\\\\Wrapper\\\\Encryption->fopen('Huoguo.jpg', 'w')\\n#7 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/storage\\\/wrapper\\\/encryption.php(323): OC\\\\Files\\\\Storage\\\\Wrapper\\\\Encryption->copyFromStorage(Object(OC\\\\Files\\\\Storage\\\\Wrapper\\\\Encryption), 'Huoguo.jpg', 'Huoguo.jpg', true)\\n#8 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/files\\\/view.php(644): OC\\\\Files\\\\Storage\\\\Wrapper\\\\Encryption->moveFromStorage(Object(OC\\\\Files\\\\Storage\\\\Wrapper\\\\Encryption), 'Huoguo.jpg', 'Huoguo.jpg')\\n#9 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/connector\\\/sabre\\\/objecttree.php(222): OC\\\\Files\\\\View->rename('SFTP2\\\/Huoguo.jp...', 'SFTP\\\/Huoguo.jpg')\\n#10 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/CorePlugin.php(630): OC\\\\Connector\\\\Sabre\\\\ObjectTree->move('SFTP2\\\/Huoguo.jp...', 'SFTP\\\/Huoguo.jpg')\\n#11 [internal function]: Sabre\\\\DAV\\\\CorePlugin->httpMove(Object(Sabre\\\\HTTP\\\\Request), Object(Sabre\\\\HTTP\\\\Response))\\n#12 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/event\\\/lib\\\/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\\n#13 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(469): Sabre\\\\Event\\\\EventEmitter->emit('method:MOVE', Array)\\n#14 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(254): Sabre\\\\DAV\\\\Server->invokeMethod(Object(Sabre\\\\HTTP\\\\Request), Object(Sabre\\\\HTTP\\\\Response))\\n#15 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/apps\\\/files\\\/appinfo\\\/remote.php(80): Sabre\\\\DAV\\\\Server->exec()\\n#16 \\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/remote.php(84): require_once('\\\/srv\\\/www\\\/htdocs...')\\n#17 {main}\",\"File\":\"\\\/srv\\\/www\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/encryption\\\/util.php\",\"Line\":242}","level":4,"time":"2015-04-15T15:39:34+00:00","method":"MOVE","url":"\/owncloud\/remote.php\/webdav\/SFTP2\/Huoguo.jpg"}

=> moved to #15688

@PVince81

Copy link
Copy Markdown
Contributor
  • BUG: can't upload file directly into "SFTP", also getting notification that says "path needs to be relative to the system wide data folder and point to a user specific file" (possibly related to the previous entry) raised as [enc2] Cannot upload to external storage #15688

Note: here I setup my OC + keys using the enc2_migration branch, just to be sure.

@schiessle

Copy link
Copy Markdown
Contributor Author

@PVince81 did you also used this PR for testing: #15616 ? This fixes are needed in order to work properly.

@PVince81

Copy link
Copy Markdown
Contributor

I don't remember. Let's get #15616 merged first then.

@PVince81

Copy link
Copy Markdown
Contributor

#15616 was just merged.

Please rebase to get the latest changes and get more accurate testing 😄

@PVince81

Copy link
Copy Markdown
Contributor

Well I'll do it myself then test this.

@PVince81

Copy link
Copy Markdown
Contributor
  • move file in/out of a shared folder as recipient works now

The external storage bugs are not related to this PR, so I raised them here: #15688

Please have a look at my comment regarding duplicate code before this can be merged.
Thanks.

@PVince81

Copy link
Copy Markdown
Contributor

Fixes #15840

@nickvergessen

Copy link
Copy Markdown
Contributor

Needs another loop of rebasing, sorry

@PVince81

Copy link
Copy Markdown
Contributor

And we still have no good solution for the duplicate code 😦
Looks like we'll have to keep it in short term and add a big fat TODO/WARNING in the code

@schiessle

Copy link
Copy Markdown
Contributor Author

I will rebase it once #15839 was merged because there is some overlapping.

@schiessle

Copy link
Copy Markdown
Contributor Author

@PVince81 now it is no longer a 1:1 copy from the base storage. I changed the code to also adjust the "encrypted"-flag in the filecache entry if files gets moved between encrypted and un-encrypted storage. Otherwise a unencrypted file can be detected as a legacy encrypted file.

PS: Unit tests will come later today 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason "moveFromStorage" was introduced was to be able to move files when needed.
Assuming that the encryption wrapper is always specified, it would cancel that effort by always doing a copy.
You probably copied this from https://github.com/owncloud/core/blob/master/lib/private/files/storage/common.php. But in many cases it's about the local storage, so the code would be https://github.com/owncloud/core/blob/master/lib/private/files/storage/local.php#L382

Would it possible to add a check "if encryption actually enabled", then do the special logic, else just call the underlying storage's "moveFromStorage" ?

@schiessle

Copy link
Copy Markdown
Contributor Author

Seems like Jenkins don't want to test this branch any longer... I opened a new PR just for Jenkins: #16046

@schiessle

Copy link
Copy Markdown
Contributor Author

Would be great to get this reviewed and merged... cc @th3fallen @nickvergessen @DeepDiver1975

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@schiessle

Copy link
Copy Markdown
Contributor Author

@nickvergessen you can ignore the failing tests... passing tests are here #16046

@schiessle

Copy link
Copy Markdown
Contributor Author

rebased to resolve merge conflicts

@ghost

ghost commented May 6, 2015

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/12200/

Build result: FAILURE

[...truncated 14 lines...] > git config remote.origin.url https://github.com/owncloud/core.git # timeout=10 > git config --add remote.origin.fetch +refs/heads/:refs/remotes/origin/ # timeout=10 > git config remote.origin.url https://github.com/owncloud/core.git # timeout=10Fetching upstream changes from https://github.com/owncloud/core.gitusing GIT_SSH to set credentials using .gitcredentials to set credentials > git config --local credential.helper store --file=/tmp/git1028190303737524368.credentials # timeout=10 > git -c core.askpass=true fetch --tags --progress https://github.com/owncloud/core.git +refs/pull/:refs/remotes/origin/pr/ > git config --local --remove-section credential # timeout=10 > git rev-parse refs/remotes/origin/pr/15628/merge^{commit} # timeout=10 > git rev-parse refs/remotes/origin/origin/pr/15628/merge^{commit} # timeout=10Checking out Revision f8fac96f774e56a23bb5041677d2728d33beb547 (refs/remotes/origin/pr/15628/merge) > git config core.sparsecheckout # timeout=10 > git checkout -f f8fac96f774e56a23bb5041677d2728d33beb547 > git rev-list 14e482fff3d4ee31e097f19e80a7cdbf2c8e2293 # timeout=10First time build. Skipping changelog. > git remote # timeout=10 > git submodule init # timeout=10 > git submodule sync # timeout=10 > git config --get remote.origin.url # timeout=10 > git submodule update --init --recursiveTriggering pull-request-analyser-ng-simple » SLAVEpull-request-analyser-ng-simple » SLAVE completed with result FAILURESetting status of 6e6ec55 to FAILURE with url https://ci.owncloud.org/job/pull-request-analyser-ng-simple/12200/ and message: Build finished.
💣 Test FAILed. 💣

nooo432

@nickvergessen

Copy link
Copy Markdown
Contributor

tested and still works as expected 👍
additionally I fixed a little doc block

@scrutinizer-notifier

Copy link
Copy Markdown

A new inspection was created.

@nickvergessen

Copy link
Copy Markdown
Contributor

rebased again

@ghost

ghost commented May 6, 2015

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/12211/

Build result: FAILURE

[...truncated 14 lines...] > git config remote.origin.url https://github.com/owncloud/core.git # timeout=10 > git config --add remote.origin.fetch +refs/heads/:refs/remotes/origin/ # timeout=10 > git config remote.origin.url https://github.com/owncloud/core.git # timeout=10Fetching upstream changes from https://github.com/owncloud/core.gitusing GIT_SSH to set credentials using .gitcredentials to set credentials > git config --local credential.helper store --file=/tmp/git5178862980473275824.credentials # timeout=10 > git -c core.askpass=true fetch --tags --progress https://github.com/owncloud/core.git +refs/pull/:refs/remotes/origin/pr/ > git config --local --remove-section credential # timeout=10 > git rev-parse refs/remotes/origin/pr/15628/merge^{commit} # timeout=10 > git rev-parse refs/remotes/origin/origin/pr/15628/merge^{commit} # timeout=10Checking out Revision fd0d800602cd3230ecf21932c733fdcdea907eec (refs/remotes/origin/pr/15628/merge) > git config core.sparsecheckout # timeout=10 > git checkout -f fd0d800602cd3230ecf21932c733fdcdea907eec > git rev-list c30a9dafe9b76a0806946fe287572d17defe0624 # timeout=10First time build. Skipping changelog. > git remote # timeout=10 > git submodule init # timeout=10 > git submodule sync # timeout=10 > git config --get remote.origin.url # timeout=10 > git submodule update --init --recursiveTriggering pull-request-analyser-ng-simple » SLAVEpull-request-analyser-ng-simple » SLAVE completed with result FAILURESetting status of aea734a to FAILURE with url https://ci.owncloud.org/job/pull-request-analyser-ng-simple/12211/ and message: Build finished.
💣 Test FAILed. 💣

nooo432

@SergioBertolinSG

Copy link
Copy Markdown
Contributor

👍 Working fine, tested with SFTP external storage and shared folder (in same OC server)

schiessle added a commit that referenced this pull request May 6, 2015
Encryption - fix moving/copying files between storages
@schiessle
schiessle merged commit 6633514 into master May 6, 2015
@schiessle
schiessle deleted the enc_fix_rename branch May 6, 2015 13:04
mmattel pushed a commit to mmattel/core that referenced this pull request May 22, 2015
Encryption - fix moving/copying files between storages
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Moving encrypted files to an external storage folder with encryption enabled decrypts them.

6 participants