\r
/**\r
* @brief Check if a file is encrypted via legacy system\r
+ * @param string $relPath The path of the file, relative to user/data;\r
+ * e.g. filename or /Docs/filename, NOT admin/files/filename\r
* @return true / false\r
*/\r
- public static function isLegacyEncryptedContent( $data, $path ) {\r
- \r
- $trimmed = ltrim( $path, '/' );\r
- \r
- // Path must not include user/files\r
- $split = explode( '/', $trimmed );\r
- $sliced = array_slice( $split, 2 );\r
- $relPath = implode( '/', $sliced );\r
+ public static function isLegacyEncryptedContent( $data, $relPath ) {\r
\r
// trigger_error("REL PATH = ".var_export($relPath, 1));\r
\r
// Fetch all file metadata from DB\r
$metadata = \OC\Files\Filesystem::getFileInfo( $relPath, '' );\r
\r
- trigger_error("PATH = ". var_export($trimmed, 1)." METADATA = ".var_export($metadata['encrypted'], 1));\r
+ trigger_error("PATH = ". var_export($relPath, 1)." METADATA = ".var_export($metadata['encrypted'], 1));\r
\r
// If a file is flagged with encryption in DB, but isn't a \r
// valid content + IV combination, it's probably using the \r
) {
$filePath = $directory . '/' . $this->view->getRelativePath( '/' . $file );
+ $relPath = $this->stripUserFilesPath( $filePath );
// If the path is a directory, search
// its contents
// 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 );
}
+ /**
+ * @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
// 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'] );
// 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'] );