Skip to content

Fix share key pattern matching - #11137

Merged
PVince81 merged 1 commit into
masterfrom
enc-pregfix
Sep 23, 2014
Merged

PVince81 merged 1 commit into
masterfrom
enc-pregfix

Conversation

@PVince81

Copy link
Copy Markdown
Contributor

Fixes #11127

But there's another failing pattern, unit test will fail.
Still looking for a solution...

@karlitschek

Copy link
Copy Markdown
Contributor

looks good. And great to have a test! 👍

@PVince81

Copy link
Copy Markdown
Contributor Author

@LukasReschke @schiesbn

The remaining problem is the pattern like:
File 1: "test.txt"
File 2: "test.txt.backup"

The keys become:
File 1: "test.txt.currentuser.shareKey"
File 2: "test.txt.backup.currentuser.shareKey"

If you move file "test.txt" it will also match the key from "test.txt.backup".
At this point we cannot accurately split the user name (especially if it contains dots) inside the key name:

File 1: "test.txt.firstname.lastname.shareKey"
File 2: "test.txt.backup.firstname.lastname.shareKey"

Still looking for a quick solution that doesn't require changing the key name format...

@PVince81

Copy link
Copy Markdown
Contributor Author

CC @ser72 see previous comment for problem I talk with you about

@LukasReschke

Copy link
Copy Markdown
Contributor

At this point we cannot accurately split the user name (especially if it contains dots) inside the key name:

Don't we know the user name at this point?

@PVince81

Copy link
Copy Markdown
Contributor Author

We need the share keys of all users who have access, not only the current one. Resolving the user names (checking for matches) can be slow (LDAP...).

Alternative: Getting the list of users who have access to the file is possible but complex due to reshares. The algo exists somewhere and might be reusable.

Another quick fix idea: if a matched key might match another file name, exclude it.

There's one other scenario with a user "user1" and "user1.test" with the files "file.user1" and "file.user1.test" where it could still mess up... Hopefully much rare.

Ultimate solution would be to put all share keys of a file inside a sub folder with the file name. Migration is a concern...

@PVince81

Copy link
Copy Markdown
Contributor Author

Part of this problem also exists on OC 6.0.5 where glob() is used...

@schiessle

Copy link
Copy Markdown
Contributor

I just checked the trash bin, the trash bin still uses glob() to get all share keys. I think it would make sense to change the trash bin to use the same methods as files_encryption to collect the share keys.

@PVince81

Copy link
Copy Markdown
Contributor Author

Then also the question how to fix stable6 which only uses glob... should we use preg_match there as well then ? (separate PR)

@PVince81

Copy link
Copy Markdown
Contributor Author
  • try getting the user list who have access to the file to provide the most accurate matches
  • add unit test for the keymanager.php change

Trashbin glob will be fixed separately...

@PVince81

Copy link
Copy Markdown
Contributor Author
  • add/modify unit tests for move/copy files, add file name cases that would trigger the issue

@PVince81

Copy link
Copy Markdown
Contributor Author

That approach worked.
Remaining to do: more unit tests.

@PVince81

Copy link
Copy Markdown
Contributor Author
  • fixed case where deleting key for a specific user accross subdirs (for example when deleting a user)

Please review @schiesbn @LukasReschke @icewind1991 @th3fallen

Comment thread apps/files_encryption/hooks/hooks.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or !count($matches)

@PVince81

Copy link
Copy Markdown
Contributor Author

Doing some local testing as well.
Would be good if @schiesbn could help to identify the cases where this code kicks in.

Already found an issue with the sync client 😦

@PVince81

Copy link
Copy Markdown
Contributor Author

Bad news, it seems that this fix is still not enough.
By doing some manipulations with shared files I still managed to have disappearing sharing keys.
Will continue investigating.

@PVince81

Copy link
Copy Markdown
Contributor Author

The problem happens when the owner changes:

  1. Create two users user1 and user2
  2. As user2 share a folder "sh" with user1
  3. As user1 create a folder "fold"
  4. As user1 upload two non-empty files "test.txt" and "test_review.txt" into "fold"
  5. Move the folder "fold" into "sh" to make it change owner
    The key of "test.txt" will be lost.

Will compare with master and try and find a solution.

@PVince81

Copy link
Copy Markdown
Contributor Author

I raised #11162 for the warnings I saw in the log, but when using only one file that file is not broken after move.
But when I have these two, one of them is broken.

I'll continue to debug.

@PVince81

Copy link
Copy Markdown
Contributor Author

Please carry on testing/reviewing, that issue is completely different and unrelated to file name patterns. See #11162 for details.

@PVince81 PVince81 added this to the 2014-sprint-04-current milestone Sep 18, 2014
@PVince81

Copy link
Copy Markdown
Contributor Author

Test plan:

  1. Create three users "user1", "user2" and "user3"
  2. Upload two files "test.txt" and "test_review.txt" into a shared folder "sh".
  3. Make multiple subdirectories and have these files appear in all of them
  4. Share "sh" with "user2" and "user3"
  5. For every test, check that "user3" can still read the files

Testing deletion

With trashbin enabled

  • Delete shared folder as owner "user1"
  • Unshare from self as share receiver "user2", the correct share keys must be gone, other files still readable
  • Unshare from "user2", the correct share keys must be gone, other files still readable
  • Restore from trashbin make files readable again

With trashbin disabled

  • Delete shared folder as owner "user1"
  • Unshare from self as share receiver "user2", the correct share keys must be gone, other files still readable
  • Unshare from "user2", the correct share keys must be gone, other files still readable

Other

  • Delete "user2" after sharing, the correct share keys must be gone, other files still readable

Testing move / copy

  • webdav move the two files into a subfolder, both files still readable (that was the original issue)
  • webdav copy the two files into a subfolder, target files still readable

@PVince81

Copy link
Copy Markdown
Contributor Author
  • BUG: REGRESSION: when moving files over webdav from "sh" to "sh/sub", some share keys still exist in "sh" even though the file is gone. Target files can still be read though, keys seem to have been copied
  • BUG: unshare "sh" from self as "user2" did not delete the share keys for "user2" (also happens on stable7, not a regression) raised as: [stable7] Stray share key after unshare from self #11177

@PVince81

Copy link
Copy Markdown
Contributor Author
  • test with reshares
  • delete file inside folder (with trashbin): only the keys of that file must be deleted
  • delete file inside folder (without trashbin): only the keys of that file must be deleted

@PVince81

Copy link
Copy Markdown
Contributor Author

Ok... I'll retest these bugs and see whether they happen on master and raise tickets if needed.
I don't want to fix all possible encryption bugs here... and stray keys aren't that bad.
At least in all test cases there was no data loss: files were always still readable.

@PVince81

Copy link
Copy Markdown
Contributor Author

I have raised three tickets for the issues that exist on stable7.
I'll look into that remaining regression after lunch.

@PVince81

Copy link
Copy Markdown
Contributor Author
  • TEST: with recovery key, it must be moved correctly as well
  • TEST: with system wide mount points

@PVince81

Copy link
Copy Markdown
Contributor Author

I give up on trying to write unit tests for that. Too many static classes, not enough dependency injection. It's simply not possible in a short time frame.

So I tested the system mount point case manually: moving a file from "/mount" to "/mount/file2" when the mount point is accessible to multiple users. This correctly moves the share keys to the new folder.

@PVince81

Copy link
Copy Markdown
Contributor Author

Seems it all works now.

Please help review and testing.

@schiesbn

@ghost

ghost commented Sep 19, 2014

Copy link
Copy Markdown

🚀 Test Passed. 🚀
Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org/job/pull-request-analyser/7479/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't we have the same problem again, that we could match the wrong share keys with preg_match() ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think about two users, "name2" and "name1.name2". You want to delete all shares keys for "name2". With the preg_match statement above you would also delete the share key for user "name1.name2", right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm right, the wildcard (.*) that is before might match too much, including the left part of the wrong user name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrote a unit test, indeed it can happen... will see whether I can just reuse the $realFile somehow.

@PVince81

Copy link
Copy Markdown
Contributor Author

@schiesbn I fixed the part and added further unit tests.
Note that the commented out unit tests are for the more complex case where we have a user "user1" and "test.user" and prepend or append both in the file name. This will require a more complex fix to be done separately.

@PVince81

Copy link
Copy Markdown
Contributor Author

@schiesbn see a8b55b4 where I have also fixed the trashbin share key matching using the helper, as you advised.

@ghost

ghost commented Sep 23, 2014

Copy link
Copy Markdown

🚀 Test PASSed. 🚀
Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser/7527/

@ghost

ghost commented Sep 23, 2014

Copy link
Copy Markdown

🚀 Test PASSed. 🚀
Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser/7528/

@schiessle

Copy link
Copy Markdown
Contributor

looks good 👍

@PVince81

Copy link
Copy Markdown
Contributor Author

Thanks. Needs another reviewer please @LukasReschke @icewind1991

To test the trashbin part you need to create two files "test.txt" and "text.txt.backup". Before the fix, deleting "test.txt" would kill both file's share keys. After the fix the correct key is removed.

For the former part please have a look at the original ticket, the pattern is "test.txt" and "test_review.txt" and involves a WebDAV MOVE into a subdir within a shared folder.

@icewind1991

Copy link
Copy Markdown
Contributor

Code looks good 👍

@PVince81

Copy link
Copy Markdown
Contributor Author

Thanks guys. Going to squash this first.

Instead of inaccurate pattern matching, use the list of users who we
know have access to the file to build the list of share keys.

This covers the following cases:

- Move/copy files into a subfolder within a share
- Unsharing from a user
- Deleting files directlry / moving share keys to trashbin
@PVince81

Copy link
Copy Markdown
Contributor Author

I just squashed them all into one commit.

PVince81 pushed a commit that referenced this pull request Sep 23, 2014
Fix share key pattern matching
@PVince81
PVince81 merged commit 75593f8 into master Sep 23, 2014
@PVince81
PVince81 deleted the enc-pregfix branch September 23, 2014 10:36
@scrutinizer-notifier

Copy link
Copy Markdown

A new inspection was created.

@PVince81

Copy link
Copy Markdown
Contributor Author

@karlitschek please confirm backport for stable7 and stable6 (stable6 will be done later as it might need a different approach)

@karlitschek

Copy link
Copy Markdown
Contributor

backporting confirmed

@PVince81

Copy link
Copy Markdown
Contributor Author

stable7: 85d7492

I've raised #11252 for stable6 so we can schedule it separately (the fix might need more time as the code is quite different there)

@PVince81

Copy link
Copy Markdown
Contributor Author

Raised #11297 for the last issue related to having user names in file names.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

7 participants