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
83574053
Commit
83574053
authored
10 years ago
by
Björn Schießle
Browse files
Options
Downloads
Patches
Plain Diff
if we download a public shared file we need to retrieve the user from the path
parent
331d73c3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/files_encryption/lib/proxy.php
+9
-11
9 additions, 11 deletions
apps/files_encryption/lib/proxy.php
apps/files_encryption/lib/stream.php
+4
-2
4 additions, 2 deletions
apps/files_encryption/lib/stream.php
apps/files_encryption/tests/proxy.php
+1
-12
1 addition, 12 deletions
apps/files_encryption/tests/proxy.php
with
14 additions
and
25 deletions
apps/files_encryption/lib/proxy.php
+
9
−
11
View file @
83574053
...
...
@@ -47,31 +47,30 @@ class Proxy extends \OC_FileProxy {
* check if path is excluded from encryption
*
* @param string $path relative to data/
* @param string $uid user
* @return boolean
*/
protected
function
isExcludedPath
(
$path
,
$uid
)
{
protected
function
isExcludedPath
(
$path
)
{
$view
=
new
\OC\Files\View
();
$
p
ath
=
\OC\Files\Filesystem
::
normalizePath
(
$path
);
$
normalizedP
ath
=
\OC\Files\Filesystem
::
normalizePath
(
$path
);
$parts
=
explode
(
'/'
,
$
p
ath
);
$parts
=
explode
(
'/'
,
$
normalizedP
ath
);
// we only encrypt/decrypt files in the files and files_versions folder
if
(
strpos
(
$path
,
'/'
.
$uid
.
'
/
files
/'
)
!==
0
&&
!
(
$parts
[
2
]
===
'files
'
&&
\OCP\User
::
userExists
(
$parts
[
1
]))
&&
!
(
$parts
[
2
]
===
'files_versions'
&&
\OCP\User
::
userExists
(
$parts
[
1
])))
{
return
true
;
}
if
(
!
$view
->
file_exists
(
$
p
ath
))
{
$
p
ath
=
dirname
(
$
p
ath
);
if
(
!
$view
->
file_exists
(
$
normalizedP
ath
))
{
$
normalizedP
ath
=
dirname
(
$
normalizedP
ath
);
}
// we don't encrypt server-to-server shares
list
(
$storage
,
)
=
\OC\Files\Filesystem
::
resolvePath
(
$
p
ath
);
list
(
$storage
,
)
=
\OC\Files\Filesystem
::
resolvePath
(
$
normalizedP
ath
);
/**
* @var \OCP\Files\Storage $storage
*/
...
...
@@ -93,17 +92,16 @@ class Proxy extends \OC_FileProxy {
*/
private
function
shouldEncrypt
(
$path
,
$mode
=
'w'
)
{
$userId
=
Helper
::
getUser
(
$path
);
// don't call the crypt stream wrapper, if...
if
(
Crypt
::
mode
()
!==
'server'
// we are not in server-side-encryption mode
||
$this
->
isExcludedPath
(
$path
,
$userId
)
// if path is excluded from encryption
||
$this
->
isExcludedPath
(
$path
)
// if path is excluded from encryption
||
substr
(
$path
,
0
,
8
)
===
'crypt://'
// we are already in crypt mode
)
{
return
false
;
}
$userId
=
Helper
::
getUser
(
$path
);
$view
=
new
\OC\Files\View
(
''
);
$util
=
new
Util
(
$view
,
$userId
);
...
...
This diff is collapsed.
Click to expand it.
apps/files_encryption/lib/stream.php
+
4
−
2
View file @
83574053
...
...
@@ -136,7 +136,8 @@ class Stream {
switch
(
$fileType
)
{
case
Util
::
FILE_TYPE_FILE
:
$this
->
relPath
=
Helper
::
stripUserFilesPath
(
$this
->
rawPath
);
$this
->
userId
=
\OC
::
$server
->
getUserSession
()
->
getUser
()
->
getUID
();
$user
=
\OC
::
$server
->
getUserSession
()
->
getUser
();
$this
->
userId
=
$user
?
$user
->
getUID
()
:
Helper
::
getUserFromPath
(
$this
->
rawPath
);
break
;
case
Util
::
FILE_TYPE_VERSION
:
$this
->
relPath
=
Helper
::
getPathFromVersion
(
$this
->
rawPath
);
...
...
@@ -145,7 +146,8 @@ class Stream {
case
Util
::
FILE_TYPE_CACHE
:
$this
->
relPath
=
Helper
::
getPathFromCachedFile
(
$this
->
rawPath
);
Helper
::
mkdirr
(
$this
->
rawPath
,
new
\OC\Files\View
(
'/'
));
$this
->
userId
=
\OC
::
$server
->
getUserSession
()
->
getUser
()
->
getUID
();
$user
=
\OC
::
$server
->
getUserSession
()
->
getUser
();
$this
->
userId
=
$user
?
$user
->
getUID
()
:
Helper
::
getUserFromPath
(
$this
->
rawPath
);
break
;
default
:
\OCP\Util
::
writeLog
(
'Encryption library'
,
'failed to open file "'
.
$this
->
rawPath
.
'" expecting a path to "files", "files_versions" or "cache"'
,
\OCP\Util
::
ERROR
);
...
...
This diff is collapsed.
Click to expand it.
apps/files_encryption/tests/proxy.php
+
1
−
12
View file @
83574053
...
...
@@ -126,9 +126,7 @@ class Proxy extends TestCase {
$this
->
view
->
mkdir
(
dirname
(
$path
));
$this
->
view
->
file_put_contents
(
$path
,
"test"
);
$testClass
=
new
DummyProxy
();
$result
=
$testClass
->
isExcludedPathTesting
(
$path
,
$this
->
userId
);
$result
=
\Test_Helper
::
invokePrivate
(
new
\OCA\Files_Encryption\Proxy
(),
'isExcludedPath'
,
array
(
$path
));
$this
->
assertSame
(
$expected
,
$result
);
$this
->
view
->
deleteAll
(
dirname
(
$path
));
...
...
@@ -149,12 +147,3 @@ class Proxy extends TestCase {
}
/**
* Dummy class to make protected methods available for testing
*/
class
DummyProxy
extends
\OCA\Files_Encryption\Proxy
{
public
function
isExcludedPathTesting
(
$path
,
$uid
)
{
return
$this
->
isExcludedPath
(
$path
,
$uid
);
}
}
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