Closed
Description
Steps to reproduce
- Upload a bunch of pictures from a computer
- Run the sync client from another computer
- 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
PVince81 commentedon Aug 13, 2014
Assigning to self since this is on my own server, will try and debug that.
PVince81 commentedon Aug 13, 2014
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.
PVince81 commentedon Aug 13, 2014
It looks like the key file is moving properly with the file, but I see the following entries in the DB:
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)
PVince81 commentedon Aug 13, 2014
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).
PVince81 commentedon Aug 13, 2014
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...
PVince81 commentedon Aug 13, 2014
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.
[-]Decryption of content failed from sync client, webdav ok[/-][+]Cannot download encrypted file with HTTP range request[/+]PVince81 commentedon Aug 13, 2014
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
fseekis 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
$ignoreRangeHeaderto 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.
PVince81 commentedon Aug 13, 2014
@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 ?
ogoffart commentedon Aug 13, 2014
Since 1.6.2 it should work. (before it used to be broken)
PVince81 commentedon Aug 14, 2014
CC @evert for SabreDAV stuff.
PVince81 commentedon Aug 14, 2014
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: byteswhen the file is first requested can tell the client that range requests are allowed.Returning
Accept-Ranges: noneis 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.
PVince81 commentedon Aug 14, 2014
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.
PVince81 commentedon Aug 14, 2014
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.
icewind1991 commentedon Aug 14, 2014
With
libsmbclient-phpSMB does support it :)PVince81 commentedon Aug 14, 2014
@icewind1991 nice 😄
evert commentedon Aug 14, 2014
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.
PVince81 commentedon Aug 14, 2014
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.evert commentedon Aug 14, 2014
Ah fair enough. If there's still a bug like this in the 1.8 branch, I'd be happy to take a look.