Repository navigation
make encryption stream wrapper seekable - #12909
jknockaert wants to merge 19 commits into
Conversation
|
Thanks a lot for your contribution! Contributions to the core repo require a signed contributors agreement http://owncloud.org/contribute/agreement/ Alternatively you can add a comment here stating that this contribution is MIT licensed. Some more details about out pull request workflow can be found here: http://owncloud.org/code-reviews-on-github/ |
|
CC @schiesbn |
|
@owncloud-bot okay to test |
|
I had a quick look at the inspection report. As far as I can see there's nothing of much concern. The duplication reported is deliberate, the $newPosition bug seems to be a false positive and the $this->plainkey bug is not new. |
|
This is a too big change for a backport (we only backport critical bugfixes) so this is more likely to make it either into 8.0 or 8.1. |
|
@PVince81: The backporting suggestion was only meant as an advise to those who want to use/test the PR on 7.0.4. |
|
@jknockaert would it possible to add some unit test for the fseek behaviour? Thanks! |
|
@schiesbn You should maybe help a bit. What to test, where to test, how to test ... add maybe an example. Otherwise it will be hard to do ;) |
|
@jknockaert just let me know if you need any help. Think it would be good to have a unit test which does some seek operation on a encrypted file and check that it end up at the correct position. Also it would be good to perform this test with a encrypted file which contain a header and with a encrypted file which doesn't have a header. |
|
@schiesbn I never before wrote a unit test (but it's definitely something I'd like to learn). I will have a look at it. I agree on the suggestion to test it with and without header (which is something I did already). And on a file shorter than a block and one longer than a block (and maybe also one where the the last block is full). And an empty file (writing and reading), as empty files should be headerless. We should probably also test it for a seekable as well as a nonseekable encrypted file stream, but less sure how to do that. |
|
@jknockaert did you saw: http://doc.owncloud.org/server/6.0/developer_manual/core/unit-testing.html Installing phpunit should be quite easy on most distributions. If phpunit is installed you can run all tests with: or a specific test with for example: The easiest way is to use "sqlite" as database but the autotest.sh also contains a description how to prepare a mysql or postgresql database for the unit tests. "/apps/files_encryption/tests/stream.php" is also the place where you could place your unit test, you can probably reuse many stuff from the existing tests and just copy&pasting them. Regarding #10422, this needs to be reverted to make your PR work, right? Don't you want to revert it as part of your PR, so that everything which belongs together is in one PR? |
|
@jknockaert thanks for clarification |
|
@schiesbn OK, I've setup this unit testing, and the stream.php tests work fine. I've also written a first new test for writing a string to a file, reopening it, seeking and reading (with the reading for a size<6126 bytes and across two encryption blocks). Works fine. Before writing more complicated tests, I've two questions. 1. Where do I post new tests? As a commit attached to this PR? 2. In apps/files_encryption/tests/stream.php: what mechanism does actually enable the encryption stream wrapper in this context? Just the namespace declaration at the top of the file? |
|
So we missed 8.0; that's OK. But could we now pls move forward with this PR? I've been (re)writing and using the code since 6.0.2. In my opinion the legacy implementation of the encryption stream wrapper is a hack, this PR fixes a number of issues. It properly implements the stream metrics (in the legacy code the metrics of the encrypted stream are used in reading/searching/writing on the unencrypted stream), it fixes the dependency on php bug 21641 (which is actually not a bug, and which no longer holds), it implements proper stream searching (which allows for more efficient webdav using http-range requests after reversing #10422 and probably fixes other bugs caused by the bogus search implementation of the legacy wrapper), it correctly sets the encrypted file size in the cache (which was probably not fixed in #11736). We went quite far in rewriting related code in #11659 to avoid recursion (and improve stability) and we debugged (remotely) related issues in #11736. |
|
Forgot to mention here that stream_write (in combination with flush()) as implemented in this PR has provision for writing chunks to existing encrypted streams (at any arbitrary position in that stream). That can potentially allow for future optimisations, like the one suggested by #12006. |
|
@jknockaert Thanks a lot for your work. We will release oc8 at the end of the month and directly afterwards we will review and merge your pr. |
|
ownCloud8 is out so let's review and merge this PR as soon as possible. @th3fallen can you also have a look at it and help reviewing it? Thanks! |
|
@jknockaert can you rebase the branch? Thanks! |
There was a problem hiding this comment.
6126 is used quite often, I think it would be good to introduce a constant for it. This makes it easier to find out where this number come from if you read the code again in a few years.
There was a problem hiding this comment.
Not sure a constant is the best way, I would say a property would be better. (imho)
|
I will update this PR asap. As for the 6126, I've suggested before that it should be defined in the same place where Crypt::BLOCKSIZE is defined. I would prefer to do that after this PR is in (and in a a separate PR). We've already been reviewing far too much other code in the history of this PR, resulting in it being postponed over again. |
|
I finished the upgrade of my production server to 8.0. I will first port my code to that server and test it. After that I will rebase my git development version and update this PR. After the PR is reviewed and merged I will open a separate PR for the 6126 discussion. |
|
@jknockaert This sounds great! At the same time we (mainly @th3fallen and I) working on a improved encryption which is more modular than what we have today. That's why I would love to have your PR merged soon so that we can also integrated it in the re-design. We can then probably also address the "6126-issue" directly in the branch where we do the re-design. If this was merged and if you are interested I would like to invite you to also have a look at our re-design. Maybe you even want to join the development? The branch is here https://github.com/owncloud/core/tree/enc_ng |
|
@schiesbn I will first focus on finishing this PR. I plan to work on it this Friday, so expect a rebased PR for review early next week. After that I will have a look at the broader redesign and check if I can contribute. |
This prevents a misusage of \OC\Files\View by calling it with user-supplied input. In such cases an exception is now thrown.
Add loadfeedback
add documentation issue trackers and use https everywhere
Dont update the cache when working with part files
…ile-view Disallow path traversals in file view
|
OK, ported this PR to OC8 and it works. Next will be rebasing my development version. Later today or tomorrow. |
If no link text has been set for the navigation show the link nonetheless
Conflicts: apps/files_encryption/lib/stream.php
|
Ok, this rebase is a complete failure. |
|
rebased in #14383 |
|
The inspection completed: No issues found |
Rewrite of #8390.
There's a lot of stuff fixed, such as support for reads that are not exactly 6126 bytes, the encrypted file size pushed to fileinfo, but most importantly it makes encrypted streams seekable (if the storage is seekable). Main purpose is to serve http range requests well. Note that #10422 must be reversed to support http range requests on encrypted streams.
A main change is that stream_read and stream_write operate on an unencrypted cached block, with all file readings/writings handled by flush and readCache, which is where encryption/decryption happens.