summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption
diff options
context:
space:
mode:
authorSam Tuke <samtuke@owncloud.com>2013-02-05 15:59:28 +0000
committerSam Tuke <samtuke@owncloud.com>2013-02-05 15:59:28 +0000
commita1f200c1e5a4814d63561e581b7917270444e463 (patch)
tree34ec46a4b1959c1d8355e4a06c3a09e1a84c1ab6 /apps/files_encryption
parent50faddfa409f7afbb2a41fddaf9ce117e06d16d0 (diff)
downloadnextcloud-server-a1f200c1e5a4814d63561e581b7917270444e463.tar.gz
nextcloud-server-a1f200c1e5a4814d63561e581b7917270444e463.zip
Cleaned up path formatting with new method stripUserFilesPath()
Diffstat (limited to 'apps/files_encryption')
-rwxr-xr-xapps/files_encryption/lib/crypt.php13
-rw-r--r--apps/files_encryption/lib/util.php29
2 files changed, 22 insertions, 20 deletions
diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php
index 7f96702b768..ff7d6dfb1fd 100755
--- a/apps/files_encryption/lib/crypt.php
+++ b/apps/files_encryption/lib/crypt.php
@@ -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
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 89fe79b6ff5..a16bf941600 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -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 ), $filePath ) ) {
+ } elseif ( Crypt::isLegacyEncryptedContent( $this->view->file_get_contents( $filePath ), $relPath ) ) {
$found['legacy'][] = array( 'name' => $file, 'path' => $filePath );
@@ -342,6 +343,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
* @param string $dirPath the directory whose files will be encrypted
@@ -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'] );