Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
6e447b67
Commit
6e447b67
authored
10 years ago
by
Björn Schießle
Browse files
Options
Downloads
Patches
Plain Diff
update keys recursively if a folder was moved
parent
59226892
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/files_encryption/hooks/hooks.php
+33
-26
33 additions, 26 deletions
apps/files_encryption/hooks/hooks.php
apps/files_encryption/tests/share.php
+48
-0
48 additions, 0 deletions
apps/files_encryption/tests/share.php
with
81 additions
and
26 deletions
apps/files_encryption/hooks/hooks.php
+
33
−
26
View file @
6e447b67
...
...
@@ -289,7 +289,7 @@ class Hooks {
}
/**
*
@brief
*
update share keys if a file was shared
*/
public
static
function
postShared
(
$params
)
{
...
...
@@ -299,29 +299,39 @@ class Hooks {
if
(
$params
[
'itemType'
]
===
'file'
||
$params
[
'itemType'
]
===
'folder'
)
{
$view
=
new
\OC\Files\View
(
'/'
);
$session
=
new
\OCA\Encryption\Session
(
$view
);
$userId
=
\OCP\User
::
getUser
();
$util
=
new
Util
(
$view
,
$userId
);
$path
=
\OC\Files\Filesystem
::
getPath
(
$params
[
'fileSource'
]);
$sharingEnabled
=
\OCP\Share
::
isEnabled
();
self
::
updateKeyfiles
(
$path
,
$params
[
'itemType'
]);
}
}
$mountManager
=
\OC\Files\Filesystem
::
getMountManager
();
$mount
=
$mountManager
->
find
(
'/'
.
$userId
.
'/files'
.
$path
);
$mountPoint
=
$mount
->
getMountPoint
();
/**
* update keyfiles and share keys recursively
*
* @param string $path to the file/folder
* @param string $type 'file' or 'folder'
*/
private
static
function
updateKeyfiles
(
$path
,
$type
)
{
$view
=
new
\OC\Files\View
(
'/'
);
$userId
=
\OCP\User
::
getUser
();
$session
=
new
\OCA\Encryption\Session
(
$view
);
$util
=
new
Util
(
$view
,
$userId
);
$sharingEnabled
=
\OCP\Share
::
isEnabled
();
// if a folder was shared, get a list of all (sub-)folders
if
(
$params
[
'itemType'
]
===
'folder'
)
{
$allFiles
=
$util
->
getAllFiles
(
$path
,
$mountPoint
);
}
else
{
$allFiles
=
array
(
$path
);
}
$mountManager
=
\OC\Files\Filesystem
::
getMountManager
();
$mount
=
$mountManager
->
find
(
'/'
.
$userId
.
'/files'
.
$path
);
$mountPoint
=
$mount
->
getMountPoint
();
foreach
(
$allFiles
as
$path
)
{
$usersSharing
=
$util
->
getSharingUsersArray
(
$sharingEnabled
,
$path
);
$util
->
setSharedFileKeyfiles
(
$session
,
$usersSharing
,
$path
);
}
// if a folder was shared, get a list of all (sub-)folders
if
(
$type
===
'folder'
)
{
$allFiles
=
$util
->
getAllFiles
(
$path
,
$mountPoint
);
}
else
{
$allFiles
=
array
(
$path
);
}
foreach
(
$allFiles
as
$path
)
{
$usersSharing
=
$util
->
getSharingUsersArray
(
$sharingEnabled
,
$path
);
$util
->
setSharedFileKeyfiles
(
$session
,
$usersSharing
,
$path
);
}
}
...
...
@@ -420,7 +430,6 @@ class Hooks {
\OC_FileProxy
::
$enabled
=
false
;
$view
=
new
\OC\Files\View
(
'/'
);
$session
=
new
\OCA\Encryption\Session
(
$view
);
$userId
=
\OCP\User
::
getUser
();
$util
=
new
Util
(
$view
,
$userId
);
...
...
@@ -428,6 +437,7 @@ class Hooks {
isset
(
self
::
$renamedFiles
[
$params
[
'oldpath'
]][
'path'
]))
{
$ownerOld
=
self
::
$renamedFiles
[
$params
[
'oldpath'
]][
'uid'
];
$pathOld
=
self
::
$renamedFiles
[
$params
[
'oldpath'
]][
'path'
];
unset
(
self
::
$renamedFiles
[
$params
[
'oldpath'
]]);
}
else
{
\OCP\Util
::
writeLog
(
'Encryption library'
,
"can't get path and owner from the file before it was renamed"
,
\OCP\Util
::
DEBUG
);
return
false
;
...
...
@@ -462,6 +472,7 @@ class Hooks {
// handle share keys
if
(
!
$view
->
is_dir
(
$oldKeyfilePath
))
{
$type
=
'file'
;
$oldKeyfilePath
.
=
'.key'
;
$newKeyfilePath
.
=
'.key'
;
...
...
@@ -473,6 +484,7 @@ class Hooks {
}
}
else
{
$type
=
"folder"
;
// handle share-keys folders
$view
->
rename
(
$oldShareKeyPath
,
$newShareKeyPath
);
}
...
...
@@ -482,14 +494,9 @@ class Hooks {
$view
->
rename
(
$oldKeyfilePath
,
$newKeyfilePath
);
}
// update share keys
$sharingEnabled
=
\OCP\Share
::
isEnabled
();
// get users
$usersSharing
=
$util
->
getSharingUsersArray
(
$sharingEnabled
,
$pathNew
);
// update sharing-keys
$util
->
setSharedFileKeyfiles
(
$session
,
$usersSharing
,
$pathNew
);
self
::
updateKeyfiles
(
$params
[
'newpath'
],
$type
);
\OC_FileProxy
::
$enabled
=
$proxyStatus
;
}
...
...
This diff is collapsed.
Click to expand it.
apps/files_encryption/tests/share.php
+
48
−
0
View file @
6e447b67
...
...
@@ -1015,4 +1015,52 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
$this
->
view
->
unlink
(
'/'
.
\Test_Encryption_Share
::
TEST_ENCRYPTION_SHARE_USER1
.
'/files/'
.
$this
->
filename
);
}
/**
* test if additional share keys are added if we move a folder to a shared parent
* @medium
*/
function
testMoveFolder
()
{
$view
=
new
\OC\Files\View
(
'/'
.
\Test_Encryption_Share
::
TEST_ENCRYPTION_SHARE_USER1
);
$filename
=
'/tmp-'
.
uniqid
();
$folder
=
'/folder'
.
uniqid
();
\OC\Files\Filesystem
::
mkdir
(
$folder
);
// Save long data as encrypted file using stream wrapper
$cryptedFile
=
\OC\Files\Filesystem
::
file_put_contents
(
$folder
.
$filename
,
$this
->
dataShort
);
// Test that data was successfully written
$this
->
assertTrue
(
is_int
(
$cryptedFile
));
// Get file decrypted contents
$decrypt
=
\OC\Files\Filesystem
::
file_get_contents
(
$folder
.
$filename
);
$this
->
assertEquals
(
$this
->
dataShort
,
$decrypt
);
$newFolder
=
'/newfolder/subfolder'
.
uniqid
();
\OC\Files\Filesystem
::
mkdir
(
'/newfolder'
);
// get the file info from previous created file
$fileInfo
=
\OC\Files\Filesystem
::
getFileInfo
(
'/newfolder'
);
$this
->
assertTrue
(
$fileInfo
instanceof
\OC\Files\FileInfo
);
// share the folder
\OCP\Share
::
shareItem
(
'folder'
,
$fileInfo
[
'fileid'
],
\OCP\Share
::
SHARE_TYPE_USER
,
\Test_Encryption_Share
::
TEST_ENCRYPTION_SHARE_USER2
,
OCP\PERMISSION_ALL
);
\OC\Files\Filesystem
::
rename
(
$folder
,
$newFolder
);
// Get file decrypted contents
$newDecrypt
=
\OC\Files\Filesystem
::
file_get_contents
(
$newFolder
.
$filename
);
$this
->
assertEquals
(
$this
->
dataShort
,
$newDecrypt
);
// check if additional share key for user2 exists
$this
->
assertTrue
(
$view
->
file_exists
(
'files_encryption/share-keys'
.
$newFolder
.
'/'
.
$filename
.
'.'
.
\Test_Encryption_Share
::
TEST_ENCRYPTION_SHARE_USER2
.
'.shareKey'
));
// tear down
\OC\Files\Filesystem
::
unlink
(
$newFolder
);
\OC\Files\Filesystem
::
unlink
(
'/newfolder'
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment