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
a1f200c1
Commit
a1f200c1
authored
12 years ago
by
Sam Tuke
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned up path formatting with new method stripUserFilesPath()
parent
50faddfa
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/files_encryption/lib/crypt.php
+4
-9
4 additions, 9 deletions
apps/files_encryption/lib/crypt.php
apps/files_encryption/lib/util.php
+18
-11
18 additions, 11 deletions
apps/files_encryption/lib/util.php
with
22 additions
and
20 deletions
apps/files_encryption/lib/crypt.php
+
4
−
9
View file @
a1f200c1
...
...
@@ -182,16 +182,11 @@ class Crypt {
/**
* @brief Check if a file is encrypted via legacy system
* @param string $relPath The path of the file, relative to user/data;
* e.g. filename or /Docs/filename, NOT admin/files/filename
* @return true / false
*/
public
static
function
isLegacyEncryptedContent
(
$data
,
$path
)
{
$trimmed
=
ltrim
(
$path
,
'/'
);
// Path must not include user/files
$split
=
explode
(
'/'
,
$trimmed
);
$sliced
=
array_slice
(
$split
,
2
);
$relPath
=
implode
(
'/'
,
$sliced
);
public
static
function
isLegacyEncryptedContent
(
$data
,
$relPath
)
{
// trigger_error("REL PATH = ".var_export($relPath, 1));
...
...
@@ -200,7 +195,7 @@ class Crypt {
// Fetch all file metadata from DB
$metadata
=
\OC\Files\Filesystem
::
getFileInfo
(
$relPath
,
''
);
trigger_error
(
"PATH = "
.
var_export
(
$
trimmed
,
1
)
.
" METADATA = "
.
var_export
(
$metadata
[
'encrypted'
],
1
));
trigger_error
(
"PATH = "
.
var_export
(
$
relPath
,
1
)
.
" METADATA = "
.
var_export
(
$metadata
[
'encrypted'
],
1
));
// If a file is flagged with encryption in DB, but isn't a
// valid content + IV combination, it's probably using the
...
...
This diff is collapsed.
Click to expand it.
apps/files_encryption/lib/util.php
+
18
−
11
View file @
a1f200c1
...
...
@@ -251,6 +251,7 @@ class Util {
)
{
$filePath
=
$directory
.
'/'
.
$this
->
view
->
getRelativePath
(
'/'
.
$file
);
$relPath
=
$this
->
stripUserFilesPath
(
$filePath
);
// If the path is a directory, search
// its contents
...
...
@@ -286,7 +287,7 @@ class Util {
// If the file uses old
// encryption system
}
elseif
(
Crypt
::
isLegacyEncryptedContent
(
$this
->
view
->
file_get_contents
(
$filePath
),
$
file
Path
)
)
{
}
elseif
(
Crypt
::
isLegacyEncryptedContent
(
$this
->
view
->
file_get_contents
(
$filePath
),
$
rel
Path
)
)
{
$found
[
'legacy'
][]
=
array
(
'name'
=>
$file
,
'path'
=>
$filePath
);
...
...
@@ -341,6 +342,20 @@ class Util {
}
/**
* @brief Format a path to be relative to the /user/files/ directory
*/
public
function
stripUserFilesPath
(
$path
)
{
$trimmed
=
ltrim
(
$path
,
'/'
);
$split
=
explode
(
'/'
,
$trimmed
);
$sliced
=
array_slice
(
$split
,
2
);
$relPath
=
implode
(
'/'
,
$sliced
);
return
$relPath
;
}
/**
* @brief Encrypt all files in a directory
* @param string $publicKey the public key to encrypt files with
...
...
@@ -365,11 +380,7 @@ class Util {
// Encrypt data, generate catfile
$encrypted
=
Crypt
::
keyEncryptKeyfile
(
$plainData
,
$publicKey
);
// Format path to be relative to user files dir
$trimmed
=
ltrim
(
$plainFile
[
'path'
],
'/'
);
$split
=
explode
(
'/'
,
$trimmed
);
$sliced
=
array_slice
(
$split
,
2
);
$relPath
=
implode
(
'/'
,
$sliced
);
$relPath
=
$this
->
stripUserFilesPath
(
$plainFile
[
'path'
]
);
// Save keyfile
Keymanager
::
setFileKey
(
$this
->
view
,
$relPath
,
$this
->
userId
,
$encrypted
[
'key'
]
);
...
...
@@ -401,11 +412,7 @@ class Util {
// Recrypt data, generate catfile
$recrypted
=
Crypt
::
legacyKeyRecryptKeyfile
(
$legacyData
,
$legacyPassphrase
,
$publicKey
,
$newPassphrase
);
// Format path to be relative to user files dir
$trimmed
=
ltrim
(
$legacyFile
[
'path'
],
'/'
);
$split
=
explode
(
'/'
,
$trimmed
);
$sliced
=
array_slice
(
$split
,
2
);
$relPath
=
implode
(
'/'
,
$sliced
);
$relPath
=
$this
->
stripUserFilesPath
(
$legacyFile
[
'path'
]
);
// Save keyfile
Keymanager
::
setFileKey
(
$this
->
view
,
$relPath
,
$this
->
userId
,
$recrypted
[
'key'
]
);
...
...
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