Repository navigation
Description
Note: I only had the case happen once and am still trying to find a way to reproduce this consistently.
Steps I had when the issue happened (with encryption enabled)
- I have a folder "/clientsync" that my local sync client syncs
- I have an existing folder "/clientsync/doc".
- Create a folder "/clientsync/doc/jeremie" on the web UI
- Wait for the sync client to download it
- On the local machine, copy two files "ME 11_09_14.docx" and "ME 11_09_14_review.docx" into "/clientsync/doc" (not the subdir). First file is 13M big and second one 7.7 MB
- While they are being uploaded, share the folder "/clientsync/doc/jeremie" with link
- When the upload is finished, locally move both files from "/clientsync/doc" to "/clientsync/doc/jeremie"
- Wait for the sync client to move the files
- Open the public link
- Try and download both files
Expected result
Both files can be downloaded from the public page
Actual result
The first file "ME 11_09_14.docx" can be downloaded but the second file ""ME 11_09_14_review.docx" shows an error page: "Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you"
Server Environment
openSUSE 13.1 x86_64
Apache 2.4
PHP 5.4.20
APC cache enabled (I simply installed the package "php5-APC-3.1.14_git201309121127-3.1.x86_64" from the PHP suse repo)
Client Environment
openSUSE 13.1 x86_64
Sync client 1.6.2
owncloud.log
{"reqId":"5417502a16d70","app":"OC\\Files\\Cache\\Scanner","message":"!!! Path 'files\/clientsync\/doc\/ME 11_09_14_review.docx' is not readable !!!","
level":0,"time":"2014-09-15T20:46:34+00:00","method":"PUT","url":"\/remote.php\/webdav\/clientsync\/doc\/ME%2011_09_14_review.docx"}
{"reqId":"5417502a16d70","app":"OC\\Files\\Cache\\Scanner","message":"!!! No reuse of etag for 'files\/clientsync\/doc\/ME 11_09_14_review.docx' !!! \n
cache: Array\n(\n [fileid] => 19909\n [storage] => local::\/srv\/www\/vhosts\/owncloud\/data\/vincent\/\n [path] => files\/clientsync\/doc\/ME
11_09_14_review.docx\n [parent] => 744\n [name] => ME 11_09_14_review.docx\n [mimetype] => application\/vnd.openxmlformats-officedocument.wor
dprocessingml.document\n [mimepart] => application\n [size] => 10810820\n [mtime] => 1410813994\n [storage_mtime] => 1410813994\n [encry
pted] => 1\n [unencrypted_size] => 8078228\n [etag] => 5417502a2f1e8\n [permissions] => 27\n)\n \ndata: Array\n(\n [mimetype] => applicatio
n\/vnd.openxmlformats-officedocument.wordprocessingml.document\n [mtime] => 1410813786\n [size] => 10810820\n [etag] => 5417502a2f4f7\n [st
orage_mtime] => 1410813786\n [permissions] => 27\n [parent] => 744\n)\n","level":0,"time":"2014-09-15T20:46:34+00:00","method":"PUT","url":"\/rem
ote.php\/webdav\/clientsync\/doc\/ME%2011_09_14_review.docx"}
{"reqId":"5417511413b9f","app":"PHP","message":"rename(\/srv\/www\/vhosts\/owncloud\/data\/vincent\/files_encryption\/share-keys\/clientsync\/doc\/ME 1
1_09_14_review.docx.vincent.shareKey,\/srv\/www\/vhosts\/owncloud\/data\/vincent\/files_encryption\/share-keys\/clientsync\/doc\/ME 11_09_14_review.doc
x.vincent.shareKey): No such file or directory at \/srv\/www\/htdocs\/owncloud\/lib\/private\/files\/storage\/local.php#190","level":3,"time":"2014-09-
15T20:50:28+00:00","method":"MOVE","url":"\/remote.php\/webdav\/clientsync\/doc\/ME%2011_09_14.docx"}
{"reqId":"54175114a589f","app":"files_encryption","message":"set shareFileKeyFailed (code: 20): multiKeyDecrypt with share-keyfailed: error:0407106B:rs
a routines:RSA_padding_check_PKCS1_type_2:block type is not 02","level":4,"time":"2014-09-15T20:50:28+00:00","method":"MOVE","url":"\/remote.php\/webda
v\/clientsync\/doc\/ME%2011_09_14_review.docx"}
As you can see at step 8) the share key of "ME 11_09_14_review.docx" did not work.
Even stranger is that the previous MOVE operation is done on the first file "ME 11_09_14.docx" but the rename error is on the share keys of the second file "ME 11_09_14_review.docx": see
{"reqId":"5417511413b9f","app":"PHP","message":"rename(/srv/www/vhosts/owncloud/data/vincent/files_encryption/share-keys/clientsync/doc/ME 1
1_09_14_review.docx.vincent.shareKey,/srv/www/vhosts/owncloud/data/vincent/files_encryption/share-keys/clientsync/doc/ME 11_09_14_review.doc
x.vincent.shareKey): No such file or directory at /srv/www/htdocs/owncloud/lib/private/files/storage/local.php#190","level":3,"time":"2014-09-
15T20:50:28+00:00","method":"MOVE","url":"/remote.php/webdav/clientsync/doc/ME%2011_09_14.docx"}
And here the share key is renamed to itself.
It seems that the file names got mixed up somehow during processing. That doesn't even make sense !
Access log
85.180.8.194 - vincent [12/Sep/2014:20:35:07 +0200] "PUT /remote.php/webdav/clientsync/doc/ME%2011_09_14.docx-chunking-2413552273-2-0 HTTP/1.1" 201 - "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:36:55 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:37:10 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:37:25 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:37:40 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:37:56 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:38:10 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:38:26 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:38:40 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:38:57 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:39:10 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:39:27 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:39:40 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:39:57 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:40:10 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:40:28 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:40:40 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:40:58 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:41:10 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:41:28 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - - [12/Sep/2014:20:41:41 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 5381 "-" "Mozilla/5.0 (Linux) csyncoC/0.91.5 neon/0.30.0"
85.180.8.194 - vincent [12/Sep/2014:20:41:59 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:42:29 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:43:00 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:41:41 +0200] "PUT /remote.php/webdav/clientsync/doc/ME%2011_09_14.docx-chunking-2045707607-2-0 HTTP/1.1" 201 - "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:43:30 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.8.194 - vincent [12/Sep/2014:20:43:12 +0200] "PUT /remote.php/webdav/clientsync/doc/ME%2011_09_14.docx-chunking-2045707607-2-1 HTTP/1.1" 201 - "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
(-- snip --)
85.180.13.211 - vincent [15/Sep/2014:22:45:24 +0200] "PUT /remote.php/webdav/clientsync/doc/ME%2011_09_14_review.docx HTTP/1.1" 201 - "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.13.211 - vincent [15/Sep/2014:22:46:55 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.13.211 - vincent [15/Sep/2014:22:47:04 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.13.211 - - [15/Sep/2014:22:47:05 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 5872 "-" "Mozilla/5.0 (Linux) csyncoC/0.91.5 neon/0.30.0"
85.180.13.211 - - [15/Sep/2014:22:47:05 +0200] "PROPFIND /remote.php/webdav/clientsync/doc HTTP/1.1" 207 8212 "-" "Mozilla/5.0 (Linux) csyncoC/0.91.5 neon/0.30.0"
85.180.13.211 - - [15/Sep/2014:22:47:05 +0200] "PROPFIND /remote.php/webdav/clientsync/doc/jeremie HTTP/1.1" 207 650 "-" "Mozilla/5.0 (Linux) csyncoC/0.91.5 neon/0.30.0"
(--snip--)
85.180.13.211 - - [15/Sep/2014:22:50:20 +0200] "GET /index.php/apps/files/ajax/list.php?dir=%2Fclientsync%2Fdoc%2Fjeremie&sort=name&sortdirection=asc HTTP/1.1" 200 98 "https://owncloud.vincentpetry.net/index.php/apps/files/?dir=%2Fclientsync%2Fdoc%2Fjeremie" "Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
85.180.13.211 - - [15/Sep/2014:22:50:21 +0200] "GET /index.php/apps/files/ajax/getstoragestats.php?dir=%2Fclientsync%2Fdoc%2Fjeremie HTTP/1.1" 200 145 "https://owncloud.vincentpetry.net/index.php/apps/files/?dir=%2Fclientsync%2Fdoc%2Fjeremie" "Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
85.180.13.211 - - [15/Sep/2014:22:50:27 +0200] "PROPFIND /remote.php/webdav/clientsync HTTP/1.1" 207 5872 "-" "Mozilla/5.0 (Linux) csyncoC/0.91.5 neon/0.30.0"
85.180.13.211 - - [15/Sep/2014:22:50:27 +0200] "MOVE /remote.php/webdav/clientsync/doc/ME%2011_09_14.docx HTTP/1.1" 201 - "-" "Mozilla/5.0 (Linux) csyncoC/0.91.5 neon/0.30.0"
85.180.13.211 - - [15/Sep/2014:22:50:28 +0200] "PROPPATCH /remote.php/webdav/clientsync/doc/jeremie/ME%2011_09_14.docx HTTP/1.1" 207 350 "-" "Mozilla/5.0 (Linux) csyncoC/0.91.5 neon/0.30.0"
85.180.13.211 - - [15/Sep/2014:22:50:28 +0200] "HEAD /remote.php/webdav/clientsync/doc/jeremie/ME%2011_09_14.docx HTTP/1.1" 200 - "-" "Mozilla/5.0 (Linux) csyncoC/0.91.5 neon/0.30.0"
85.180.13.211 - - [15/Sep/2014:22:50:28 +0200] "MOVE /remote.php/webdav/clientsync/doc/ME%2011_09_14_review.docx HTTP/1.1" 201 - "-" "Mozilla/5.0 (Linux) csyncoC/0.91.5 neon/0.30.0"
85.180.13.211 - vincent [15/Sep/2014:22:50:28 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 479 "-" "Mozilla/5.0 (Linux) mirall/1.6.2"
85.180.13.211 - - [15/Sep/2014:22:50:28 +0200] "PROPPATCH /remote.php/webdav/clientsync/doc/jeremie/ME%2011_09_14_review.docx HTTP/1.1" 207 357 "-" "Mozilla/5.0 (Linux) csyncoC/0.91.5 neon/0.30.0"
85.180.13.211 - - [15/Sep/2014:22:50:28 +0200] "HEAD /remote.php/webdav/clientsync/doc/jeremie/ME%2011_09_14_review.docx HTTP/1.1" 200 - "-" "Mozilla/5.0 (Linux) csyncoC/0.91.5 neon/0.30.0"
(-- snip --)
86.65.208.68 - - [16/Sep/2014:08:44:38 +0200] "GET /public.php?service=files&t=f98173a5e001456b9bc3547b0f6a351f&path=%2F&files=ME%2011_09_14_review.doc
x&download HTTP/1.1" 302 - "https://owncloud.vincentpetry.net/public.php?service=files&t=f98173a5e001456b9bc3547b0f6a351f" "Mozilla/5.0 (Windows NT 6.1
; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0"
86.65.208.68 - - [16/Sep/2014:08:44:38 +0200] "GET /apps/files_encryption/files/error.php?p=0&errorCode=3 HTTP/1.1" 403 5770 "https://owncloud.vincentp
etry.net/public.php?service=files&t=f98173a5e001456b9bc3547b0f6a351f" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0"
Error log
Nothing relevant
Note: I haven't been able to reproduce the weird mix up of files names nor the share key loss.
Need further investigation.
CC @schiesbn @ser72
Activity
PVince81 commentedon Sep 17, 2014
To summarize, three issues:
[-]Share key generation fail, strange file name mix up[/-][+][7.0.2] Share key generation fail, strange file name mix up[/+]PVince81 commentedon Sep 17, 2014
Okay, I was able to reproduce it locally and I found that the
preg_matchused to find the share keys is matching the wrong key!! Here: https://github.com/owncloud/core/blob/master/apps/files_encryption/lib/helper.php#L446The dots must be escaped.
I'll fix it and add a unit test.
PVince81 commentedon Sep 17, 2014
@MTRichards @craigpg setting to current sprint, to summarize: encryption keys wrongly moved, potential data loss: critical.
karlitschek commentedon Sep 17, 2014
Wow. Awesome work with debugging this @schiesbn @PVince81
PVince81 commentedon Sep 17, 2014
I will thank my brother for asking me to review his internship report. That's how I got "lucky" and had this case happening on my personal ownCloud...
MTRichards commentedon Sep 17, 2014
No kidding. Thanks guys, absolutely critical.
PVince81 commentedon Sep 17, 2014
Fix is here: #11137
schiessle commentedon Sep 18, 2014
As already explained by Vincent, there is no way to catch all share keys without false positives with a regular expression.
One relatively easy solution for OC7 (and maybe also OC6) would be to use this method to get a list of all users with access to the file: https://github.com/owncloud/core/blob/master/apps/files_encryption/lib/util.php#L983 . If we have the list of users we can construct the correct path for all share keys and move them to the new place.
The proposed patch from @PVince81 fixes almost all cases but not all, but we didn't come up with a better short term solution yesterday.
Even my suggestion would keep one possible error unfixed, even if it is quite unlikely to happen. Think about following:
Users:
uname1
part1.uname1
Files:
/file
/file.part1
Both files are owned by "user", so the share key looks like this:
/file.uname1.shareKey (for /file)
/file.part1.uname1.shareKey (for /file.part1)
Now "uname1" decides to share "/file" to "part1.uname1". This would introduce following additional share key for "/file":
/file.part1.uname1.shareKey
This key would belong to "/file" for user "part1.uname1" and would overwrite the share key of "/file.part1" for user "uname1"
Long term solution (I would suggest to implement it for OC8) to improve the performance and to make sure that we never pick a wrong key or overwrite a existing one:
Change the key file format from
/path/to/file/<filename>.<user>.shareKeyto/path/to/file/<filename>/<user>.shareKey. This would mean that we create a directory for every file in the share key directory and store all share keys in the directory.LukasReschke commentedon Sep 18, 2014
Wouldn't this collide with directories with the
.shareKeyextension?i.e. user has:
/Invoices/2014/data.shareKey/foo.txt(directory with file in it)/Invoices/2014/data(file)As far I can see this will become:
/Invoices/2014/data.shareKey/foo.txt/<user>.shareKey/Invoices/2014/data.shareKeyschiessle commentedon Sep 18, 2014
No,
The share keys for
/Invoices/2014/data.shareKey/foo.txtwill be stored in the folderfiles_encryption/keys/Invoices/2014/data.shareKey/foo.txt/The share keys for
/Invoices/2014/datawill be stored in the folderfiles_encryption/keys/Invoices/2014/data/Every file will become a folder in the "keys" folder and contain all share keys. Since we can't have more than one file/folder with the same name in files/ the key folder will be also unique.
LukasReschke commentedon Sep 18, 2014
Got it. Thank you. - Makes sense.
PVince81 commentedon Sep 18, 2014
@schiesbn where is the code we talked about to find all users who have access to the share ? I hope it doesn't need major refactoring to make it usable elsewhere.
PVince81 commentedon Sep 18, 2014
Ok here's a list of what needs to be fixed for all code that finds share keys:
@schiesbn did I forget anything ?
PVince81 commentedon Sep 22, 2014
PVince81 commentedon Sep 23, 2014
Raised #11252 for stable6 fix.
carlaschroder commentedon Jan 29, 2015
fixed, so I am removing release note label.