* Base class for all encryption exception
*
* Possible Error Codes:
- * 10 - unknown error
+ * 10 - generic error
* 20 - unexpected end of encryption header
* 30 - unexpected blog size
* 40 - encryption header to large
* 90 - private key missing
*/
class EncryptionException extends \Exception {
- const UNKNOWN = 10;
+ const GENERIC = 10;
const UNEXPECTED_END_OF_ENCRYPTION_HEADER = 20;
const UNEXPECTED_BLOG_SIZE = 30;
const ENCRYPTION_HEADER_TO_LARGE = 40;
// file for which we want to delete the keys after the delete operation was successful\r
private static $deleteFiles = array();\r
// file for which we want to delete the keys after the delete operation was successful\r
- private static $umountedFiles = array();\r
+ private static $unmountedFiles = array();\r
\r
/**\r
* Startup encryption backend upon user login\r
\r
$path = \OC\Files\Filesystem::getPath($params['fileSource']);\r
\r
- self::updateKeyfiles($path, $params['itemType']);\r
+ self::updateKeyfiles($path);\r
}\r
}\r
\r
* update keyfiles and share keys recursively\r
*\r
* @param string $path to the file/folder\r
- * @param string $type 'file' or 'folder'\r
*/\r
- private static function updateKeyfiles($path, $type) {\r
+ private static function updateKeyfiles($path) {\r
$view = new \OC\Files\View('/');\r
$userId = \OCP\User::getUser();\r
$session = new \OCA\Encryption\Session($view);\r
$mountPoint = $mount->getMountPoint();\r
\r
// if a folder was shared, get a list of all (sub-)folders\r
- if ($type === 'folder') {\r
+ if ($view->is_dir('/' . $userId . '/files' . $path)) {\r
$allFiles = $util->getAllFiles($path, $mountPoint);\r
} else {\r
$allFiles = array($path);\r
\r
// Unshare every user who no longer has access to the file\r
$delUsers = array_diff($userIds, $sharingUsers);\r
-\r
- list($owner, $ownerPath) = $util->getUidAndFilename($path);\r
+ $keyPath = Keymanager::getKeyPath($view, $util, $path);\r
\r
// delete share key\r
- Keymanager::delShareKey($view, $delUsers, $ownerPath, $owner);\r
+ Keymanager::delShareKey($view, $delUsers, $keyPath, $userId, $path);\r
}\r
\r
}\r
$user = \OCP\User::getUser();\r
$view = new \OC\Files\View('/');\r
$util = new Util($view, $user);\r
- list($ownerOld, $pathOld) = $util->getUidAndFilename($params['oldpath']);\r
\r
// we only need to rename the keys if the rename happens on the same mountpoint\r
// otherwise we perform a stream copy, so we get a new set of keys\r
$mp1 = $view->getMountPoint('/' . $user . '/files/' . $params['oldpath']);\r
$mp2 = $view->getMountPoint('/' . $user . '/files/' . $params['newpath']);\r
\r
- $type = $view->is_dir('/' . $user . '/files/' . $params['oldpath']) ? 'folder' : 'file';\r
-\r
if ($mp1 === $mp2) {\r
- if ($util->isSystemWideMountPoint($pathOld)) {\r
- $oldShareKeyPath = 'files_encryption/share-keys/' . $pathOld;\r
- } else {\r
- $oldShareKeyPath = $ownerOld . '/' . 'files_encryption/share-keys/' . $pathOld;\r
- }\r
- // gather share keys here because in postRename() the file will be moved already\r
- $oldShareKeys = Helper::findShareKeys($pathOld, $oldShareKeyPath, $view);\r
- if (count($oldShareKeys) === 0) {\r
- \OC_Log::write(\r
- 'Encryption library', 'No share keys found for "' . $pathOld . '"',\r
- \OC_Log::WARN\r
- );\r
- }\r
+\r
+ $oldKeysPath = Keymanager::getKeyPath($view, $util, $params['oldpath']);\r
+\r
self::$renamedFiles[$params['oldpath']] = array(\r
- 'uid' => $ownerOld,\r
- 'path' => $pathOld,\r
- 'type' => $type,\r
'operation' => $operation,\r
- 'sharekeys' => $oldShareKeys\r
+ 'oldKeysPath' => $oldKeysPath,\r
);\r
\r
}\r
return true;\r
}\r
\r
- // Disable encryption proxy to prevent recursive calls\r
- $proxyStatus = \OC_FileProxy::$enabled;\r
- \OC_FileProxy::$enabled = false;\r
-\r
$view = new \OC\Files\View('/');\r
$userId = \OCP\User::getUser();\r
$util = new Util($view, $userId);\r
- $oldShareKeys = null;\r
\r
- if (isset(self::$renamedFiles[$params['oldpath']]['uid']) &&\r
- isset(self::$renamedFiles[$params['oldpath']]['path'])) {\r
- $ownerOld = self::$renamedFiles[$params['oldpath']]['uid'];\r
- $pathOld = self::$renamedFiles[$params['oldpath']]['path'];\r
- $type = self::$renamedFiles[$params['oldpath']]['type'];\r
+ if (isset(self::$renamedFiles[$params['oldpath']]['operation']) &&\r
+ isset(self::$renamedFiles[$params['oldpath']]['oldKeysPath'])) {\r
$operation = self::$renamedFiles[$params['oldpath']]['operation'];\r
- $oldShareKeys = self::$renamedFiles[$params['oldpath']]['sharekeys'];\r
+ $oldKeysPath = self::$renamedFiles[$params['oldpath']]['oldKeysPath'];\r
unset(self::$renamedFiles[$params['oldpath']]);\r
} else {\r
\OCP\Util::writeLog('Encryption library', "can't get path and owner from the file before it was renamed", \OCP\Util::DEBUG);\r
- \OC_FileProxy::$enabled = $proxyStatus;\r
return false;\r
}\r
\r
list($ownerNew, $pathNew) = $util->getUidAndFilename($params['newpath']);\r
\r
- // Format paths to be relative to user files dir\r
- if ($util->isSystemWideMountPoint($pathOld)) {\r
- $oldKeyfilePath = 'files_encryption/keyfiles/' . $pathOld;\r
- $oldShareKeyPath = 'files_encryption/share-keys/' . $pathOld;\r
- } else {\r
- $oldKeyfilePath = $ownerOld . '/' . 'files_encryption/keyfiles/' . $pathOld;\r
- $oldShareKeyPath = $ownerOld . '/' . 'files_encryption/share-keys/' . $pathOld;\r
- }\r
-\r
if ($util->isSystemWideMountPoint($pathNew)) {\r
- $newKeyfilePath = 'files_encryption/keyfiles/' . $pathNew;\r
- $newShareKeyPath = 'files_encryption/share-keys/' . $pathNew;\r
- } else {\r
- $newKeyfilePath = $ownerNew . '/files_encryption/keyfiles/' . $pathNew;\r
- $newShareKeyPath = $ownerNew . '/files_encryption/share-keys/' . $pathNew;\r
- }\r
-\r
- // create new key folders if it doesn't exists\r
- if (!$view->file_exists(dirname($newShareKeyPath))) {\r
- $view->mkdir(dirname($newShareKeyPath));\r
- }\r
- if (!$view->file_exists(dirname($newKeyfilePath))) {\r
- $view->mkdir(dirname($newKeyfilePath));\r
- }\r
-\r
- // handle share keys\r
- if ($type === 'file') {\r
- $oldKeyfilePath .= '.key';\r
- $newKeyfilePath .= '.key';\r
-\r
- foreach ($oldShareKeys as $src) {\r
- $dst = \OC\Files\Filesystem::normalizePath(str_replace($pathOld, $pathNew, $src));\r
- $view->$operation($src, $dst);\r
- }\r
-\r
+ $newKeysPath = 'files_encryption/keys/' . $pathNew;\r
} else {\r
- // handle share-keys folders\r
- $view->$operation($oldShareKeyPath, $newShareKeyPath);\r
+ $newKeysPath = $ownerNew . '/files_encryption/keys/' . $pathNew;\r
}\r
\r
- // Rename keyfile so it isn't orphaned\r
- if ($view->file_exists($oldKeyfilePath)) {\r
- $view->$operation($oldKeyfilePath, $newKeyfilePath);\r
+ // create key folders if it doesn't exists\r
+ if (!$view->file_exists(dirname($newKeysPath))) {\r
+ $view->mkdir(dirname($newKeysPath));\r
}\r
\r
+ $view->$operation($oldKeysPath, $newKeysPath);\r
\r
// update sharing-keys\r
- self::updateKeyfiles($params['newpath'], $type);\r
-\r
- \OC_FileProxy::$enabled = $proxyStatus;\r
+ self::updateKeyfiles($params['newpath']);\r
}\r
\r
/**\r
*/\r
public static function postDelete($params) {\r
\r
- if (!isset(self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]])) {\r
+ $path = $params[\OC\Files\Filesystem::signal_param_path];\r
+\r
+ if (!isset(self::$deleteFiles[$path])) {\r
return true;\r
}\r
\r
- $deletedFile = self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]];\r
- $path = $deletedFile['path'];\r
- $user = $deletedFile['uid'];\r
+ $deletedFile = self::$deleteFiles[$path];\r
+ $keyPath = $deletedFile['keyPath'];\r
\r
// we don't need to remember the file any longer\r
- unset(self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]]);\r
+ unset(self::$deleteFiles[$path]);\r
\r
$view = new \OC\Files\View('/');\r
\r
// return if the file still exists and wasn't deleted correctly\r
- if ($view->file_exists('/' . $user . '/files/' . $path)) {\r
+ if ($view->file_exists('/' . \OCP\User::getUser() . '/files/' . $path)) {\r
return true;\r
}\r
\r
- // Disable encryption proxy to prevent recursive calls\r
- $proxyStatus = \OC_FileProxy::$enabled;\r
- \OC_FileProxy::$enabled = false;\r
-\r
// Delete keyfile & shareKey so it isn't orphaned\r
- if (!Keymanager::deleteFileKey($view, $path, $user)) {\r
- \OCP\Util::writeLog('Encryption library',\r
- 'Keyfile or shareKey could not be deleted for file "' . $user.'/files/'.$path . '"', \OCP\Util::ERROR);\r
- }\r
-\r
- Keymanager::delAllShareKeys($view, $user, $path);\r
+ $view->unlink($keyPath);\r
\r
- \OC_FileProxy::$enabled = $proxyStatus;\r
}\r
\r
/**\r
* @return boolean|null\r
*/\r
public static function preDelete($params) {\r
+ $view = new \OC\Files\View('/');\r
$path = $params[\OC\Files\Filesystem::signal_param_path];\r
\r
// skip this method if the trash bin is enabled or if we delete a file\r
}\r
\r
$util = new Util(new \OC\Files\View('/'), \OCP\USER::getUser());\r
- list($owner, $ownerPath) = $util->getUidAndFilename($path);\r
\r
- self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]] = array(\r
- 'uid' => $owner,\r
- 'path' => $ownerPath);\r
+ $keysPath = Keymanager::getKeyPath($view, $util, $path);\r
+\r
+ self::$deleteFiles[$path] = array(\r
+ 'keyPath' => $keysPath);\r
}\r
\r
/**\r
* unmount file from yourself\r
* remember files/folders which get unmounted\r
*/\r
- public static function preUmount($params) {\r
+ public static function preUnmount($params) {\r
+ $view = new \OC\Files\View('/');\r
+ $user = \OCP\User::getUser();\r
$path = $params[\OC\Files\Filesystem::signal_param_path];\r
- $user = \OCP\USER::getUser();\r
-\r
- $view = new \OC\Files\View();\r
- $itemType = $view->is_dir('/' . $user . '/files' . $path) ? 'folder' : 'file';\r
\r
$util = new Util($view, $user);\r
list($owner, $ownerPath) = $util->getUidAndFilename($path);\r
\r
- self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]] = array(\r
- 'uid' => $owner,\r
- 'path' => $ownerPath,\r
- 'itemType' => $itemType);\r
+ $keysPath = Keymanager::getKeyPath($view, $util, $path);\r
+\r
+ self::$unmountedFiles[$path] = array(\r
+ 'keyPath' => $keysPath,\r
+ 'owner' => $owner,\r
+ 'ownerPath' => $ownerPath\r
+ );\r
}\r
\r
/**\r
* unmount file from yourself\r
*/\r
- public static function postUmount($params) {\r
+ public static function postUnmount($params) {\r
+\r
+ $path = $params[\OC\Files\Filesystem::signal_param_path];\r
+ $user = \OCP\User::getUser();\r
\r
- if (!isset(self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]])) {\r
+ if (!isset(self::$unmountedFiles[$path])) {\r
return true;\r
}\r
\r
- $umountedFile = self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]];\r
- $path = $umountedFile['path'];\r
- $user = $umountedFile['uid'];\r
- $itemType = $umountedFile['itemType'];\r
+ $umountedFile = self::$unmountedFiles[$path];\r
+ $keyPath = $umountedFile['keyPath'];\r
+ $owner = $umountedFile['owner'];\r
+ $ownerPath = $umountedFile['ownerPath'];\r
\r
$view = new \OC\Files\View();\r
- $util = new Util($view, $user);\r
\r
// we don't need to remember the file any longer\r
- unset(self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]]);\r
-\r
- // if we unshare a folder we need a list of all (sub-)files\r
- if ($itemType === 'folder') {\r
- $allFiles = $util->getAllFiles($path);\r
- } else {\r
- $allFiles = array($path);\r
- }\r
+ unset(self::$unmountedFiles[$path]);\r
\r
- foreach ($allFiles as $path) {\r
-\r
- // check if the user still has access to the file, otherwise delete share key\r
- $sharingUsers = \OCP\Share::getUsersSharingFile($path, $user);\r
- if (!in_array(\OCP\User::getUser(), $sharingUsers['users'])) {\r
- Keymanager::delShareKey($view, array(\OCP\User::getUser()), $path, $user);\r
- }\r
+ // check if the user still has access to the file, otherwise delete share key\r
+ $sharingUsers = \OCP\Share::getUsersSharingFile($path, $user);\r
+ if (!in_array(\OCP\User::getUser(), $sharingUsers['users'])) {\r
+ Keymanager::delShareKey($view, array(\OCP\User::getUser()), $keyPath, $owner, $ownerPath);\r
}\r
}\r
\r
\OCP\Util::connectHook('OC_Filesystem', 'post_copy', 'OCA\Encryption\Hooks', 'postRenameOrCopy');
\OCP\Util::connectHook('OC_Filesystem', 'post_delete', 'OCA\Encryption\Hooks', 'postDelete');
\OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Encryption\Hooks', 'preDelete');
- \OCP\Util::connectHook('OC_Filesystem', 'post_umount', 'OCA\Encryption\Hooks', 'postUmount');
- \OCP\Util::connectHook('OC_Filesystem', 'umount', 'OCA\Encryption\Hooks', 'preUmount');
\OCP\Util::connectHook('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', 'OCA\Encryption\Hooks', 'postPasswordReset');
+ \OCP\Util::connectHook('OC_Filesystem', 'post_umount', 'OCA\Encryption\Hooks', 'postUnmount');
+ \OCP\Util::connectHook('OC_Filesystem', 'umount', 'OCA\Encryption\Hooks', 'preUnmount');
}
/**
return $config;
}
- /**
- * find all share keys for a given file
- *
- * @param string $filePath path to the file name relative to the user's files dir
- * for example "subdir/filename.txt"
- * @param string $shareKeyPath share key prefix path relative to the user's data dir
- * for example "user1/files_encryption/share-keys/subdir/filename.txt"
- * @param \OC\Files\View $rootView root view, relative to data/
- * @return array list of share key files, path relative to data/$user
- */
- public static function findShareKeys($filePath, $shareKeyPath, \OC\Files\View $rootView) {
- $result = array();
-
- $user = \OCP\User::getUser();
- $util = new Util($rootView, $user);
- // get current sharing state
- $sharingEnabled = \OCP\Share::isEnabled();
-
- // get users sharing this file
- $usersSharing = $util->getSharingUsersArray($sharingEnabled, $filePath);
-
- $pathinfo = pathinfo($shareKeyPath);
-
- $baseDir = $pathinfo['dirname'] . '/';
- $fileName = $pathinfo['basename'];
- foreach ($usersSharing as $user) {
- $keyName = $fileName . '.' . $user . '.shareKey';
- if ($rootView->file_exists($baseDir . $keyName)) {
- $result[] = $baseDir . $keyName;
- } else {
- \OC_Log::write(
- 'Encryption library',
- 'No share key found for user "' . $user . '" for file "' . $fileName . '"',
- \OC_Log::WARN
- );
- }
- }
-
- return $result;
- }
-
/**
* remember from which file the tmp file (getLocalFile() call) was created
* @param string $tmpFile path of tmp file
*/
class Keymanager {
+ // base dir where all the file related keys are stored
+ const KEYS_BASE_DIR = '/files_encryption/keys/';
+
/**
* retrieve the ENCRYPTED private key from a user
*
$path = '/' . $user . '/' . 'files_encryption' . '/' . $user . '.private.key';
$key = false;
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
if ($view->file_exists($path)) {
$key = $view->file_get_contents($path);
}
- \OC_FileProxy::$enabled = $proxyStatus;
-
return $key;
}
*/
public static function getPublicKey(\OC\Files\View $view, $userId) {
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
$result = $view->file_get_contents('/public-keys/' . $userId . '.public.key');
- \OC_FileProxy::$enabled = $proxyStatus;
-
return $result;
}
$keys = array();
foreach ($userIds as $userId) {
-
$keys[$userId] = self::getPublicKey($view, $userId);
-
}
return $keys;
*/
public static function setFileKey(\OC\Files\View $view, $util, $path, $catfile) {
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
- list($owner, $filename) = $util->getUidAndFilename($path);
-
- // in case of system wide mount points the keys are stored directly in the data directory
- if ($util->isSystemWideMountPoint($filename)) {
- $basePath = '/files_encryption/keyfiles';
- } else {
- $basePath = '/' . $owner . '/files_encryption/keyfiles';
- }
+ $basePath = self::getKeyPath($view, $util, $path);
- $targetPath = self::keySetPreparation($view, $filename, $basePath);
+ self::keySetPreparation($view, $basePath);
- // try reusing key file if part file
- if (Helper::isPartialFilePath($targetPath)) {
-
- $result = $view->file_put_contents(
- $basePath . '/' . Helper::stripPartialFileExtension($targetPath) . '.key', $catfile);
-
- } else {
-
- $result = $view->file_put_contents($basePath . '/' . $targetPath . '.key', $catfile);
-
- }
-
- \OC_FileProxy::$enabled = $proxyStatus;
+ $result = $view->file_put_contents(
+ $basePath . '/fileKey', $catfile);
return $result;
}
/**
- * retrieve keyfile for an encrypted file
- * @param \OC\Files\View $view
+ * get path to key folder for a given file
+ *
+ * @param \OC\Files\View $view relative to data directory
* @param \OCA\Encryption\Util $util
- * @param string|false $filePath
- * @internal param \OCA\Encryption\file $string name
- * @return string file key or false
- * @note The keyfile returned is asymmetrically encrypted. Decryption
- * of the keyfile must be performed by client code
+ * @param string $path path to the file, relative to the users file directory
+ * @return string
*/
- public static function getFileKey($view, $util, $filePath) {
+ public static function getKeyPath($view, $util, $path) {
+ if ($view->is_dir('/' . \OCP\User::getUser() . '/' . $path)) {
+ throw new Exception\EncryptionException('file was expected but directoy was given', Exception\EncryptionException::GENERIC);
+ }
- list($owner, $filename) = $util->getUidAndFilename($filePath);
+ list($owner, $filename) = $util->getUidAndFilename($path);
$filename = Helper::stripPartialFileExtension($filename);
$filePath_f = ltrim($filename, '/');
// in case of system wide mount points the keys are stored directly in the data directory
if ($util->isSystemWideMountPoint($filename)) {
- $keyfilePath = '/files_encryption/keyfiles/' . $filePath_f . '.key';
+ $keyPath = self::KEYS_BASE_DIR . $filePath_f . '/';
} else {
- $keyfilePath = '/' . $owner . '/files_encryption/keyfiles/' . $filePath_f . '.key';
+ $keyPath = '/' . $owner . self::KEYS_BASE_DIR . $filePath_f . '/';
}
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
- if ($view->file_exists($keyfilePath)) {
-
- $result = $view->file_get_contents($keyfilePath);
-
- } else {
+ return $keyPath;
+ }
- $result = false;
+ /**
+ * get path to file key for a given file
+ *
+ * @param \OC\Files\View $view relative to data directory
+ * @param \OCA\Encryption\Util $util
+ * @param string $path path to the file, relative to the users file directory
+ * @return string
+ */
+ public static function getFileKeyPath($view, $util, $path) {
+ if ($view->is_dir('/' . \OCP\User::getUser() . '/' . $path)) {
+ throw new Exception\EncryptionException('file was expected but directoy was given', Exception\EncryptionException::GENERIC);
}
- \OC_FileProxy::$enabled = $proxyStatus;
+ list($owner, $filename) = $util->getUidAndFilename($path);
+ $filename = Helper::stripPartialFileExtension($filename);
+ $filePath_f = ltrim($filename, '/');
- return $result;
+ // in case of system wide mount points the keys are stored directly in the data directory
+ if ($util->isSystemWideMountPoint($filename)) {
+ $keyfilePath = self::KEYS_BASE_DIR . $filePath_f . '/fileKey';
+ } else {
+ $keyfilePath = '/' . $owner . self::KEYS_BASE_DIR . $filePath_f . '/fileKey';
+ }
+ return $keyfilePath;
}
/**
- * Delete a keyfile
+ * get path to share key for a given user
*
- * @param \OC\Files\View $view
- * @param string $path path of the file the key belongs to
- * @param string $userId the user to whom the file belongs
- * @return bool Outcome of unlink operation
- * @note $path must be relative to data/user/files. e.g. mydoc.txt NOT
- * /data/admin/files/mydoc.txt
+ * @param \OC\Files\View $view relateive to data directory
+ * @param \OCA\Encryption\Util $util
+ * @param string $path path to file relative to the users files directoy
+ * @param string $uid user for whom we want the share-key path
+ * @retrun string
*/
- public static function deleteFileKey($view, $path, $userId=null) {
-
- $trimmed = ltrim($path, '/');
+ public static function getShareKeyPath($view, $util, $path, $uid) {
- if ($trimmed === '') {
- \OCP\Util::writeLog('Encryption library',
- 'Can\'t delete file-key empty path given!', \OCP\Util::ERROR);
- return false;
+ if ($view->is_dir('/' . \OCP\User::getUser() . '/' . $path)) {
+ throw new Exception\EncryptionException('file was expected but directoy was given', Exception\EncryptionException::GENERIC);
}
- if ($userId === null) {
- $userId = Helper::getUser($path);
- }
- $util = new Util($view, $userId);
+ list($owner, $filename) = $util->getUidAndFilename($path);
+ $filename = Helper::stripPartialFileExtension($filename);
- if($util->isSystemWideMountPoint($path)) {
- $keyPath = '/files_encryption/keyfiles/' . $trimmed;
+ // in case of system wide mount points the keys are stored directly in the data directory
+ if ($util->isSystemWideMountPoint($filename)) {
+ $shareKeyPath = self::KEYS_BASE_DIR . $filename . '/'. $uid . '.shareKey';
} else {
- $keyPath = '/' . $userId . '/files_encryption/keyfiles/' . $trimmed;
+ $shareKeyPath = '/' . $owner . self::KEYS_BASE_DIR . $filename . '/' . $uid . '.shareKey';
}
- $result = false;
- $fileExists = $view->file_exists('/' . $userId . '/files/' . $trimmed);
+ return $shareKeyPath;
+ }
- if ($view->is_dir($keyPath) && !$fileExists) {
- \OCP\Util::writeLog('files_encryption', 'deleteFileKey: delete file key: ' . $keyPath, \OCP\Util::DEBUG);
- $result = $view->unlink($keyPath);
- } elseif ($view->file_exists($keyPath . '.key') && !$fileExists) {
- \OCP\Util::writeLog('files_encryption', 'deleteFileKey: delete file key: ' . $keyPath, \OCP\Util::DEBUG);
- $result = $view->unlink($keyPath . '.key');
- }
- if ($fileExists) {
- \OCP\Util::writeLog('Encryption library',
- 'Did not delete the file key, file still exists: ' . '/' . $userId . '/files/' . $trimmed, \OCP\Util::ERROR);
- } elseif (!$result) {
- \OCP\Util::writeLog('Encryption library',
- 'Could not delete keyfile; does not exist: "' . $keyPath, \OCP\Util::ERROR);
+ /**
+ * retrieve keyfile for an encrypted file
+ * @param \OC\Files\View $view
+ * @param \OCA\Encryption\Util $util
+ * @param string|false $filePath
+ * @internal param \OCA\Encryption\file $string name
+ * @return string file key or false
+ * @note The keyfile returned is asymmetrically encrypted. Decryption
+ * of the keyfile must be performed by client code
+ */
+ public static function getFileKey($view, $util, $filePath) {
+
+ $keyfilePath = self::getFileKeyPath($view, $util, $filePath);
+
+ if ($view->file_exists($keyfilePath)) {
+ $result = $view->file_get_contents($keyfilePath);
+ } else {
+ $result = false;
}
return $result;
* @param array $shareKeys
* @return bool
*/
- public static function setShareKeys(\OC\Files\View $view, $util, $path, array $shareKeys) {
-
- // $shareKeys must be an array with the following format:
- // [userId] => [encrypted key]
-
- list($owner, $filename) = $util->getUidAndFilename($path);
+ public static function setShareKeys($view, $util, $path, array $shareKeys) {
// in case of system wide mount points the keys are stored directly in the data directory
- if ($util->isSystemWideMountPoint($filename)) {
- $basePath = '/files_encryption/share-keys';
- } else {
- $basePath = '/' . $owner . '/files_encryption/share-keys';
- }
+ $basePath = Keymanager::getKeyPath($view, $util, $path);
- $shareKeyPath = self::keySetPreparation($view, $filename, $basePath);
+ self::keySetPreparation($view, $basePath);
$result = true;
foreach ($shareKeys as $userId => $shareKey) {
- // try reusing key file if part file
- if (Helper::isPartialFilePath($shareKeyPath)) {
- $writePath = $basePath . '/' . Helper::stripPartialFileExtension($shareKeyPath) . '.' . $userId . '.shareKey';
- } else {
- $writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey';
- }
+ $writePath = $basePath . '/' . $userId . '.shareKey';
if (!self::setShareKey($view, $writePath, $shareKey)) {
* @note The sharekey returned is encrypted. Decryption
* of the keyfile must be performed by client code
*/
- public static function getShareKey(\OC\Files\View $view, $userId, $util, $filePath) {
+ public static function getShareKey($view, $userId, $util, $filePath) {
- // try reusing key file if part file
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
- list($owner, $filename) = $util->getUidAndFilename($filePath);
- $filename = Helper::stripPartialFileExtension($filename);
- // in case of system wide mount points the keys are stored directly in the data directory
- if ($util->isSystemWideMountPoint($filename)) {
- $shareKeyPath = '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey';
- } else {
- $shareKeyPath = '/' . $owner . '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey';
- }
+ $shareKeyPath = self::getShareKeyPath($view, $util, $filePath, $userId);
if ($view->file_exists($shareKeyPath)) {
-
$result = $view->file_get_contents($shareKeyPath);
-
} else {
-
$result = false;
-
}
- \OC_FileProxy::$enabled = $proxyStatus;
-
return $result;
-
- }
-
- /**
- * delete all share keys of a given file
- * @param \OC\Files\View $view
- * @param string $userId owner of the file
- * @param string $filePath path to the file, relative to the owners file dir
- */
- public static function delAllShareKeys($view, $userId, $filePath) {
-
- $filePath = ltrim($filePath, '/');
-
- if ($view->file_exists('/' . $userId . '/files/' . $filePath)) {
- \OCP\Util::writeLog('Encryption library',
- 'File still exists, stop deleting share keys!', \OCP\Util::ERROR);
- return false;
- }
-
- if ($filePath === '') {
- \OCP\Util::writeLog('Encryption library',
- 'Can\'t delete share-keys empty path given!', \OCP\Util::ERROR);
- return false;
- }
-
- $util = new util($view, $userId);
-
- if ($util->isSystemWideMountPoint($filePath)) {
- $baseDir = '/files_encryption/share-keys/';
- } else {
- $baseDir = $userId . '/files_encryption/share-keys/';
- }
-
- $result = true;
-
- if ($view->is_dir($baseDir . $filePath)) {
- \OCP\Util::writeLog('files_encryption', 'delAllShareKeys: delete share keys: ' . $baseDir . $filePath, \OCP\Util::DEBUG);
- $result = $view->unlink($baseDir . $filePath);
- } else {
- $sharingEnabled = \OCP\Share::isEnabled();
- $users = $util->getSharingUsersArray($sharingEnabled, $filePath);
- foreach($users as $user) {
- $keyName = $baseDir . $filePath . '.' . $user . '.shareKey';
- if ($view->file_exists($keyName)) {
- \OCP\Util::writeLog(
- 'files_encryption',
- 'dellAllShareKeys: delete share keys: "' . $keyName . '"',
- \OCP\Util::DEBUG
- );
- $result &= $view->unlink($keyName);
- }
- }
- }
-
- return (bool)$result;
}
/**
*
* @param \OC\Files\View $view relative to data/
* @param array $userIds list of users we want to remove
- * @param string $filename the owners name of the file for which we want to remove the users relative to data/user/files
- * @param string $owner owner of the file
+ * @param string $keyPath
+ * @param string $owner the owner of the file
+ * @param string $ownerPath the owners name of the file for which we want to remove the users relative to data/user/files
*/
- public static function delShareKey($view, $userIds, $filename, $owner) {
+ public static function delShareKey($view, $userIds, $keysPath, $owner, $ownerPath) {
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
- $util = new Util($view, $owner);
-
- if ($util->isSystemWideMountPoint($filename)) {
- $shareKeyPath = \OC\Files\Filesystem::normalizePath('/files_encryption/share-keys/' . $filename);
- } else {
- $shareKeyPath = \OC\Files\Filesystem::normalizePath('/' . $owner . '/files_encryption/share-keys/' . $filename);
+ $key = array_search($owner, $userIds, true);
+ if ($key !== false && $view->file_exists('/' . $owner . '/files/' . $ownerPath)) {
+ unset($userIds[$key]);
}
- if ($view->is_dir($shareKeyPath)) {
-
- self::recursiveDelShareKeys($shareKeyPath, $userIds, $owner, $view);
-
- } else {
-
- foreach ($userIds as $userId) {
-
- if ($userId === $owner && $view->file_exists('/' . $owner . '/files/' . $filename)) {
- \OCP\Util::writeLog('files_encryption', 'Tried to delete owner key, but the file still exists!', \OCP\Util::FATAL);
- continue;
- }
- $result = $view->unlink($shareKeyPath . '.' . $userId . '.shareKey');
- \OCP\Util::writeLog('files_encryption', 'delShareKey: delete share key: ' . $shareKeyPath . '.' . $userId . '.shareKey' , \OCP\Util::DEBUG);
- if (!$result) {
- \OCP\Util::writeLog('Encryption library',
- 'Could not delete shareKey; does not exist: "' . $shareKeyPath . '.' . $userId
- . '.shareKey"', \OCP\Util::ERROR);
- }
- }
- }
+ self::recursiveDelShareKeys($keysPath, $userIds, $view);
- \OC_FileProxy::$enabled = $proxyStatus;
}
/**
*
* @param string $dir directory
* @param array $userIds user ids for which the share keys should be deleted
- * @param string $owner owner of the file
* @param \OC\Files\View $view view relative to data/
*/
- private static function recursiveDelShareKeys($dir, $userIds, $owner, $view) {
+ private static function recursiveDelShareKeys($dir, $userIds, $view) {
$dirContent = $view->opendir($dir);
- $dirSlices = explode('/', ltrim($dir, '/'));
- $realFileDir = '/' . $owner . '/files/' . implode('/', array_slice($dirSlices, 3)) . '/';
if (is_resource($dirContent)) {
while (($file = readdir($dirContent)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if ($view->is_dir($dir . '/' . $file)) {
- self::recursiveDelShareKeys($dir . '/' . $file, $userIds, $owner, $view);
+ self::recursiveDelShareKeys($dir . '/' . $file, $userIds, $view);
} else {
foreach ($userIds as $userId) {
- $fileNameFromShareKey = self::getFilenameFromShareKey($file, $userId);
- if (!$fileNameFromShareKey) {
- continue;
- }
- $realFile = $realFileDir . $fileNameFromShareKey;
-
- if ($userId === $owner &&
- $view->file_exists($realFile)) {
- \OCP\Util::writeLog('files_encryption', 'original file still exists, keep owners share key!', \OCP\Util::ERROR);
- continue;
+ if ($userId . '.shareKey' === $file) {
+ \OCP\Util::writeLog('files_encryption', 'recursiveDelShareKey: delete share key: ' . $file, \OCP\Util::DEBUG);
+ $view->unlink($dir . '/' . $file);
}
- \OCP\Util::writeLog('files_encryption', 'recursiveDelShareKey: delete share key: ' . $file, \OCP\Util::DEBUG);
- $view->unlink($dir . '/' . $file);
}
}
}
/**
* Make preparations to vars and filesystem for saving a keyfile
- * @param string|boolean $path
+ *
+ * @param \OC\Files\View $view
+ * @param string $path relatvie to the views root
* @param string $basePath
*/
- protected static function keySetPreparation(\OC\Files\View $view, $path, $basePath) {
-
- $targetPath = ltrim($path, '/');
-
- $path_parts = pathinfo($targetPath);
+ protected static function keySetPreparation($view, $path) {
// If the file resides within a subdirectory, create it
- if (
- isset($path_parts['dirname'])
- && !$view->file_exists($basePath . '/' . $path_parts['dirname'])
- ) {
- $sub_dirs = explode('/', $basePath . '/' . $path_parts['dirname']);
+ if (!$view->file_exists($path)) {
+ $sub_dirs = explode('/', $path);
$dir = '';
foreach ($sub_dirs as $sub_dir) {
$dir .= '/' . $sub_dir;
}
}
}
-
- return $targetPath;
-
}
- /**
- * extract filename from share key name
- * @param string $shareKey (filename.userid.sharekey)
- * @param string $userId
- * @return string|false filename or false
- */
- protected static function getFilenameFromShareKey($shareKey, $userId) {
- $expectedSuffix = '.' . $userId . '.' . 'shareKey';
- $suffixLen = strlen($expectedSuffix);
-
- $suffix = substr($shareKey, -$suffixLen);
-
- if ($suffix !== $expectedSuffix) {
- return false;
- }
-
- return substr($shareKey, 0, -$suffixLen);
- }
}
public function postFile_get_contents($path, $data) {
$plainData = null;
- $view = new \OC\Files\View('/');
// If data is a catfile
if (
Crypt::mode() === 'server'
+ && $this->shouldEncrypt($path)
&& Crypt::isCatfileContent($data)
) {
private $client; // Client side encryption mode flag
private $publicKeyDir; // Dir containing all public user keys
private $encryptionDir; // Dir containing user's files_encryption
- private $keyfilesPath; // Dir containing user's keyfiles
- private $shareKeysPath; // Dir containing env keys for shared files
+ private $keysPath; // Dir containing all file related encryption keys
private $publicKeyPath; // Path to user's public key
private $privateKeyPath; // Path to user's private key
+ private $userFilesDir;
private $publicShareKeyId;
private $recoveryKeyId;
private $isPublic;
'/' . $userId . '/' . $this->fileFolderName; // TODO: Does this need to be user configurable?
$this->publicKeyDir = '/' . 'public-keys';
$this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption';
- $this->keyfilesPath = $this->encryptionDir . '/' . 'keyfiles';
- $this->shareKeysPath = $this->encryptionDir . '/' . 'share-keys';
+ $this->keysPath = $this->encryptionDir . '/' . 'keys';
$this->publicKeyPath =
$this->publicKeyDir . '/' . $this->userId . '.public.key'; // e.g. data/public-keys/admin.public.key
$this->privateKeyPath =
if (
!$this->view->file_exists($this->encryptionDir)
- or !$this->view->file_exists($this->keyfilesPath)
- or !$this->view->file_exists($this->shareKeysPath)
+ or !$this->view->file_exists($this->keysPath)
or !$this->view->file_exists($this->publicKeyPath)
or !$this->view->file_exists($this->privateKeyPath)
) {
$this->userDir,
$this->publicKeyDir,
$this->encryptionDir,
- $this->keyfilesPath,
- $this->shareKeysPath
+ $this->keysPath
);
// Check / create all necessary dirs
}
if ($successful) {
- $this->view->rename($this->keyfilesPath, $this->keyfilesPath . '.backup');
- $this->view->rename($this->shareKeysPath, $this->shareKeysPath . '.backup');
+ $this->backupAllKeys('decryptAll');
+ $this->view->deleteAll($this->keysPath);
}
\OC_FileProxy::$enabled = true;
break;
- case 'keyfilesPath':
+ case 'keysPath':
- return $this->keyfilesPath;
+ return $this->keysPath;
break;
* add recovery key to all encrypted files
*/
public function addRecoveryKeys($path = '/') {
- $dirContent = $this->view->getDirectoryContent($this->keyfilesPath . $path);
+ $dirContent = $this->view->getDirectoryContent($this->keysPath . '/' . $path);
foreach ($dirContent as $item) {
// get relative path from files_encryption/keyfiles/
- $filePath = substr($item['path'], strlen('files_encryption/keyfiles'));
- if ($item['type'] === 'dir') {
+ $filePath = substr($item['path'], strlen('files_encryption/keys'));
+ if ($this->view->is_dir($this->userFilesDir . '/' . $filePath)) {
$this->addRecoveryKeys($filePath . '/');
} else {
$session = new \OCA\Encryption\Session(new \OC\Files\View('/'));
$sharingEnabled = \OCP\Share::isEnabled();
- // remove '.key' extension from path e.g. 'file.txt.key' to 'file.txt'
- $file = substr($filePath, 0, -4);
- $usersSharing = $this->getSharingUsersArray($sharingEnabled, $file);
- $this->setSharedFileKeyfiles($session, $usersSharing, $file);
+ $usersSharing = $this->getSharingUsersArray($sharingEnabled, $filePath);
+ $this->setSharedFileKeyfiles($session, $usersSharing, $filePath);
}
}
}
* remove recovery key to all encrypted files
*/
public function removeRecoveryKeys($path = '/') {
- $dirContent = $this->view->getDirectoryContent($this->keyfilesPath . $path);
+ $dirContent = $this->view->getDirectoryContent($this->keysPath . '/' . $path);
foreach ($dirContent as $item) {
// get relative path from files_encryption/keyfiles
- $filePath = substr($item['path'], strlen('files_encryption/keyfiles'));
- if ($item['type'] === 'dir') {
+ $filePath = substr($item['path'], strlen('files_encryption/keys'));
+ if ($this->view->is_dir($this->userFilesDir . '/' . $filePath)) {
$this->removeRecoveryKeys($filePath . '/');
} else {
- // remove '.key' extension from path e.g. 'file.txt.key' to 'file.txt'
- $file = substr($filePath, 0, -4);
- $this->view->unlink($this->shareKeysPath . '/' . $file . '.' . $this->recoveryKeyId . '.shareKey');
+ $this->view->unlink($this->keysPath . '/' . $filePath . '/' . $this->recoveryKeyId . '.shareKey');
}
}
}
}
$filteredUids = $this->filterShareReadyUsers($userIds);
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
//decrypt file key
- $encKeyfile = $this->view->file_get_contents($this->keyfilesPath . $file . ".key");
- $shareKey = $this->view->file_get_contents(
- $this->shareKeysPath . $file . "." . $this->recoveryKeyId . ".shareKey");
+ $encKeyfile = Keymanager::getFileKey($this->view, $this, $file);
+ $shareKey = Keymanager::getShareKey($this->view, $this->recoveryKeyId, $this, $file);
$plainKeyfile = Crypt::multiKeyDecrypt($encKeyfile, $shareKey, $privateKey);
// encrypt file key again to all users, this time with the new public key for the recovered use
$userPubKeys = Keymanager::getPublicKeys($this->view, $filteredUids['ready']);
$multiEncKey = Crypt::multiKeyEncrypt($plainKeyfile, $userPubKeys);
- // write new keys to filesystem TDOO!
- $this->view->file_put_contents($this->keyfilesPath . $file . '.key', $multiEncKey['data']);
- foreach ($multiEncKey['keys'] as $userId => $shareKey) {
- $shareKeyPath = $this->shareKeysPath . $file . '.' . $userId . '.shareKey';
- $this->view->file_put_contents($shareKeyPath, $shareKey);
- }
+ Keymanager::setFileKey($this->view, $this, $file, $multiEncKey['data']);
+ Keymanager::setShareKeys($this->view, $this, $file, $multiEncKey['keys']);
- // Return proxy to original status
- \OC_FileProxy::$enabled = $proxyStatus;
}
/**
* @param string $privateKey private recovery key which is used to decrypt the files
*/
private function recoverAllFiles($path, $privateKey) {
- $dirContent = $this->view->getDirectoryContent($this->keyfilesPath . $path);
+ $dirContent = $this->view->getDirectoryContent($this->keysPath . '/' . $path);
foreach ($dirContent as $item) {
// get relative path from files_encryption/keyfiles
- $filePath = substr($item['path'], strlen('files_encryption/keyfiles'));
- if ($item['type'] === 'dir') {
+ $filePath = substr($item['path'], strlen('files_encryption/keys'));
+ if ($this->view->is_dir($this->userFilesDir . '/' . $filePath)) {
$this->recoverAllFiles($filePath . '/', $privateKey);
} else {
- // remove '.key' extension from path e.g. 'file.txt.key' to 'file.txt'
- $file = substr($filePath, 0, -4);
- $this->recoverFile($file, $privateKey);
+ $this->recoverFile($filePath, $privateKey);
}
}
}
$backupDir = $this->encryptionDir . '/backup.';
$backupDir .= ($purpose === '') ? date("Y-m-d_H-i-s") . '/' : $purpose . '.' . date("Y-m-d_H-i-s") . '/';
$this->view->mkdir($backupDir);
- $this->view->copy($this->shareKeysPath, $backupDir . 'share-keys/');
- $this->view->copy($this->keyfilesPath, $backupDir . 'keyfiles/');
+ $this->view->copy($this->keysPath, $backupDir . 'keys/');
$this->view->copy($this->privateKeyPath, $backupDir . $this->userId . '.private.key');
$this->view->copy($this->publicKeyPath, $backupDir . $this->userId . '.public.key');
}
// Teardown
$this->view->unlink($this->userId . '/files/' . $filename);
-
- Encryption\Keymanager::deleteFileKey($this->view, $filename);
}
/**
// Teardown
$this->view->unlink($this->userId . '/files/' . $filename);
-
- Encryption\Keymanager::deleteFileKey($this->view, $filename);
}
/**
$this->assertEquals($this->dataLong . $this->dataLong, $decrypted);
// Teardown
-
$this->view->unlink($this->userId . '/files/' . $filename);
-
- Encryption\Keymanager::deleteFileKey($this->view, $filename);
-
}
/**
$this->assertEquals($this->dataLong . $this->dataLong, $decrypted);
// Teardown
-
$this->view->unlink($this->userId . '/files/' . $filename);
-
- Encryption\Keymanager::deleteFileKey($this->view, $filename);
-
}
/**
$this->assertEquals($this->dataLong . $this->dataLong, $decrypted);
// Teardown
-
$this->view->unlink($this->userId . '/files/' . $filename);
-
- Encryption\Keymanager::deleteFileKey($this->view, $filename);
-
}
/**
self::cleanUpUsers();
}
- function userNamesProvider() {
- return array(
- array('testuser' . $this->getUniqueID()),
- array('user.name.with.dots'),
- );
- }
-
- /**
- * Tests whether share keys can be found
- *
- * @dataProvider userNamesProvider
- */
- function testFindShareKeys($userName) {
- self::setUpUsers();
- // note: not using dataProvider as we want to make
- // sure that the correct keys are match and not any
- // other ones that might happen to have similar names
- self::setupHooks();
- self::loginHelper($userName, true);
- $testDir = 'testFindShareKeys' . $this->getUniqueID() . '/';
- $baseDir = $userName . '/files/' . $testDir;
- $fileList = array(
- 't est.txt',
- 't est_.txt',
- 't est.doc.txt',
- 't est(.*).txt', // make sure the regexp is escaped
- 'multiple.dots.can.happen.too.txt',
- 't est.' . $userName . '.txt',
- 't est_.' . $userName . '.shareKey.txt',
- 'who would upload their.shareKey',
- 'user ones file.txt',
- 'user ones file.txt.backup',
- '.t est.txt'
- );
-
- $rootView = new \OC\Files\View('/');
- $rootView->mkdir($baseDir);
- foreach ($fileList as $fileName) {
- $rootView->file_put_contents($baseDir . $fileName, 'dummy');
- }
-
- $shareKeysDir = $userName . '/files_encryption/share-keys/' . $testDir;
- foreach ($fileList as $fileName) {
- // make sure that every file only gets its correct respective keys
- $result = Encryption\Helper::findShareKeys($baseDir . $fileName, $shareKeysDir . $fileName, $rootView);
- $this->assertEquals(
- array($shareKeysDir . $fileName . '.' . $userName . '.shareKey'),
- $result
- );
- }
- self::cleanUpUsers();
- }
}
// check if all keys are generated
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
self::logoutHelper();
// check if all keys are generated
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
// create a dummy file that we can delete something outside of data/user/files
// all keys should still exist
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
// delete the file in data/user/files
// check if keys from user2 are really deleted
$this->assertFalse($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
$this->assertFalse($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
// but user1 keys should still exist
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
if ($stateFilesTrashbin) {
OC_App::enable('files_trashbin');
// check if all keys are generated
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
// get the file info from previous created file
$fileInfo = $this->user1View->getFileInfo($this->filename);
// check if new share key exists
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
self::logoutHelper();
self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
// keys should be stored at user1s dir, not in user2s
$this->assertFalse($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
$this->assertFalse($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
// delete the Shared file from user1 in data/user2/files/Shared
$result = $this->user2View->unlink($this->filename);
// share key for user2 from user1s home should be gone, all other keys should still exists
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
$this->assertFalse($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
$this->assertTrue($this->rootView->file_exists(
- self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->filename . '/fileKey'));
// cleanup
function doTestRenameHook($filename) {
// check if keys exists
$this->assertTrue($this->rootView->file_exists(
- '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
$this->assertTrue($this->rootView->file_exists(
- '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/'
- . $filename . '.key'));
+ '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $filename . '/fileKey'));
// make subfolder and sub-subfolder
$this->rootView->mkdir('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder);
// keys should be renamed too
$this->assertFalse($this->rootView->file_exists(
- '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
$this->assertFalse($this->rootView->file_exists(
- '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/'
- . $filename . '.key'));
+ '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $filename . '/fileKey'));
$this->assertTrue($this->rootView->file_exists(
- '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $this->folder . '/' . $this->folder . '/'
- . $filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->folder . '/' . $this->folder . '/'
+ . $filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
$this->assertTrue($this->rootView->file_exists(
- '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->folder . '/' . $this->folder . '/'
- . $filename . '.key'));
+ '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->folder . '/' . $this->folder . '/'
+ . $filename . '/fileKey'));
// cleanup
$this->rootView->unlink('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder);
function doTestCopyHook($filename) {
// check if keys exists
$this->assertTrue($this->rootView->file_exists(
- '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
$this->assertTrue($this->rootView->file_exists(
- '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/'
- . $filename . '.key'));
+ '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $filename . '/fileKey'));
// make subfolder and sub-subfolder
$this->rootView->mkdir('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder);
// keys should be copied too
$this->assertTrue($this->rootView->file_exists(
- '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
$this->assertTrue($this->rootView->file_exists(
- '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/'
- . $filename . '.key'));
+ '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/'
+ . $filename . '/fileKey'));
$this->assertTrue($this->rootView->file_exists(
- '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $this->folder . '/' . $this->folder . '/'
- . $filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->folder . '/' . $this->folder . '/'
+ . $filename . '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
$this->assertTrue($this->rootView->file_exists(
- '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->folder . '/' . $this->folder . '/'
- . $filename . '.key'));
+ '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keys/' . $this->folder . '/' . $this->folder . '/'
+ . $filename . '/fileKey'));
// cleanup
$this->rootView->unlink('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder);
}
function tearDown() {
- $this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys');
- $this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles');
-
+ $this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys');
parent::tearDown();
}
$this->assertArrayHasKey('key', $sslInfo);
}
- function fileNameFromShareKeyProvider() {
- return array(
- array('file.user.shareKey', 'user', 'file'),
- array('file.name.with.dots.user.shareKey', 'user', 'file.name.with.dots'),
- array('file.name.user.with.dots.shareKey', 'user.with.dots', 'file.name'),
- array('file.txt', 'user', false),
- array('user.shareKey', 'user', false),
- );
- }
-
- /**
- * @small
- *
- * @dataProvider fileNameFromShareKeyProvider
- */
- function testGetFilenameFromShareKey($fileName, $user, $expectedFileName) {
- $this->assertEquals($expectedFileName,
- \TestProtectedKeymanagerMethods::testGetFilenameFromShareKey($fileName, $user)
- );
- }
-
/**
* @medium
*/
Encryption\Keymanager::setFileKey($this->view, $util, $file, $key);
- $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/keyfiles/' . $file . '.key'));
+ $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/keys/' . $file . '/fileKey'));
// cleanup
$this->view->unlink('/' . $this->userId . '/files/' . $file);
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/existingFile.txt', 'data');
// create folder structure for some dummy share key files
- $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1');
- $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder');
- $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder');
+ $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1');
+ $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/existingFile.txt');
+ $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1');
+ $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file2');
+ $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder');
+ $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/file2');
+ $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder');
+ $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file1');
+ $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file2');
// create some dummy share keys
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user1.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.user1.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.user1.test.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.test-keymanager-userxdot.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.userx.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.' . Test_Encryption_Keymanager::TEST_USER . '.userx.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.user1.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.' . Test_Encryption_Keymanager::TEST_USER . '.user1.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2.user2.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2.user3.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/file2.user3.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file1.user1.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2.user2.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2.user3.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/existingFile.txt/user1.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/existingFile.txt/' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/user1.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/user1.test.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/test-keymanager-userxdot.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/userx.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/' . Test_Encryption_Keymanager::TEST_USER . '.userx.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/user1.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/' . Test_Encryption_Keymanager::TEST_USER . '.user1.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file2/user2.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file2/user3.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/file2/user3.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file1/user1.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file2/user2.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file2/user3.shareKey', 'data');
// recursive delete share keys from user1 and user2
- Encryption\Keymanager::delShareKey($this->view, array('user1', 'user2', Test_Encryption_Keymanager::TEST_USER), '/folder1/', Test_Encryption_Keymanager::TEST_USER);
+ Encryption\Keymanager::delShareKey($this->view,
+ array('user1', 'user2', Test_Encryption_Keymanager::TEST_USER),
+ Encryption\Keymanager::getKeyPath($this->view, new Encryption\Util($this->view, Test_Encryption_Keymanager::TEST_USER), '/folder1'),
+ Test_Encryption_Keymanager::TEST_USER,
+ '/folder1');
// check if share keys from user1 and user2 are deleted
$this->assertFalse($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.user1.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/existingFile.txt/user1.shareKey'));
$this->assertFalse($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.user1.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1/user1.shareKey'));
$this->assertFalse($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2.user2.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2/user2.shareKey'));
$this->assertFalse($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file1.user1.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file1/user1.shareKey'));
$this->assertFalse($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2.user2.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2/user2.shareKey'));
// check if share keys from user3 still exists
$this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2.user3.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file2/user3.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2.user3.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/subsubfolder/file2/user3.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/file2.user3.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/subfolder/file2/user3.shareKey'));
- // check if share keys for user or file with similar name
+ // check if share keys for user or file with similar name
$this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.user1.test.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/user1.test.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.test-keymanager-userxdot.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/test-keymanager-userxdot.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.' . Test_Encryption_Keymanager::TEST_USER . '.userx.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/' . Test_Encryption_Keymanager::TEST_USER . '.userx.shareKey'));
// FIXME: this case currently cannot be distinguished, needs further fixing
- /*
$this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.userx.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/userx.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.user1.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/user1.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.' . Test_Encryption_Keymanager::TEST_USER . '.user1.shareKey'));
- */
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/file1/' . Test_Encryption_Keymanager::TEST_USER . '.user1.shareKey'));
// owner key from existing file should still exists because the file is still there
$this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keys/folder1/existingFile.txt/' . Test_Encryption_Keymanager::TEST_USER . '.shareKey'));
// cleanup
$this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
// recursive delete share keys from user1 and user2
- Encryption\Keymanager::delShareKey($this->view, array('user1', 'user2', Test_Encryption_Keymanager::TEST_USER), '/folder1/existingFile.txt', Test_Encryption_Keymanager::TEST_USER);
+ Encryption\Keymanager::delShareKey($this->view,
+ array('user1', 'user2', Test_Encryption_Keymanager::TEST_USER),
+ Encryption\Keymanager::getKeyPath($this->view, new Encryption\Util($this->view, Test_Encryption_Keymanager::TEST_USER), '/folder1/existingFile.txt'),
+ Test_Encryption_Keymanager::TEST_USER,
+ '/folder1/existingFile.txt');
+
// check if share keys from user1 and user2 are deleted
$this->assertFalse($this->view->file_exists(
}
- /**
- * @medium
- */
- function testDeleteFileKey() {
-
- $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/existingFile.txt', 'data');
-
- // create folder structure for some dummy file key files
- $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1');
-
- // create dummy keyfile
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/dummyFile.txt.key', 'data');
-
- // recursive delete share keys from user1 and user2
- $result = Encryption\Keymanager::deleteFileKey($this->view, '/folder1/existingFile.txt');
- $this->assertFalse($result);
-
- $result2 = Encryption\Keymanager::deleteFileKey($this->view, '/folder1/dummyFile.txt');
- $this->assertTrue($result2);
-
- // check if file key from dummyFile was deleted
- $this->assertFalse($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/dummyFile.txt.key'));
-
- // check if file key from existing file still exists
- $this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/existingFile.txt.key'));
-
- // cleanup
- $this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
-
- }
-
- /**
- * @medium
- */
- function testDeleteFileKeyFolder() {
-
- $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/existingFile.txt', 'data');
-
- // create folder structure for some dummy file key files
- $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1');
-
- // create dummy keyfile
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/dummyFile.txt.key', 'data');
-
- // recursive delete share keys from user1 and user2
- $result = Encryption\Keymanager::deleteFileKey($this->view, '/folder1');
- $this->assertFalse($result);
-
- // all file keys should still exists if we try to delete a folder with keys for which some files still exists
- $this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/dummyFile.txt.key'));
- $this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/existingFile.txt.key'));
-
- // delete folder
- $this->view->unlink('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
- // create dummy keyfile
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/dummyFile.txt.key', 'data');
-
- // now file keys should be deleted since the folder no longer exists
- $result = Encryption\Keymanager::deleteFileKey($this->view, '/folder1');
- $this->assertTrue($result);
-
- $this->assertFalse($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1'));
-
- // cleanup
- $this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
-
- }
-
- function testDelAllShareKeysFile() {
- $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/existingFile.txt', 'data');
-
- // create folder structure for some dummy share key files
- $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1');
-
- // create some dummy share keys for the existing file
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user1.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user2.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user3.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
-
- // create some dummy share keys for a non-existing file
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.user1.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.user2.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.user3.shareKey', 'data');
- $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
-
- // try to del all share keys from a existing file, should fail because the file still exists
- $result = Encryption\Keymanager::delAllShareKeys($this->view, Test_Encryption_Keymanager::TEST_USER, 'folder1/existingFile.txt');
- $this->assertFalse($result);
-
- // check if share keys still exists
- $this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey'));
- $this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user1.shareKey'));
- $this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user2.shareKey'));
- $this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user3.shareKey'));
-
- // try to del all share keys from file, should succeed because the does not exist any more
- $result2 = Encryption\Keymanager::delAllShareKeys($this->view, Test_Encryption_Keymanager::TEST_USER, 'folder1/nonexistingFile.txt');
- $this->assertTrue($result2);
-
- // check if share keys are really gone
- $this->assertFalse($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey'));
- // check that it only deleted keys or users who had access, others remain
- $this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.user1.shareKey'));
- $this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.user2.shareKey'));
- $this->assertTrue($this->view->file_exists(
- '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.user3.shareKey'));
-
- // cleanup
- $this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
-
- }
-
function testKeySetPreperation() {
$basePath = '/'.Test_Encryption_Keymanager::TEST_USER.'/files';
$path = '/folder1/subfolder/subsubfolder/file.txt';
$this->assertFalse($this->view->is_dir($basePath . '/testKeySetPreperation'));
- $result = TestProtectedKeymanagerMethods::testKeySetPreperation($this->view, $path, $basePath);
-
- // return path without leading slash
- $this->assertSame('folder1/subfolder/subsubfolder/file.txt', $result);
+ TestProtectedKeymanagerMethods::testKeySetPreperation($this->view, $basePath . $path);
// check if directory structure was created
- $this->assertTrue($this->view->is_dir($basePath . '/folder1/subfolder/subsubfolder'));
+ $this->assertTrue($this->view->is_dir($basePath . $path));
// cleanup
$this->view->deleteAll($basePath . '/folder1');
*/
class TestProtectedKeymanagerMethods extends \OCA\Encryption\Keymanager {
- /**
- * @param string $sharekey
- */
- public static function testGetFilenameFromShareKey($sharekey, $user) {
- return self::getFilenameFromShareKey($sharekey, $user);
- }
-
/**
* @param \OC\Files\View $view relative to data/
* @param string $path
* @param string $basePath
*/
- public static function testKeySetPreperation($view, $path, $basePath) {
- return self::keySetPreparation($view, $path, $basePath);
+ public static function testKeySetPreperation($view, $path) {
+ return self::keySetPreparation($view, $path);
}
}
// check if share key for user1 exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// login as user1
self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
$this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
}
}
// check if share key for user2 exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// login as user2
self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// unshare the file with user1
\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
$this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
}
}
// check if share key for user1 exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys' . $this->folder1
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1
. $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// login as user1
self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys'
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys'
. $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
$this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys'
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys'
. $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
}
return $fileInfo;
// check if share key for user3 exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys' . $this->folder1
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1
. $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// login as user3
self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// check if share key for user3 exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys' . $this->folder1
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1
. $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// login as user3
self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4);
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys'
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys'
. $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// login as user1
self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys'
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys'
. $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// login as admin
self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys'
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys'
. $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
$this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys'
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys'
. $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
}
}
// check if share key for public exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . $publicShareKeyId . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . $publicShareKeyId . '.shareKey'));
// some hacking to simulate public link
//$GLOBALS['app'] = 'files_sharing';
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . $publicShareKeyId . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . $publicShareKeyId . '.shareKey'));
// cleanup
$this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
}
/**
// check if share key for user2 and user3 exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// login as user1
self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// cleanup
$this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
}
// check if share key for admin and recovery exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . $recoveryKeyId . '.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->folder1
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1
. $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->folder1
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1
. $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ . $this->filename . '/' . $recoveryKeyId . '.shareKey'));
// disable recovery for admin
$this->assertTrue($util->setRecoveryForUser(0));
// check if share key for recovery not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . $recoveryKeyId . '.shareKey'));
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->folder1
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1
. $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ . $this->filename . '/' . $recoveryKeyId . '.shareKey'));
// enable recovery for admin
$this->assertTrue($util->setRecoveryForUser(1));
// check if share key for admin and recovery exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . $recoveryKeyId . '.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->folder1
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1
. $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ . $this->filename . '/' . $recoveryKeyId . '.shareKey'));
// cleanup
$this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
// check if share key for recovery not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . $recoveryKeyId . '.shareKey'));
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->folder1
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1
. $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ . $this->filename . '/' . $recoveryKeyId . '.shareKey'));
$this->assertTrue(\OCA\Encryption\Helper::adminEnableRecovery(null, 'test123'));
$this->assertTrue(\OCA\Encryption\Helper::adminDisableRecovery('test123'));
// check if share key for user and recovery exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/'
- . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/'
+ . $this->filename . '/' . $recoveryKeyId . '.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->folder1
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1
. $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->folder1
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1
. $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ . $this->filename . '/' . $recoveryKeyId . '.shareKey'));
// login as admin
self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user and recovery exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/'
- . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/'
+ . $this->filename . '/' . $recoveryKeyId . '.shareKey'));
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->folder1
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1
. $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->folder1
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1
. $this->subfolder . $this->subsubfolder . '/'
- . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ . $this->filename . '/' . $recoveryKeyId . '.shareKey'));
// enable recovery for admin
$this->assertTrue($util->setRecoveryForUser(0));
// check if share key for user1 not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
'/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.public.key');
// remove share file
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3
+ $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3
. '.shareKey');
// re-enable the file proxy
// check if share key not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// cleanup
$this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
// check if share key for user2 exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
+ . $this->filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// login as user2
$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'));
+ $this->assertTrue($view->file_exists('files_encryption/keys' . $newFolder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// check that old keys were removed/moved properly
- $this->assertFalse($view->file_exists('files_encryption/share-keys' . $folder . '/' . $filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// tear down
\OC\Files\Filesystem::unlink($newFolder);
\OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL);
// check that the share keys exist
- $this->assertTrue($view->file_exists('files_encryption/share-keys' . $folder . '/' . $filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
- $this->assertTrue($view->file_exists('files_encryption/share-keys' . $folder . '/' . $filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ $this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ $this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// move the file into the subfolder as the test user
self::loginHelper($userId);
$this->assertEquals($this->dataShort, $newDecrypt);
// check if additional share key for user2 exists
- $this->assertTrue($view->file_exists('files_encryption/share-keys' . $subFolder . '/' . $filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
- $this->assertTrue($view->file_exists('files_encryption/share-keys' . $subFolder . '/' . $filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ $this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ $this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// check that old keys were removed/moved properly
- $this->assertFalse($view->file_exists('files_encryption/share-keys' . $folder . '/' . $filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
- $this->assertFalse($view->file_exists('files_encryption/share-keys' . $folder . '/' . $filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ $this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// tear down
\OC\Files\Filesystem::unlink($subFolder);
// check if key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
- . '.key'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' . $filename . '/fileKey'));
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename2
- . '.key'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' . $filename2 . '/fileKey'));
// check if share key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/'
+ . $filename . '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename2 . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/'
+ . $filename2 . '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// delete first file
- \OC\FIles\Filesystem::unlink($filename);
+ \OC\Files\Filesystem::unlink($filename);
// check if file not exists
$this->assertFalse($this->view->file_exists(
// check if key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
- . '.key'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' . $filename . '/fileKey'));
// check if share key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/'
+ . $filename . '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// check that second file still exists
$this->assertTrue($this->view->file_exists(
// check that key for second file still exists
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename2
- . '.key'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' . $filename2 . '/fileKey'));
// check that share key for second file still exists
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename2 . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/'
+ . $filename2 . '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// get files
$trashFiles = $this->view->getDirectoryContent(
// check if we found the file we created
$this->assertNotNull($trashFileSuffix);
+ $this->assertTrue($this->view->is_dir('/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keys/' . $filename . '.' . $trashFileSuffix));
+
// check if key for admin not exists
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
- . '.key.' . $trashFileSuffix));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keys/' . $filename . '.' . $trashFileSuffix . '/fileKey'));
// check if share key for admin not exists
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename
- . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keys/' . $filename
+ . '.' . $trashFileSuffix . '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
}
/**
// prepare file information
$timestamp = str_replace('d', '', $trashFileSuffix);
+ // before calling the restore operation the keys shouldn't be there
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' . $filename . '/fileKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/'
+ . $filename . '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+
// restore first file
$this->assertTrue(\OCA\Files_Trashbin\Trashbin::restore($filename . '.' . $trashFileSuffix, $filename, $timestamp));
// check if key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/'
- . $filename . '.key'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' . $filename . '/fileKey'));
// check if share key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/'
+ . $filename . '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// check that second file was NOT restored
$this->assertFalse($this->view->file_exists(
// check if key for admin exists
$this->assertFalse($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/'
- . $filename2 . '.key'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' . $filename2 . '/fileKey'));
// check if share key for admin exists
$this->assertFalse($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename2 . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/'
+ . $filename2 . '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
}
/**
// check if key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
- . '.key'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' . $filename . '/fileKey'));
// check if share key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/'
+ . $filename . '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// delete file
\OC\Files\Filesystem::unlink($filename);
// check if key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
- . '.key'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/' . $filename . '/'
+ . $filename . '.key'));
// check if share key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keys/'
+ . $filename . '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// find created file with timestamp
$query = \OC_DB::prepare('SELECT `timestamp`,`type` FROM `*PREFIX*files_trash`'
// check if key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
- . '.key.' . $trashFileSuffix));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keys/' . $filename
+ . '.' . $trashFileSuffix . '/fileKey'));
// check if share key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename
- . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keys/'
+ . $filename . '.' . $trashFileSuffix . '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// get timestamp from file
$timestamp = str_replace('d', '', $trashFileSuffix);
// check if key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
- . '.key.' . $trashFileSuffix));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keys/' . $filename
+ . '.' . $trashFileSuffix . '/fileKey'));
// check if share key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename
- . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keys/' . $filename
+ . '.' . $trashFileSuffix . '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
}
}
$this->publicKeyDir = '/' . 'public-keys';
$this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption';
- $this->keyfilesPath = $this->encryptionDir . '/' . 'keyfiles';
+ $this->keysPath = $this->encryptionDir . '/' . 'keys';
$this->publicKeyPath =
$this->publicKeyDir . '/' . $this->userId . '.public.key'; // e.g. data/public-keys/admin.public.key
$this->privateKeyPath =
$this->assertEquals($this->publicKeyDir, $util->getPath('publicKeyDir'));
$this->assertEquals($this->encryptionDir, $util->getPath('encryptionDir'));
- $this->assertEquals($this->keyfilesPath, $util->getPath('keyfilesPath'));
+ $this->assertEquals($this->keysPath, $util->getPath('keysPath'));
$this->assertEquals($this->publicKeyPath, $util->getPath('publicKeyPath'));
$this->assertEquals($this->privateKeyPath, $util->getPath('privateKeyPath'));
// file should no longer be encrypted
$this->assertEquals(0, $fileInfoUnencrypted['encrypted']);
+ $backupPath = $this->getBackupPath('decryptAll');
+
// check if the keys where moved to the backup location
- $this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/keyfiles.backup'));
- $this->assertTrue($this->view->file_exists($this->userId . '/files_encryption/keyfiles.backup/' . $filename . '.key'));
- $this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/share-keys.backup'));
- $this->assertTrue($this->view->file_exists($this->userId . '/files_encryption/share-keys.backup/' . $filename . '.' . $user . '.shareKey'));
+ $this->assertTrue($this->view->is_dir($backupPath . '/keys'));
+ $this->assertTrue($this->view->file_exists($backupPath . '/keys/' . $filename . '/fileKey'));
+ $this->assertTrue($this->view->file_exists($backupPath . '/keys/' . $filename . '/' . $user . '.shareKey'));
+ $this->assertTrue($this->view->file_exists($backupPath . '/' . $user . '.private.key'));
+ $this->assertTrue($this->view->file_exists($backupPath . '/' . $user . '.public.key'));
// cleanup
$this->view->unlink($this->userId . '/files/' . $filename);
- $this->view->deleteAll($this->userId . '/files_encryption/keyfiles.backup');
- $this->view->deleteAll($this->userId . '/files_encryption/share-keys.backup');
+ $this->view->deleteAll($backupPath);
OC_App::enable('files_encryption');
}
// create some dummy key files
$encPath = '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '/files_encryption';
- $this->view->file_put_contents($encPath . '/keyfiles/foo.key', 'key');
- $this->view->file_put_contents($encPath . '/share-keys/foo.user1.shareKey', 'share key');
+ $this->view->mkdir($encPath . '/keys/foo');
+ $this->view->file_put_contents($encPath . '/keys/foo/fileKey', 'key');
+ $this->view->file_put_contents($encPath . '/keys/foo/user1.shareKey', 'share key');
$util = new \OCA\Encryption\Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1);
- $util->backupAllKeys('testing');
+ $util->backupAllKeys('testBackupAllKeys');
- $encFolderContent = $this->view->getDirectoryContent($encPath);
-
- $backupPath = '';
- foreach ($encFolderContent as $c) {
- $name = $c['name'];
- if (substr($name, 0, strlen('backup')) === 'backup') {
- $backupPath = $encPath . '/'. $c['name'];
- break;
- }
- }
-
- $this->assertTrue($backupPath !== '');
+ $backupPath = $this->getBackupPath('testBackupAllKeys');
// check backupDir Content
- $this->assertTrue($this->view->is_dir($backupPath . '/keyfiles'));
- $this->assertTrue($this->view->is_dir($backupPath . '/share-keys'));
- $this->assertTrue($this->view->file_exists($backupPath . '/keyfiles/foo.key'));
- $this->assertTrue($this->view->file_exists($backupPath . '/share-keys/foo.user1.shareKey'));
+ $this->assertTrue($this->view->is_dir($backupPath . '/keys'));
+ $this->assertTrue($this->view->is_dir($backupPath . '/keys/foo'));
+ $this->assertTrue($this->view->file_exists($backupPath . '/keys/foo/fileKey'));
+ $this->assertTrue($this->view->file_exists($backupPath . '/keys/foo/user1.shareKey'));
$this->assertTrue($this->view->file_exists($backupPath . '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '.private.key'));
$this->assertTrue($this->view->file_exists($backupPath . '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '.public.key'));
//cleanup
$this->view->deleteAll($backupPath);
- $this->view->unlink($encPath . '/keyfiles/foo.key', 'key');
- $this->view->unlink($encPath . '/share-keys/foo.user1.shareKey', 'share key');
+ $this->view->unlink($encPath . '/keys/foo/fileKey');
+ $this->view->unlink($encPath . '/keys/foo/user1.shareKey');
}
// rename keyfile for file1 so that the decryption for file1 fails
// Expected behaviour: decryptAll() returns false, file2 gets decrypted anyway
- $this->view->rename($this->userId . '/files_encryption/keyfiles/' . $file1 . '.key',
- $this->userId . '/files_encryption/keyfiles/' . $file1 . '.key.moved');
+ $this->view->rename($this->userId . '/files_encryption/keys/' . $file1 . '/fileKey',
+ $this->userId . '/files_encryption/keys/' . $file1 . '/fileKey.moved');
// decrypt all encrypted files
$result = $util->decryptAll();
$this->assertEquals(0, $fileInfoUnencrypted2['encrypted']);
// keyfiles and share keys should still exist
- $this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/keyfiles/'));
- $this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/share-keys/'));
+ $this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/keys/'));
+ $this->assertTrue($this->view->file_exists($this->userId . '/files_encryption/keys/' . $file1 . '/fileKey.moved'));
+ $this->assertTrue($this->view->file_exists($this->userId . '/files_encryption/keys/' . $file1 . '/' . $this->userId . '.shareKey'));
// rename the keyfile for file1 back
- $this->view->rename($this->userId . '/files_encryption/keyfiles/' . $file1 . '.key.moved',
- $this->userId . '/files_encryption/keyfiles/' . $file1 . '.key');
+ $this->view->rename($this->userId . '/files_encryption/keys/' . $file1 . '/fileKey.moved',
+ $this->userId . '/files_encryption/keys/' . $file1 . '/fileKey');
// try again to decrypt all encrypted files
$result = $util->decryptAll();
$this->assertEquals(0, $fileInfoUnencrypted2['encrypted']);
// keyfiles and share keys should be deleted
- $this->assertFalse($this->view->is_dir($this->userId . '/files_encryption/keyfiles/'));
- $this->assertFalse($this->view->is_dir($this->userId . '/files_encryption/share-keys/'));
+ $this->assertFalse($this->view->is_dir($this->userId . '/files_encryption/keys/'));
//cleanup
+ $backupPath = $this->getBackupPath('decryptAll');
$this->view->unlink($this->userId . '/files/' . $file1);
$this->view->unlink($this->userId . '/files/' . $file2);
- $this->view->deleteAll($this->userId . '/files_encryption/keyfiles.backup');
- $this->view->deleteAll($this->userId . '/files_encryption/share-keys.backup');
+ $this->view->deleteAll($backupPath);
+
+ }
+
+ function getBackupPath($extension) {
+ $encPath = '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '/files_encryption';
+ $encFolderContent = $this->view->getDirectoryContent($encPath);
+
+ $backupPath = '';
+ foreach ($encFolderContent as $c) {
+ $name = $c['name'];
+ if (substr($name, 0, strlen('backup.' . $extension)) === 'backup.' . $extension) {
+ $backupPath = $encPath . '/'. $c['name'];
+ break;
+ }
+ }
+ return $backupPath;
}
/**
// check if key-file was created
$this->assertTrue($this->view->file_exists(
- '/' . $this->userId . '/files_encryption/keyfiles/' . $filename . '.key'));
+ '/' . $this->userId . '/files_encryption/keys/' . $filename . '/fileKey'));
// check if shareKey-file was created
$this->assertTrue($this->view->file_exists(
- '/' . $this->userId . '/files_encryption/share-keys/' . $filename . '.' . $this->userId . '.shareKey'));
+ '/' . $this->userId . '/files_encryption/keys/' . $filename . '/' . $this->userId . '.shareKey'));
// disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
// check if key-file was removed
$this->assertFalse($this->view->file_exists(
- '/' . $this->userId . '/files_encryption/keyfiles' . $filename . '.key'));
+ '/' . $this->userId . '/files_encryption/keys/' . $filename . '/fileKey'));
// check if shareKey-file was removed
$this->assertFalse($this->view->file_exists(
- '/' . $this->userId . '/files_encryption/share-keys' . $filename . '.' . $this->userId . '.shareKey'));
+ '/' . $this->userId . '/files_encryption/keys/' . $filename . '/' . $this->userId . '.shareKey'));
}
/**
if (!$view->is_dir('files_trashbin/versions')) {
$view->mkdir('files_trashbin/versions');
}
- if (!$view->is_dir('files_trashbin/keyfiles')) {
- $view->mkdir('files_trashbin/keyfiles');
- }
- if (!$view->is_dir('files_trashbin/share-keys')) {
- $view->mkdir('files_trashbin/share-keys');
+ if (!$view->is_dir('files_trashbin/keys')) {
+ $view->mkdir('files_trashbin/keys');
}
}
return 0;
}
- $util = new \OCA\Encryption\Util(new \OC\Files\View('/'), $user);
+ $util = new \OCA\Encryption\Util($rootView, $user);
- // disable proxy to prevent recursive calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
- if ($util->isSystemWideMountPoint($ownerPath)) {
- $baseDir = '/files_encryption/';
- } else {
- $baseDir = $owner . '/files_encryption/';
- }
-
- $keyfile = \OC\Files\Filesystem::normalizePath($baseDir . '/keyfiles/' . $ownerPath);
-
- if ($rootView->is_dir($keyfile) || $rootView->file_exists($keyfile . '.key')) {
- // move keyfiles
- if ($rootView->is_dir($keyfile)) {
- $size += self::calculateSize(new \OC\Files\View($keyfile));
- if ($owner !== $user) {
- self::copy_recursive($keyfile, $owner . '/files_trashbin/keyfiles/' . basename($ownerPath) . '.d' . $timestamp, $rootView);
- }
- $rootView->rename($keyfile, $user . '/files_trashbin/keyfiles/' . $filename . '.d' . $timestamp);
- } else {
- $size += $rootView->filesize($keyfile . '.key');
- if ($owner !== $user) {
- $rootView->copy($keyfile . '.key', $owner . '/files_trashbin/keyfiles/' . basename($ownerPath) . '.key.d' . $timestamp);
- }
- $rootView->rename($keyfile . '.key', $user . '/files_trashbin/keyfiles/' . $filename . '.key.d' . $timestamp);
- }
+ $baseDir = '/files_encryption/';
+ if (!$util->isSystemWideMountPoint($ownerPath)) {
+ $baseDir = $owner . $baseDir;
}
- // retain share keys
- $sharekeys = \OC\Files\Filesystem::normalizePath($baseDir . '/share-keys/' . $ownerPath);
+ $keyfiles = \OC\Files\Filesystem::normalizePath($baseDir . '/keys/' . $ownerPath);
- if ($rootView->is_dir($sharekeys)) {
- $size += self::calculateSize(new \OC\Files\View($sharekeys));
+ if ($rootView->is_dir($keyfiles)) {
+ $size += self::calculateSize(new \OC\Files\View($keyfiles));
if ($owner !== $user) {
- self::copy_recursive($sharekeys, $owner . '/files_trashbin/share-keys/' . basename($ownerPath) . '.d' . $timestamp, $rootView);
- }
- $rootView->rename($sharekeys, $user . '/files_trashbin/share-keys/' . $filename . '.d' . $timestamp);
- } else {
- // handle share-keys
- $matches = \OCA\Encryption\Helper::findShareKeys($ownerPath, $sharekeys, $rootView);
- foreach ($matches as $src) {
- // get source file parts
- $pathinfo = pathinfo($src);
-
- // we only want to keep the users key so we can access the private key
- $userShareKey = $filename . '.' . $user . '.shareKey';
-
- // if we found the share-key for the owner, we need to move it to files_trashbin
- if ($pathinfo['basename'] == $userShareKey) {
-
- // calculate size
- $size += $rootView->filesize($sharekeys . '.' . $user . '.shareKey');
-
- // move file
- $rootView->rename($sharekeys . '.' . $user . '.shareKey', $user . '/files_trashbin/share-keys/' . $userShareKey . '.d' . $timestamp);
- } elseif ($owner !== $user) {
- $ownerShareKey = basename($ownerPath) . '.' . $owner . '.shareKey';
- if ($pathinfo['basename'] == $ownerShareKey) {
- $rootView->rename($sharekeys . '.' . $owner . '.shareKey', $owner . '/files_trashbin/share-keys/' . $ownerShareKey . '.d' . $timestamp);
- }
- } else {
- // don't keep other share-keys
- unlink($src);
- }
+ self::copy_recursive($keyfiles, $owner . '/files_trashbin/keys/' . basename($ownerPath) . '.d' . $timestamp, $rootView);
}
+ $rootView->rename($keyfiles, $user . '/files_trashbin/keys/' . $filename . '.d' . $timestamp);
}
- // enable proxy
- \OC_FileProxy::$enabled = $proxyStatus;
}
return $size;
}
* @return bool
*/
private static function restoreEncryptionKeys(\OC\Files\View $view, $file, $filename, $uniqueFilename, $location, $timestamp) {
- // Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!)
+
if (\OCP\App::isEnabled('files_encryption')) {
$user = \OCP\User::getUser();
$rootView = new \OC\Files\View('/');
return false;
}
- $util = new \OCA\Encryption\Util(new \OC\Files\View('/'), $user);
+ $util = new \OCA\Encryption\Util($rootView, $user);
- if ($util->isSystemWideMountPoint($ownerPath)) {
- $baseDir = '/files_encryption/';
- } else {
- $baseDir = $owner . '/files_encryption/';
+ $baseDir = '/files_encryption/';
+ if (!$util->isSystemWideMountPoint($ownerPath)) {
+ $baseDir = $owner . $baseDir;
}
- $path_parts = pathinfo($file);
- $source_location = $path_parts['dirname'];
+ $source_location = dirname($file);
- if ($view->is_dir('/files_trashbin/keyfiles/' . $file)) {
+ if ($view->is_dir('/files_trashbin/keys/' . $file)) {
if ($source_location != '.') {
- $keyfile = \OC\Files\Filesystem::normalizePath($user . '/files_trashbin/keyfiles/' . $source_location . '/' . $filename);
- $sharekey = \OC\Files\Filesystem::normalizePath($user . '/files_trashbin/share-keys/' . $source_location . '/' . $filename);
+ $keyfile = \OC\Files\Filesystem::normalizePath($user . '/files_trashbin/keys/' . $source_location . '/' . $filename);
} else {
- $keyfile = \OC\Files\Filesystem::normalizePath($user . '/files_trashbin/keyfiles/' . $filename);
- $sharekey = \OC\Files\Filesystem::normalizePath($user . '/files_trashbin/share-keys/' . $filename);
+ $keyfile = \OC\Files\Filesystem::normalizePath($user . '/files_trashbin/keys/' . $filename);
}
- } else {
- $keyfile = \OC\Files\Filesystem::normalizePath($user . '/files_trashbin/keyfiles/' . $source_location . '/' . $filename . '.key');
}
if ($timestamp) {
$keyfile .= '.d' . $timestamp;
}
- // disable proxy to prevent recursive calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
- if ($rootView->file_exists($keyfile)) {
- // handle directory
- if ($rootView->is_dir($keyfile)) {
-
- // handle keyfiles
- $rootView->rename($keyfile, $baseDir . '/keyfiles/' . $ownerPath);
-
- // handle share-keys
- if ($timestamp) {
- $sharekey .= '.d' . $timestamp;
- }
- $rootView->rename($sharekey, $baseDir . '/share-keys/' . $ownerPath);
- } else {
- // handle keyfiles
- $rootView->rename($keyfile, $baseDir . '/keyfiles/' . $ownerPath . '.key');
-
- // handle share-keys
- $ownerShareKey = \OC\Files\Filesystem::normalizePath($user . '/files_trashbin/share-keys/' . $source_location . '/' . $filename . '.' . $user . '.shareKey');
- if ($timestamp) {
- $ownerShareKey .= '.d' . $timestamp;
- }
-
- // move only owners key
- $rootView->rename($ownerShareKey, $baseDir . '/share-keys/' . $ownerPath . '.' . $user . '.shareKey');
-
- // try to re-share if file is shared
- $filesystemView = new \OC\Files\View('/');
- $session = new \OCA\Encryption\Session($filesystemView);
- $util = new \OCA\Encryption\Util($filesystemView, $user);
-
- // fix the file size
- $absolutePath = \OC\Files\Filesystem::normalizePath('/' . $owner . '/files/' . $ownerPath);
- $util->fixFileSize($absolutePath);
-
- // get current sharing state
- $sharingEnabled = \OCP\Share::isEnabled();
-
- // get users sharing this file
- $usersSharing = $util->getSharingUsersArray($sharingEnabled, $target);
-
- // Attempt to set shareKey
- $util->setSharedFileKeyfiles($session, $usersSharing, $target);
- }
+ if ($rootView->is_dir($keyfile)) {
+ $rootView->rename($keyfile, $baseDir . '/keys/' . $ownerPath);
}
- // enable proxy
- \OC_FileProxy::$enabled = $proxyStatus;
}
}
if (\OCP\App::isEnabled('files_encryption')) {
$user = \OCP\User::getUser();
- if ($view->is_dir('/files_trashbin/files/' . $file)) {
- $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $filename);
- $sharekeys = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $filename);
- } else {
- $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $filename . '.key');
- $sharekeys = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $filename . '.' . $user . '.shareKey');
- }
+ $keyfiles = \OC\Files\Filesystem::normalizePath('files_trashbin/keys/' . $filename);
+
if ($timestamp) {
- $keyfile .= '.d' . $timestamp;
- $sharekeys .= '.d' . $timestamp;
+ $keyfiles .= '.d' . $timestamp;
}
- if ($view->file_exists($keyfile)) {
- if ($view->is_dir($keyfile)) {
- $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile));
- $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $sharekeys));
- } else {
- $size += $view->filesize($keyfile);
- $size += $view->filesize($sharekeys);
- }
- $view->unlink($keyfile);
- $view->unlink($sharekeys);
+ if ($view->is_dir($keyfiles)) {
+ $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfiles));
+ $view->deleteAll($keyfiles);
+
}
}
return $size;