core icon indicating copy to clipboard operation
core copied to clipboard

Encryption problem - Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.

Open mSys-mislav opened this issue 10 years ago • 34 comments

Note: there are some similar topics on this subject, but all problems are closed, thus I'm opening a new one.

Steps to reproduce

  1. When encryption is enabled, I've created backup of the user X
  2. User X has deleted folder "test123"
  3. I've restored folder "test123" from backup
  4. At first I didn't see this folders inside owncloud, thus I've ran the command:

    sudo -u www-data php console.php files:scan userX

and then folders were visible 5. When I tried to access to some of the files inside this folder, I receive error: Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.

Please note that meanwhile, there was no user password change.

Expected behaviour

Since I couldn't find proper way/documentation on how to backup/restore files when encryption is enabled, I simply tar.gz-ed files and restored them - expected behaviour would be of course when this files are restore owner can access them.

Actual behaviour

Restored files as mentioned are not accessible.

Server configuration

Operating system: Debian 8

Web server: Apache

Database: MariaDB

PHP version: PHP 5.6.14

ownCloud version: (see ownCloud admin page) 8.2.2

Updated from an older ownCloud or fresh install: there was fresh install 8.1.1, but I was updating meanwhile up to current 8.2.2

Login as admin user into your ownCloud and access 
http://example.com/index.php/settings/integrity/failed 
paste the results here.
  • I automatically get redirected to http://mydomain.com/index.php/apps/files/ - it doesn't work for me

List of activated apps:

If you have access to your command line run e.g.:
sudo -u www-data php occ app:list
from within your ownCloud installation folder

Enabled:

  • activity: 2.1.3
  • encryption: 1.1.0
  • external: 1.2
  • files: 1.2.0
  • files_external: 0.3.0
  • files_pdfviewer: 0.7
  • files_sharing: 0.7.0
  • files_texteditor: 2.0
  • files_versions: 1.1.0
  • files_videoviewer: 0.1.3
  • gallery: 14.2.0
  • provisioning_api: 0.3.0
  • templateeditor: 0.1 Disabled:
  • files_trashbin
  • firstrunwizard
  • notifications
  • user_external
  • user_ldap

The content of config/config.php:

If you have access to your command line run e.g.:
sudo -u www-data php occ config:list system
from within your ownCloud installation folder
{
    "system": {
        "instanceid": "",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "mydomain.com"
        ],
        "datadirectory": "\/opt\/owncloud\/data",
        "overwrite.cli.url": "https:\/\/mydomain.com",
        "dbtype": "mysql",
        "version": "8.2.2.2",
        "dbname": "test_do_ownc_db",
        "dbhost": "localhost",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "logtimezone": "UTC",
        "installed": true,
        "loglevel": 3,
        "asset-pipeline.enabled": true,
        "memcache.local": "\\OC\\Memcache\\APCu",
        "defaultapp": "files",
        "check_for_working_htaccess": false,
        "mail_smtpmode": "php",
        "mail_smtpsecure": "ssl",
        "mail_smtpauth": 1,
        "enable_previews": false,
        "singleuser": false,
        "maintenance": false,
        "theme": "",
        "filesystem_check_changes": 0,
        "trashbin_retention_obligation": "auto"
    }
}

Are you using external storage, if yes which one: local/smb/sftp/... no external sstorage

Are you using encryption: yes

Are you using an external user-backend, if yes which one: LDAP/ActiveDirectory/Webdav/... no external user-backend


### Client configuration
**Browser:** Mozilla Firefox (latest)

**Operating system:** Ubuntu 14.04 LTS

### Logs
#### Web server error log

Insert your webserver log here


#### ownCloud log (data/owncloud.log)

Insert your ownCloud log here {"reqId":"rKDme2Gqks7+p8mwAVIJ","remoteAddr":"","app":"no app in context","message":"Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.","level":3,"time":"2016-02-01T10:02:21+00:00"} {"reqId":"YYZkvFFDsrON4ZduTQOG","remoteAddr":"","app":"no app in context","message":"Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.","level":3,"time":"2016-02-01T10:02:28+00:00"}

I've tried to run also the following command: $ sudo -u www-data php occ encryption:decrypt-all userX

[-->-------------------------]PHP Fatal error: Call to a member function get() on null in /var/www/owncloud/apps/files_sharing/lib/updater.php on line 76

owncloud log: {"reqId":"zUQOrO8dOGtNiV6ksPvF","remoteAddr":"","app":"PHP","message":"Call to a member function get() on null at /var/www/owncloud/apps/files_sharing/lib/updater.php#76","level":3,"time":"2016-02-01T10:00:16+00:00"}


#### Browser log

Insert your browser log here, this could for example include:

GET https://mydomain.com/index.php/app...r/ajax/loadfile?filename=test2.txt&dir=%2Ftest12

400 Bad request 248ms
fb1bf5b...1351.js (line 6) "NetworkError: 400 Bad request - https://mydomain.com/index.php/apps/files_texteditor/ajax/loadfile?filename=test2.txt&dir=%2Ftest12" loadfil.../test12 "NetworkError: 404 Not Found - https://mydomain.com/index.php/core/preview.png?file=%2Ftest12%2Ftest2.txt&c=5477&x=32&y=32&forceIcon=0"


Please help - advise!

mSys-mislav avatar Feb 01 '16 10:02 mSys-mislav

Looks like the keys for that folder (better for the files inside the folder) are not found. Did you backup the files_encryption folder of the user within the data directory?

Try to restore the keys.

DeepDiver1975 avatar Feb 01 '16 14:02 DeepDiver1975

Since I couldn't find proper way/documentation on how to backup/restore files when encryption is enabled, I simply tar.gz-ed files and restored them - expected behaviour would be of course when this files are restore owner can access them.

@schiesbn @carlaschroder do we have documentation about this somewhere? THX

DeepDiver1975 avatar Feb 01 '16 14:02 DeepDiver1975

I will check it out and let you know.

Also about documentation - there is explanation, but only for non-encryption related stuff. I'll also test it out how it is when:

  • user changes password and how is it with restore then (I guess password changes encryption keys)
  • if user is deleted, how to restore it and his data from backup
  • if I want to migrate everything to new server

And this is all when encryption is enabled.

mSys-mislav avatar Feb 01 '16 14:02 mSys-mislav

Update:

Did you backup the files_encryption folder of the user within the data directory?

No, as I didn't knew. I've tried now and there is some progress. After I've done the same thing as above, I was getting this shared file error, however when I placed back also folder inside of files_encryption situation was the following:

  • I was able to read .txt files
  • nothing else was possible, this includes .pdfs - error: PDF.js v1.0.712 (build: 6969ed4) Message: Unexpected server response (0) while retrieving PDF "https://mydomain.com/index.php/apps/files/ajax/download.php?dir=%2Ftest_folder&files=ownCloud_Server_Administration_Manual.pdf".
  • also docs and images were also throwing errors: /tmp/mozilla_mislav/kQbY7AVM.jpg.part could not be saved, because the source file could not be read. /tmp/mozilla_mislav/sTarsMf6.docx.part could not be saved, because the source file could not be read.

Also, if I try to run decrypt command I receive error: $ sudo -u www-data php occ encryption:decrypt-all userX

{"reqId":"LL648SrdZN5+XJ8gsYBU","remoteAddr":"","app":"PHP","message":"Call to a member function get() on null at /var/www/owncloud/apps/files_sharing/lib/updater.php#76","level":3,"time":"2016-02-02T07:47:26+00:00"}

Is there anything else that must be done for other-related-stuff?

mSys-mislav avatar Feb 02 '16 08:02 mSys-mislav

@mislav-eu I suspect that the file size in the database doesn't match the unencrypted size but it's the encrypted size. So far it's not clear how the file size could become wrong, maybe it was a result of running "occ files:scan".

Since you're on 8.2.2 you could try with this patch: https://github.com/owncloud/core/pull/22008 This should automatically fix the wrong file sizes when downloading a file twice. (first download fixes it but fails, second one should work)

PVince81 avatar Feb 02 '16 09:02 PVince81

CC @MorrisJobke another case of restored encrypted files from backup

PVince81 avatar Feb 02 '16 09:02 PVince81

@PVince81 how exactly should I test this? I've changed the script /my_owncloud/lib/private/files/stream/encryption.php

and tried to do the same as above + download it few times, same problem

Am I doing something wrong?

mSys-mislav avatar Feb 02 '16 10:02 mSys-mislav

How did you change the script ? Did you use the patch -p1 < patchfile.patch command ?

Please try redownloading it, we just found a bug in that PR so needs repatching.

PVince81 avatar Feb 02 '16 10:02 PVince81

Download as patch: https://patch-diff.githubusercontent.com/raw/owncloud/core/pull/22008.patch

PVince81 avatar Feb 02 '16 10:02 PVince81

I did like you said, result is:

$ patch -p1 < 22008.patch patching file lib/private/files/stream/encryption.php patching file lib/private/files/stream/encryption.php

and same problem, I keep getting messages: /tmp/mozilla_mislav0/1umyztOX.jpg.part could not be saved, because the source file could not be read.

However, if I try to download e.g. image + doc or image + pdf together, then it's working (multiple files). I'm not sure if this is because of the patch, as I didn't test this before, but when you want to download few files, owncloud creates a .zip file and once this is downloaded, I can open files and they're not corrupted - downloading them one by one - then they're corrupted.

mSys-mislav avatar Feb 02 '16 10:02 mSys-mislav

If a zip file works, then it's very likely to be the file size issue. Because a zip file doesn't need to know the size in advance.

The reason why Firefox doesn't manage to download it is because the "Content-Length" header (the size the server says) doesn't match the number of bytes the server returned.

Have you tried downloading the same file twice ? The second time it should work.

PVince81 avatar Feb 02 '16 11:02 PVince81

Have you tried downloading the same file twice ? The second time it should work.

Yes, 5-10 times, same problem.

I've tested it with chrome and no problems. So I guess this is firefox related problem? Please note that in both browsers pdf preview is not working, it stops at around 80% - but if you download it from chrome, it works. (zip file works normal there also)

I will test other things mentioned and get back here if I found some problems with encryption app.

mSys-mislav avatar Feb 02 '16 11:02 mSys-mislav

Something to try: find the entry of one of the broken files in the "oc_filecache" table, then manually set its size to "-1". Then download that file twice. It should trigger the repair.

PVince81 avatar Feb 02 '16 11:02 PVince81

So far I'm assuming that you're running 8.2.2 by the way.

PVince81 avatar Feb 02 '16 11:02 PVince81

Yes, I'm running 8.2.2.

Here is the result:

update oc_filecache set size="-1" where name="3923511_187678037986761_228371050_n1.jpg"; Query OK, 2 rows affected (0.00 sec) Rows matched: 2 Changed: 2 Warnings: 0

MariaDB [test_do_ownc_db]> select * from oc_filecache where name="3923511_187678037986761_228371050_n1.jpg" \G *************************** 1. row *************************** fileid: 5554 storage: 55 path: files/test_folder/3923511_187678037986761_228371050_n1.jpg path_hash: 4ce666741b14ef360bc0b5cbdcc932a6 parent: 5549 name: 3923511_187678037986761_228371050_n1.jpg mimetype: 4 mimepart: 3 size: -1 mtime: 1454398485 storage_mtime: 1454398485 encrypted: 0 unencrypted_size: 0 etag: a5cdb042fe19f2159b64d1cb3cf746db permissions: 27 *************************** 2. row *************************** fileid: 5560 storage: 55 path: files_encryption/keys/files/test_folder/3923511_187678037986761_228371050_n1.jpg path_hash: 1139af1f5be29baf5a3911a9b9ad4456 parent: 5555 name: 3923511_187678037986761_228371050_n1.jpg mimetype: 2 mimepart: 1 size: -1 mtime: 1454417392 storage_mtime: 1454398485 encrypted: 0 unencrypted_size: 0 etag: 56b0a5f0dffe2 permissions: 31 2 rows in set (0.00 sec)

After that I've tried to download file few times and same problem - size is updated in "oc_filecache" table after that, but problem persist.

mSys-mislav avatar Feb 02 '16 12:02 mSys-mislav

Hmm, ok let's try this. Download the file using the ZIP technique. Then check the exact size of this file and compare it to the value that was set in the database. Are they the same ?

PVince81 avatar Feb 02 '16 12:02 PVince81

select * from oc_filecache where name="3923511_187678037986761_228371050_n1.jpg" \G *************************** 1. row *************************** fileid: 5554 storage: 55 path: files/test_folder/3923511_187678037986761_228371050_n1.jpg path_hash: 4ce666741b14ef360bc0b5cbdcc932a6 parent: 5549 name: 3923511_187678037986761_228371050_n1.jpg mimetype: 4 mimepart: 3 size: 42969 mtime: 1454398485 storage_mtime: 1454398485 encrypted: 0 unencrypted_size: 0 etag: a5cdb042fe19f2159b64d1cb3cf746db permissions: 27 *************************** 2. row *************************** fileid: 5560 storage: 55 path: files_encryption/keys/files/test_folder/3923511_187678037986761_228371050_n1.jpg path_hash: 1139af1f5be29baf5a3911a9b9ad4456 parent: 5555 name: 3923511_187678037986761_228371050_n1.jpg mimetype: 2 mimepart: 1 size: 1068 mtime: 1454418284 storage_mtime: 1454398485 encrypted: 0 unencrypted_size: 0 etag: 56b0a96d0a2d7 permissions: 31 2 rows in set (0.01 sec)

  • local file size 43,0 kB (42969 bytes)

It's the same, question is only if this encrypted version should have size 1068 ? (I've checked now and other files also have 1068 size, encrypted version)

mSys-mislav avatar Feb 02 '16 13:02 mSys-mislav

1068 is the size of the key, ignore it.

The file's size is 42060 bytes. But I also see that the column "encrypted" is 0, so looks like the file is not considered as encrypted ?

Can you check in "data/$user/files/..." the size of the file on disk ?

PVince81 avatar Feb 02 '16 13:02 PVince81

Size of that file on disk is 65K

mSys-mislav avatar Feb 02 '16 13:02 mSys-mislav

Owncloud client seems to have some issues as well with this restored files. Most of the restored encrypted files are fine and I can read them without any issues (just like through chrome), but e.g. pdf downloading is keep failing and failing with message: 3.2.2016. 9:35:42test_folder/ownCloud_Server_Administration_Manual.pdf ownCloud Error downloading https://mydomain.com/remote.php/webdav/test_folder/ownCloud_Server_Administration_Manual.pdf - server replied: Requested Range Not Satisfiable

Also, OC client itself does not see this test_folder, however it somehow sync it once I restore it. After download failed few times, now pdf is downloaded successfully and I can open it - it is not corrupted.

In oc log file on the server I've also found this, maybe it helps:

Error PHP Cannot modify header information - headers already sent by (output started at /var/www/owncloud/3rdparty/sabre/http/lib/Sapi.php:70) at /var/www/owncloud/3rdparty/sabre/http/lib/Sapi.php#58 2016-02-03T08:50:55+00:00

Fatal webdav Exception: {"Message":"HTTP/1.1 416 The start offset (10254068) exceeded the size of the entity (9246452)","Exception":"Sabre\DAV\Exception\RequestedRangeNotSatisfiable","Code":0,"Trace":"#0 [internal function]: Sabre\DAV\CorePlugin->httpGet(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))\n#1 /var/www/owncloud/3rdparty/sabre/event/lib/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\n#2 /var/www/owncloud/3rdparty/sabre/dav/lib/DAV/Server.php(469): Sabre\Event\EventEmitter->emit('method:GET', Array)\n#3 /var/www/owncloud/3rdparty/sabre/dav/lib/DAV/Server.php(254): Sabre\DAV\Server->invokeMethod(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))\n#4 /var/www/owncloud/apps/files/appinfo/remote.php(56): Sabre\DAV\Server->exec()\n#5 /var/www/owncloud/remote.php(137): require_once('/var/www/ownclo...')\n#6 {main}","File":"/var/www/owncloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","Line":157} 2016-02-03T08:36:35+00:0

mSys-mislav avatar Feb 03 '16 08:02 mSys-mislav