Skip to content

[7.0.2] Share key generation fail, strange file name mix up #11127

Closed

Description

@PVince81

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)

  1. I have a folder "/clientsync" that my local sync client syncs
  2. I have an existing folder "/clientsync/doc".
  3. Create a folder "/clientsync/doc/jeremie" on the web UI
  4. Wait for the sync client to download it
  5. 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
  6. While they are being uploaded, share the folder "/clientsync/doc/jeremie" with link
  7. When the upload is finished, locally move both files from "/clientsync/doc" to "/clientsync/doc/jeremie"
  8. Wait for the sync client to move the files
  9. Open the public link
  10. 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

  1. PVince81 commented on Sep 17, 2014

    @PVince81
    ContributorAuthor

    To summarize, three issues:

    1. The WebDAV MOVE call for "ME 11_09_14.docx" happens first, but touches the share keys from the second file "ME 11_09_14_review.docx" for some unknown reason.
    2. The WebDAV MOVE call for "ME 11_09_14_review.docx" works but the share key cannot be decrypted (possibly a mix up due to 1))
    3. After the file "ME 11_09_14_review.docx" was moved, it cannot be decrypted. Also possibly due to 2)
  2. changed the title [-]Share key generation fail, strange file name mix up[/-] [+][7.0.2] Share key generation fail, strange file name mix up[/+] on Sep 17, 2014
  3. PVince81 commented on Sep 17, 2014

    @PVince81
    ContributorAuthor

    Okay, I was able to reproduce it locally and I found that the preg_match used to find the share keys is matching the wrong key!! Here: https://github.com/owncloud/core/blob/master/apps/files_encryption/lib/helper.php#L446

    The dots must be escaped.

    I'll fix it and add a unit test.

  4. PVince81 commented on Sep 17, 2014

    @PVince81
    ContributorAuthor

    @MTRichards @craigpg setting to current sprint, to summarize: encryption keys wrongly moved, potential data loss: critical.

  5. added this to the milestone on Sep 17, 2014
  6. karlitschek commented on Sep 17, 2014

    @karlitschek
    Contributor

    Wow. Awesome work with debugging this @schiesbn @PVince81

  7. PVince81 commented on Sep 17, 2014

    @PVince81
    ContributorAuthor

    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...

  8. MTRichards commented on Sep 17, 2014

    @MTRichards
    Contributor

    No kidding. Thanks guys, absolutely critical.

  9. PVince81 commented on Sep 17, 2014

    @PVince81
    ContributorAuthor

    Fix is here: #11137

  10. schiessle commented on Sep 18, 2014

    @schiessle
    Contributor

    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>.shareKey to /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.

  11. LukasReschke commented on Sep 18, 2014

    @LukasReschke
    Contributor

    Wouldn't this collide with directories with the .shareKey extension?

    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.shareKey
  12. schiessle commented on Sep 18, 2014

    @schiessle
    Contributor

    No,

    The share keys for /Invoices/2014/data.shareKey/foo.txt will be stored in the folder files_encryption/keys/Invoices/2014/data.shareKey/foo.txt/

    The share keys for /Invoices/2014/data will be stored in the folder files_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.

  13. LukasReschke commented on Sep 18, 2014

    @LukasReschke
    Contributor

    Got it. Thank you. - Makes sense.

  14. PVince81 commented on Sep 18, 2014

    @PVince81
    ContributorAuthor

    @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.

  15. PVince81 commented on Sep 18, 2014

    @PVince81
    ContributorAuthor

    Ok here's a list of what needs to be fixed for all code that finds share keys:

    @schiesbn did I forget anything ?

  16. PVince81 commented on Sep 22, 2014

    @PVince81
    ContributorAuthor
  17. PVince81 commented on Sep 23, 2014

    @PVince81
    ContributorAuthor

    Raised #11252 for stable6 fix.

  18. carlaschroder commented on Jan 29, 2015

    @carlaschroder

    fixed, so I am removing release note label.

  19. locked as resolved and limited conversation to collaborators on Aug 13, 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