core icon indicating copy to clipboard operation
core copied to clipboard

Shared files are encrypted. Files still encrypted after disabling encryption app

Open Elethiomel opened this issue 13 years ago • 9 comments

Running owncloud 5.0.13 from supplied debs on Debian Wheezy. Users are from our LDAP

A user can download their own files. When a file is shared with them, the file is still encrypted. Error in log is:

{"app":"Encryption library","message":"Decryption (asymmetric) of sealed content with share-key "" failed","level":3,"time":"2013-11-19T13:40:57+00:00"}

Sharing with someone gives the message

{"app":"Encryption library","message":""486a4f98-c424-1031-84da-a322d2b5bc40" is not setup for encryption","level":2,"time":"2013-11-19T13:45:49+00:00"} {"app":"Encryption library","message":"Sharing to these user(s) failed as they are unready for encryption:"Array\n(\n [0] => 486a4f98-c424-1031-84da-a322d2b5bc40\n)\n","level":2,"time":"2013-11-19T13:45:49+00:00"}

Both users are new and uploaded files ARE encrypted.

I disabled the enctyption app, logged both users out and logged them back in. Both of their files were obviously still encrypted

Elethiomel avatar Nov 19 '13 13:11 Elethiomel

@schiesbn

karlitschek avatar Nov 19 '13 14:11 karlitschek

Please check if all users involved have a private key in /data/<user>/files_encryption and a public key in /data/public-keys

If a file was shared, does it show up in the recipients Share folder despite of the error message that the recipient is not ready for encryption? Please look at the owners folder at /data/owner/files_encryption/share_keys/<path_to_the_shared_file>/<shared_file_name>.userid.shareKey if a share key exists for the owner and the recipient.

schiessle avatar Nov 19 '13 14:11 schiessle

I created two new LDAP users: owner and recipient. Using the web interface I uploaded a file as owner. I shared it with recipient. After this, this is the result: a partial listing of my /data dir.

owner/ owner/files/test.txt owner/files_encryption/keyfiles/test.txt.key owner/files_encryption/share-keys/test.txt.66b9ad9e-9a9e-1032-94e7-0d3a7aa055a3.shareKey owner/files_encryption/66b9ad9e-9a9e-1032-94e7-0d3a7aa055a3.private.key

recipient/ recipient/files_encryption/486a4f98-c424-1031-84da-a322d2b5bc40.private.key

public-keys/486a4f98-c424-1031-84da-a322d2b5bc40.public.key public-keys/66b9ad9e-9a9e-1032-94e7-0d3a7aa055a3.public.key

Is it correct that the users are referred to by name in some places (such as owner) and by id in others(66b9ad9e-9a9e-1032-94e7-0d3a7aa055a3)?

The file "owner/files_encryption/keyfiles/test.txt.key" is definitely encrypted on the server. Downloading it as recipient gives me the file encrypted. All of this is through the web interface, not the client.

Elethiomel avatar Nov 19 '13 15:11 Elethiomel

When did you logged in with the recipient for the first time? Before or after sharing the file? You need to login at least once so that ownCloud can generate the users private/public key before you start sharing files.

Now the state looks OK. Both users have a private and a public key. If you try to share the file once more, what's happening then?

If sharing was successful you should have two share keys:

owner/files_encryption/share-keys/test.txt.66b9ad9e-9a9e-1032-94e7-0d3a7aa055a3.shareKey owner/files_encryption/share-keys/test.txt.486a4f98-c424-1031-84da-a322d2b5bc40.shareKey

schiessle avatar Nov 19 '13 16:11 schiessle

I did make sure to login and logout after creating the users. I do not have the two share keys :/ Just the one for the owner.

I just tried the following now: As owner I uploaded test2.txt and shared with recipient

{"app":"Encryption library","message":""486a4f98-c424-1031-84da-a322d2b5bc40" is not setup for encryption","level":2,"time":"2013-11-19T16:16:48+00:00"} {"app":"Encryption library","message":"Sharing to these user(s) failed as they are unready for encryption:"Array\n(\n [0] => 486a4f98-c424-1031-84da-a322d2b5bc40\n)\n","level":2,"time":"2013-11-19T16:16:48+00:00"}

As recipient I can see the file in my share, but I get

{"app":"Encryption library","message":"Decryption (asymmetric) of sealed content with share-key "" failed","level":3,"time":"2013-11-19T16:18:36+00:00"}

Regards, Colin

Elethiomel avatar Nov 19 '13 16:11 Elethiomel

The strange think is that we have two checks if a user is ready for sharing. The first check should block the sharing in the first place and you should get a warning in the web interface. It seems that you pass this test, otherwise the sharing wouldn't happen but than the check during the share operation fails.

I don't have a LDAP to test it and with the ownCloud user management I can't reproduce it. But I have a idea what could be the problem. Maybe you can try following, open apps/files_encryption/lib/util.php

and than add after line 150 this code:

\OC\Files\Filesystem::initMountPoints($GLOBALS['fileOwner']);

and after line 165 this code:

\OC\Files\Filesystem::initMountPoints($this->userId);

The whole colde block should than look like this:

            if (isset($GLOBALS['app']) && $GLOBALS['app'] === 'files_sharing') {
                $this->userDir = '/' . $GLOBALS['fileOwner'];
                $this->fileFolderName = 'files';
                $this->userFilesDir = '/' . $GLOBALS['fileOwner'] . '/'
                                      . $this->fileFolderName; // TODO: Does this need to be user configurable?
                $this->publicKeyDir = '/' . 'public-keys';
                $this->encryptionDir = '/' . $GLOBALS['fileOwner'] . '/' . 'files_encryption';
                $this->keyfilesPath = $this->encryptionDir . '/' . 'keyfiles';
                $this->shareKeysPath = $this->encryptionDir . '/' . 'share-keys';
                $this->publicKeyPath =
                    $this->publicKeyDir . '/' . $this->userId . '.public.key'; // e.g. data/public-keys/admin.public.key
                $this->privateKeyPath =
                    '/owncloud_private_key/' . $this->userId . '.private.key'; // e.g. data/admin/admin.private.key
                $this->isPublic = true;
                \OC\Files\Filesystem::initMountPoints($GLOBALS['fileOwner']);
            }

        } else {
            $this->userDir = '/' . $this->userId;
            $this->fileFolderName = 'files';
            $this->userFilesDir =
                '/' . $this->userId . '/' . $this->fileFolderName; // TODO: Does this need to be user configurable?
            $this->publicKeyDir = '/' . 'public-keys';
            $this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption';
            $this->keyfilesPath = $this->encryptionDir . '/' . 'keyfiles';
            $this->shareKeysPath = $this->encryptionDir . '/' . 'share-keys';
            $this->publicKeyPath =
                $this->publicKeyDir . '/' . $this->userId . '.public.key'; // e.g. data/public-keys/admin.public.key
            $this->privateKeyPath =
                $this->encryptionDir . '/' . $this->userId . '.private.key'; // e.g. data/admin/admin.private.key
            \OC\Files\Filesystem::initMountPoints($this->userId);
        }

After that please try once more to share a file.

It is just a guess, but I remember that in same cases on LDAP you need to make sure that the users home is mounted. Maybe that's the problem.

schiessle avatar Nov 19 '13 16:11 schiessle

Success! As recipient I can now view the file. In owner's share-keys there's is now 2 sharekeys, 1 for owner and one for recipient. Also, no error messages :)

Edit: I did not mount home directories. I just patched the code as you suggested

Elethiomel avatar Nov 19 '13 17:11 Elethiomel

Great! I will prepare a pull request to fix it.

schiessle avatar Nov 19 '13 17:11 schiessle

Thank you for all your help Björn!

Elethiomel avatar Nov 19 '13 17:11 Elethiomel