Skip to content

Cannot download encrypted file with HTTP range request #10383

Closed

Description

@PVince81

Steps to reproduce

  1. Upload a bunch of pictures from a computer
  2. Run the sync client from another computer
  3. Wait for sync

Expected result

All files downloaded successfully

Actual result

One file in the list could not be decrypted: P1040575.JPG

More information

Encryption is enabled
This is ownCloud 7.0.1 upgraded from ownCloud 7.0.0.
Sync client 1.6.2.
I am able to download the file P1040575.JPG from the web UI and from WebDAV, but not from the sync client. This is very strange.
Restarting the sync client didn't help.

I have other apps enabled like calendar and contacts.

Logs

owncloud log has no information

Web server log:

[Wed Aug 13 09:32:46.447631 2014] [php5:error] [pid 23520] [client 79.222.40.203:38707] {"reqId":"53eb149e6d40b","app":"remote","message":"Encryption library: Decryption (symmetric) of content failed","level":4,"time":"2014-08-13T07:32:46+00:00","method":"GET","url":"\\/remote.php\\/webdav\\/clientsync\\/pics\\/favpics\\/P1040575.JPG"}
[Wed Aug 13 09:32:46.456481 2014] [php5:error] [pid 23520] [client 79.222.40.203:38707] {"reqId":"53eb149e6d40b","app":"PHP","message":"Session has been closed - no further changes to the session as allowed at \\/srv\\/www\\/htdocs\\/owncloud\\/lib\\/private\\/session\\/memory.php#80","level":3,"time":"2014-08-13T07:32:46+00:00","method":"GET","url":"\\/remote.php\\/webdav\\/clientsync\\/pics\\/favpics\\/P1040575.JPG"}
[Wed Aug 13 09:33:17.671724 2014] [php5:error] [pid 22966] [client 79.222.40.203:38710] {"reqId":"53eb14bda3f87","app":"remote","message":"Encryption library: Decryption (symmetric) of content failed","level":4,"time":"2014-08-13T07:33:17+00:00","method":"GET","url":"\\/remote.php\\/webdav\\/clientsync\\/pics\\/favpics\\/P1040575.JPG"}
[Wed Aug 13 09:33:17.672350 2014] [php5:error] [pid 22966] [client 79.222.40.203:38710] {"reqId":"53eb14bda3f87","app":"PHP","message":"Session has been closed - no further changes to the session as allowed at \\/srv\\/www\\/htdocs\\/owncloud\\/lib\\/private\\/session\\/memory.php#80","level":3,"time":"2014-08-13T07:33:17+00:00","method":"GET","url":"\\/remote.php\\/webdav\\/clientsync\\/pics\\/favpics\\/P1040575.JPG"}
[Wed Aug 13 09:33:48.889548 2014] [php5:error] [pid 14804] [client 79.222.40.203:38712] {"reqId":"53eb14dcd9273","app":"remote","message":"Encryption library: Decryption (symmetric) of content failed","level":4,"time":"2014-08-13T07:33:48+00:00","method":"GET","url":"\\/remote.php\\/webdav\\/clientsync\\/pics\\/favpics\\/P1040575.JPG"}
[Wed Aug 13 09:33:48.890201 2014] [php5:error] [pid 14804] [client 79.222.40.203:38712] {"reqId":"53eb14dcd9273","app":"PHP","message":"Session has been closed - no further changes to the session as allowed at \\/srv\\/www\\/htdocs\\/owncloud\\/lib\\/private\\/session\\/memory.php#80","level":3,"time":"2014-08-13T07:33:48+00:00","method":"GET","url":"\\/remote.php\\/webdav\\/clientsync\\/pics\\/favpics\\/P1040575.JPG"}
[Wed Aug 13 09:34:20.148562 2014] [php5:error] [pid 23520] [client 79.222.40.203:38714] {"reqId":"53eb14fc243e1","app":"remote","message":"Encryption library: Decryption (symmetric) of content failed","level":4,"time":"2014-08-13T07:34:20+00:00","method":"GET","url":"\\/remote.php\\/webdav\\/clientsync\\/pics\\/favpics\\/P1040575.JPG"}
[Wed Aug 13 09:34:20.149152 2014] [php5:error] [pid 23520] [client 79.222.40.203:38714] {"reqId":"53eb14fc243e1","app":"PHP","message":"Session has been closed - no further changes to the session as allowed at \\/srv\\/www\\/htdocs\\/owncloud\\/lib\\/private\\/session\\/memory.php#80","level":3,"time":"2014-08-13T07:34:20+00:00","method":"GET","url":"\\/remote.php\\/webdav\\/clientsync\\/pics\\/favpics\\/P1040575.JPG"}

I tried renaming the file back and forth to force the sync client to resync, but the error happens again.

I can probably fix this by reuploading the file but would like to keep the error for debugging.

@schiesbn

Activity

  1. self-assigned this
    on Aug 13, 2014
  2. PVince81 commented on Aug 13, 2014

    @PVince81
    ContributorAuthor

    Assigning to self since this is on my own server, will try and debug that.

  3. added this to the milestone on Aug 13, 2014
  4. PVince81 commented on Aug 13, 2014

    @PVince81
    ContributorAuthor

    I'm using a remote folder "clientsync" for local syncing.
    When moving the picture from "clientsync/pics/favpics" to "clientsync", the picture was downloaded properly. Then I moved it back to "clientsync/pics/favpics" and it was also moved properly by the sync client locally.

    Then... I moved the pic to "/" which is outside of "clientsync". The sync client properly deletes the file locally. And then, when I move back the pic to "clientsync/pics/favpics" the error happens again (sync client gets server error but webdav works)
    Very strange...

    I'll redo the same operation and observe the file keys.

  5. PVince81 commented on Aug 13, 2014

    @PVince81
    ContributorAuthor

    It looks like the key file is moving properly with the file, but I see the following entries in the DB:

    +--------+---------+-----------------------------------------------------------------------------------+----------------------------------+--------+-------------------------------+----------+----------+---------+------------+-----------+---------------+------------------+---------------+-------------+
    | fileid | storage | path                                                                              | path_hash                        | parent | name                          | mimetype | mimepart | size    | mtime      | encrypted | etag          | unencrypted_size | storage_mtime | permissions |
    +--------+---------+-----------------------------------------------------------------------------------+----------------------------------+--------+-------------------------------+----------+----------+---------+------------+-----------+---------------+------------------+---------------+-------------+
    |   3226 |       1 | files/clientsync/pics/P1040575.JPG                                                | 00defddeb5f58a33372ea78908b0d486 |   3276 | P1040575.JPG                  |       15 |        6 | 2875284 | 1390329386 |         1 | 52ded142ae729 |          2150144 |    1390329386 |          27 |
    |   3504 |       1 | gallery/vincent/clientsync/doc/favpics/P1040575.JPG                               | f7d34a421e25403570e7a1b84dbde7c0 |   3318 | P1040575.JPG                  |       15 |        6 |    6320 | 1390334274 |         0 | 52e63c953df02 |                0 |    1390334274 |           0 |
    |  13279 |       1 | files_encryption/keyfiles/clientsync/pics/favpics/P1040575.JPG.key                | 569c4733a6574f1d62fecb4d9c5f32aa |  13172 | P1040575.JPG.key              |       21 |       14 |     244 | 1390334274 |         0 | 5330395cab5f2 |                0 |    1390334274 |           0 |
    |  14144 |       1 | files_encryption/share-keys/clientsync/pics/favpics/P1040575.JPG.vincent.shareKey | d0366c714ed4c81a0d39c9eadf4976e2 |  13963 | P1040575.JPG.vincent.shareKey |       21 |       14 |     512 | 1390334274 |         0 | 5330395da7432 |                0 |    1390334274 |           0 |
    +--------+---------+-----------------------------------------------------------------------------------+----------------------------------+--------+-------------------------------+----------+----------+---------+------------+-----------+---------------+------------------+---------------+-------------+
    

    Even when I move the file, the keyfile entries stay the same.

    When I move the pic file from outside into either "clientsync" or "clientsync/pics" it can be downloaded properly.
    The issue only occurs when the file is moved from outside into "clientsync/pics/favpics" which somehow matches these key entries in the cache. (moving from outside is only to force the sync client to redownload the file instead of just moving it)

  6. PVince81 commented on Aug 13, 2014

    @PVince81
    ContributorAuthor

    I just tried to log the contents of the key used for decryption and it's the same whether called from the sync client (broken) or webdav (working).

  7. PVince81 commented on Aug 13, 2014

    @PVince81
    ContributorAuthor

    I added some logging and it looks like when the file is downloaded through the sync client, the content passed to decrypt() has an empty IV and empty content.
    Very strange that it only happens in that specific directory...

  8. PVince81 commented on Aug 13, 2014

    @PVince81
    ContributorAuthor

    I debugged a bit and found out that when the file is in "clientsync/pics/favpics" the sync client issues a range request. It seems the sync client "remembers" the file there and tries to retrieve the end of it.
    The wrongly remembering of the deleted file was filed here: owncloud/client#2057

    Need to look into the range request + encryption issue next.

  9. changed the title [-]Decryption of content failed from sync client, webdav ok[/-] [+]Cannot download encrypted file with HTTP range request[/+] on Aug 13, 2014
  10. PVince81 commented on Aug 13, 2014

    @PVince81
    ContributorAuthor

    I renamed the issue to reflect the actual issue.

    This should be fixed as follows: whenever OC receives an HTTP range request, and either encryption is on or an external storage is used that does not support fseek is used, then OC should return the WHOLE file instead and NOT set the HTTP range response headers.

    The current behavior happens in the SabreDAV code that simply does an fseek() and assumes that everything ran fine: https://github.com/owncloud/3rdparty/blob/master/sabre/dav/lib/Sabre/DAV/Server.php#L629

    We need to find a way to either remove the range headers earlier if the file is on a non-seekable storage, or try and trick it to set $ignoreRangeHeader to false.

    @DeepDiver1975 @icewind1991 @schiesbn what do you think ?

    Another alternative is the brute-force approach of make fseek() read in the whole file until it reaches the desired offset which can be bad for performance.

  11. PVince81 commented on Aug 13, 2014

    @PVince81
    ContributorAuthor

    @ogoffart can you confirm that if the sync client receives no HTTP range in the response it will understand that it's getting the whole file, not the requested range ?

  12. ogoffart commented on Aug 13, 2014

    @ogoffart

    Since 1.6.2 it should work. (before it used to be broken)

  13. PVince81 commented on Aug 14, 2014

    @PVince81
    ContributorAuthor

    CC @evert for SabreDAV stuff.

  14. PVince81 commented on Aug 14, 2014

    @PVince81
    ContributorAuthor

    There seems to be a header that OC does not set at all but could be used: http://www.cyberciti.biz/cloud-computing/http-status-code-206-commad-line-test/

    Returning Accept-Ranges: bytes when the file is first requested can tell the client that range requests are allowed.
    Returning Accept-Ranges: none is to explicitly tell that it's not supported.

    This could be used as a hint but I suspect that some clients might ignore it and still attempt range requests. So that would just be a nice addition.

  15. PVince81 commented on Aug 14, 2014

    @PVince81
    ContributorAuthor

    I did some tests with ext storage (SMB and SFTP) and the good news is that it already works without changing anything. The bad news is that for every range request, the ext storage implementation will first download the complete file from the external storage to a temp dir (like it always does) and then only read out the required part.

    The latter isn't very efficient but could be improved in the future if we can support streaming and fseek, but not all libs/protocols (like SMB) can support that.

  16. PVince81 commented on Aug 14, 2014

    @PVince81
    ContributorAuthor

    Note: someone kindly provided a PR to make encrypted files seekable here: #8390

    The fix I have provided above is mostly a short term fix with the purpose of being backportable.

  17. icewind1991 commented on Aug 14, 2014

    @icewind1991
    Contributor

    but not all libs/protocols (like SMB) can support that.

    With libsmbclient-php SMB does support it :)

  18. PVince81 commented on Aug 14, 2014

    @PVince81
    ContributorAuthor

    @icewind1991 nice 😄

  19. evert commented on Aug 14, 2014

    @evert

    Hi Vincent,

    I'm not part of the owncloud team. I'm always happy to help with things, but it would be great if you could at the very least elaborate what the problem is and how it relates to sabredav.

  20. PVince81 commented on Aug 14, 2014

    @PVince81
    ContributorAuthor

    Yes sorry. I checked the latest SabreDAV code and it seems to have a fix already, so we'll eventually get it on upgrading. The issue was mostly that it did not check whether fseek() succeeded when processing range requests.

  21. evert commented on Aug 14, 2014

    @evert

    Ah fair enough. If there's still a bug like this in the 1.8 branch, I'd be happy to take a look.

  22. locked as resolved and limited conversation to collaborators on Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions