mirror of
https://github.com/nextcloud/server.git
synced 2024-08-13 14:11:10 +02:00
new folder structure for keys
all keys are now in files_encryption/key/path_to_file/filename/ share keys are named: user.shareKey file key is named: fileKey
This commit is contained in:
parent
c5fa8f1bdc
commit
fd86d76f98
@ -27,7 +27,7 @@ namespace OCA\Encryption\Exception;
|
||||
* 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
|
||||
@ -38,7 +38,7 @@ namespace OCA\Encryption\Exception;
|
||||
* 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;
|
||||
|
@ -35,7 +35,7 @@ class Hooks {
|
||||
// file for which we want to delete the keys after the delete operation was successful
|
||||
private static $deleteFiles = array();
|
||||
// file for which we want to delete the keys after the delete operation was successful
|
||||
private static $umountedFiles = array();
|
||||
private static $unmountedFiles = array();
|
||||
|
||||
/**
|
||||
* Startup encryption backend upon user login
|
||||
@ -328,7 +328,7 @@ class Hooks {
|
||||
|
||||
$path = \OC\Files\Filesystem::getPath($params['fileSource']);
|
||||
|
||||
self::updateKeyfiles($path, $params['itemType']);
|
||||
self::updateKeyfiles($path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,9 +336,8 @@ class Hooks {
|
||||
* update keyfiles and share keys recursively
|
||||
*
|
||||
* @param string $path to the file/folder
|
||||
* @param string $type 'file' or 'folder'
|
||||
*/
|
||||
private static function updateKeyfiles($path, $type) {
|
||||
private static function updateKeyfiles($path) {
|
||||
$view = new \OC\Files\View('/');
|
||||
$userId = \OCP\User::getUser();
|
||||
$session = new \OCA\Encryption\Session($view);
|
||||
@ -350,7 +349,7 @@ class Hooks {
|
||||
$mountPoint = $mount->getMountPoint();
|
||||
|
||||
// if a folder was shared, get a list of all (sub-)folders
|
||||
if ($type === 'folder') {
|
||||
if ($view->is_dir('/' . $userId . '/files' . $path)) {
|
||||
$allFiles = $util->getAllFiles($path, $mountPoint);
|
||||
} else {
|
||||
$allFiles = array($path);
|
||||
@ -407,11 +406,10 @@ class Hooks {
|
||||
|
||||
// Unshare every user who no longer has access to the file
|
||||
$delUsers = array_diff($userIds, $sharingUsers);
|
||||
|
||||
list($owner, $ownerPath) = $util->getUidAndFilename($path);
|
||||
$keyPath = Keymanager::getKeyPath($view, $util, $path);
|
||||
|
||||
// delete share key
|
||||
Keymanager::delShareKey($view, $delUsers, $ownerPath, $owner);
|
||||
Keymanager::delShareKey($view, $delUsers, $keyPath, $userId, $path);
|
||||
}
|
||||
|
||||
}
|
||||
@ -437,35 +435,19 @@ class Hooks {
|
||||
$user = \OCP\User::getUser();
|
||||
$view = new \OC\Files\View('/');
|
||||
$util = new Util($view, $user);
|
||||
list($ownerOld, $pathOld) = $util->getUidAndFilename($params['oldpath']);
|
||||
|
||||
// we only need to rename the keys if the rename happens on the same mountpoint
|
||||
// otherwise we perform a stream copy, so we get a new set of keys
|
||||
$mp1 = $view->getMountPoint('/' . $user . '/files/' . $params['oldpath']);
|
||||
$mp2 = $view->getMountPoint('/' . $user . '/files/' . $params['newpath']);
|
||||
|
||||
$type = $view->is_dir('/' . $user . '/files/' . $params['oldpath']) ? 'folder' : 'file';
|
||||
|
||||
if ($mp1 === $mp2) {
|
||||
if ($util->isSystemWideMountPoint($pathOld)) {
|
||||
$oldShareKeyPath = 'files_encryption/share-keys/' . $pathOld;
|
||||
} else {
|
||||
$oldShareKeyPath = $ownerOld . '/' . 'files_encryption/share-keys/' . $pathOld;
|
||||
}
|
||||
// gather share keys here because in postRename() the file will be moved already
|
||||
$oldShareKeys = Helper::findShareKeys($pathOld, $oldShareKeyPath, $view);
|
||||
if (count($oldShareKeys) === 0) {
|
||||
\OC_Log::write(
|
||||
'Encryption library', 'No share keys found for "' . $pathOld . '"',
|
||||
\OC_Log::WARN
|
||||
);
|
||||
}
|
||||
|
||||
$oldKeysPath = Keymanager::getKeyPath($view, $util, $params['oldpath']);
|
||||
|
||||
self::$renamedFiles[$params['oldpath']] = array(
|
||||
'uid' => $ownerOld,
|
||||
'path' => $pathOld,
|
||||
'type' => $type,
|
||||
'operation' => $operation,
|
||||
'sharekeys' => $oldShareKeys
|
||||
'oldKeysPath' => $oldKeysPath,
|
||||
);
|
||||
|
||||
}
|
||||
@ -482,81 +464,37 @@ class Hooks {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Disable encryption proxy to prevent recursive calls
|
||||
$proxyStatus = \OC_FileProxy::$enabled;
|
||||
\OC_FileProxy::$enabled = false;
|
||||
|
||||
$view = new \OC\Files\View('/');
|
||||
$userId = \OCP\User::getUser();
|
||||
$util = new Util($view, $userId);
|
||||
$oldShareKeys = null;
|
||||
|
||||
if (isset(self::$renamedFiles[$params['oldpath']]['uid']) &&
|
||||
isset(self::$renamedFiles[$params['oldpath']]['path'])) {
|
||||
$ownerOld = self::$renamedFiles[$params['oldpath']]['uid'];
|
||||
$pathOld = self::$renamedFiles[$params['oldpath']]['path'];
|
||||
$type = self::$renamedFiles[$params['oldpath']]['type'];
|
||||
if (isset(self::$renamedFiles[$params['oldpath']]['operation']) &&
|
||||
isset(self::$renamedFiles[$params['oldpath']]['oldKeysPath'])) {
|
||||
$operation = self::$renamedFiles[$params['oldpath']]['operation'];
|
||||
$oldShareKeys = self::$renamedFiles[$params['oldpath']]['sharekeys'];
|
||||
$oldKeysPath = self::$renamedFiles[$params['oldpath']]['oldKeysPath'];
|
||||
unset(self::$renamedFiles[$params['oldpath']]);
|
||||
} else {
|
||||
\OCP\Util::writeLog('Encryption library', "can't get path and owner from the file before it was renamed", \OCP\Util::DEBUG);
|
||||
\OC_FileProxy::$enabled = $proxyStatus;
|
||||
return false;
|
||||
}
|
||||
|
||||
list($ownerNew, $pathNew) = $util->getUidAndFilename($params['newpath']);
|
||||
|
||||
// Format paths to be relative to user files dir
|
||||
if ($util->isSystemWideMountPoint($pathOld)) {
|
||||
$oldKeyfilePath = 'files_encryption/keyfiles/' . $pathOld;
|
||||
$oldShareKeyPath = 'files_encryption/share-keys/' . $pathOld;
|
||||
} else {
|
||||
$oldKeyfilePath = $ownerOld . '/' . 'files_encryption/keyfiles/' . $pathOld;
|
||||
$oldShareKeyPath = $ownerOld . '/' . 'files_encryption/share-keys/' . $pathOld;
|
||||
}
|
||||
|
||||
if ($util->isSystemWideMountPoint($pathNew)) {
|
||||
$newKeyfilePath = 'files_encryption/keyfiles/' . $pathNew;
|
||||
$newShareKeyPath = 'files_encryption/share-keys/' . $pathNew;
|
||||
$newKeysPath = 'files_encryption/keys/' . $pathNew;
|
||||
} else {
|
||||
$newKeyfilePath = $ownerNew . '/files_encryption/keyfiles/' . $pathNew;
|
||||
$newShareKeyPath = $ownerNew . '/files_encryption/share-keys/' . $pathNew;
|
||||
$newKeysPath = $ownerNew . '/files_encryption/keys/' . $pathNew;
|
||||
}
|
||||
|
||||
// create new key folders if it doesn't exists
|
||||
if (!$view->file_exists(dirname($newShareKeyPath))) {
|
||||
$view->mkdir(dirname($newShareKeyPath));
|
||||
}
|
||||
if (!$view->file_exists(dirname($newKeyfilePath))) {
|
||||
$view->mkdir(dirname($newKeyfilePath));
|
||||
}
|
||||
|
||||
// handle share keys
|
||||
if ($type === 'file') {
|
||||
$oldKeyfilePath .= '.key';
|
||||
$newKeyfilePath .= '.key';
|
||||
|
||||
foreach ($oldShareKeys as $src) {
|
||||
$dst = \OC\Files\Filesystem::normalizePath(str_replace($pathOld, $pathNew, $src));
|
||||
$view->$operation($src, $dst);
|
||||
}
|
||||
|
||||
} else {
|
||||
// handle share-keys folders
|
||||
$view->$operation($oldShareKeyPath, $newShareKeyPath);
|
||||
}
|
||||
|
||||
// Rename keyfile so it isn't orphaned
|
||||
if ($view->file_exists($oldKeyfilePath)) {
|
||||
$view->$operation($oldKeyfilePath, $newKeyfilePath);
|
||||
// create key folders if it doesn't exists
|
||||
if (!$view->file_exists(dirname($newKeysPath))) {
|
||||
$view->mkdir(dirname($newKeysPath));
|
||||
}
|
||||
|
||||
$view->$operation($oldKeysPath, $newKeysPath);
|
||||
|
||||
// update sharing-keys
|
||||
self::updateKeyfiles($params['newpath'], $type);
|
||||
|
||||
\OC_FileProxy::$enabled = $proxyStatus;
|
||||
self::updateKeyfiles($params['newpath']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -592,37 +530,28 @@ class Hooks {
|
||||
*/
|
||||
public static function postDelete($params) {
|
||||
|
||||
if (!isset(self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]])) {
|
||||
$path = $params[\OC\Files\Filesystem::signal_param_path];
|
||||
|
||||
if (!isset(self::$deleteFiles[$path])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$deletedFile = self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]];
|
||||
$path = $deletedFile['path'];
|
||||
$user = $deletedFile['uid'];
|
||||
$deletedFile = self::$deleteFiles[$path];
|
||||
$keyPath = $deletedFile['keyPath'];
|
||||
|
||||
// we don't need to remember the file any longer
|
||||
unset(self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]]);
|
||||
unset(self::$deleteFiles[$path]);
|
||||
|
||||
$view = new \OC\Files\View('/');
|
||||
|
||||
// return if the file still exists and wasn't deleted correctly
|
||||
if ($view->file_exists('/' . $user . '/files/' . $path)) {
|
||||
if ($view->file_exists('/' . \OCP\User::getUser() . '/files/' . $path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Disable encryption proxy to prevent recursive calls
|
||||
$proxyStatus = \OC_FileProxy::$enabled;
|
||||
\OC_FileProxy::$enabled = false;
|
||||
|
||||
// Delete keyfile & shareKey so it isn't orphaned
|
||||
if (!Keymanager::deleteFileKey($view, $path, $user)) {
|
||||
\OCP\Util::writeLog('Encryption library',
|
||||
'Keyfile or shareKey could not be deleted for file "' . $user.'/files/'.$path . '"', \OCP\Util::ERROR);
|
||||
}
|
||||
$view->unlink($keyPath);
|
||||
|
||||
Keymanager::delAllShareKeys($view, $user, $path);
|
||||
|
||||
\OC_FileProxy::$enabled = $proxyStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -631,6 +560,7 @@ class Hooks {
|
||||
* @return boolean|null
|
||||
*/
|
||||
public static function preDelete($params) {
|
||||
$view = new \OC\Files\View('/');
|
||||
$path = $params[\OC\Files\Filesystem::signal_param_path];
|
||||
|
||||
// skip this method if the trash bin is enabled or if we delete a file
|
||||
@ -640,67 +570,60 @@ class Hooks {
|
||||
}
|
||||
|
||||
$util = new Util(new \OC\Files\View('/'), \OCP\USER::getUser());
|
||||
list($owner, $ownerPath) = $util->getUidAndFilename($path);
|
||||
|
||||
self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]] = array(
|
||||
'uid' => $owner,
|
||||
'path' => $ownerPath);
|
||||
$keysPath = Keymanager::getKeyPath($view, $util, $path);
|
||||
|
||||
self::$deleteFiles[$path] = array(
|
||||
'keyPath' => $keysPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* unmount file from yourself
|
||||
* remember files/folders which get unmounted
|
||||
*/
|
||||
public static function preUmount($params) {
|
||||
public static function preUnmount($params) {
|
||||
$view = new \OC\Files\View('/');
|
||||
$user = \OCP\User::getUser();
|
||||
$path = $params[\OC\Files\Filesystem::signal_param_path];
|
||||
$user = \OCP\USER::getUser();
|
||||
|
||||
$view = new \OC\Files\View();
|
||||
$itemType = $view->is_dir('/' . $user . '/files' . $path) ? 'folder' : 'file';
|
||||
|
||||
$util = new Util($view, $user);
|
||||
list($owner, $ownerPath) = $util->getUidAndFilename($path);
|
||||
|
||||
self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]] = array(
|
||||
'uid' => $owner,
|
||||
'path' => $ownerPath,
|
||||
'itemType' => $itemType);
|
||||
$keysPath = Keymanager::getKeyPath($view, $util, $path);
|
||||
|
||||
self::$unmountedFiles[$path] = array(
|
||||
'keyPath' => $keysPath,
|
||||
'owner' => $owner,
|
||||
'ownerPath' => $ownerPath
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* unmount file from yourself
|
||||
*/
|
||||
public static function postUmount($params) {
|
||||
public static function postUnmount($params) {
|
||||
|
||||
if (!isset(self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]])) {
|
||||
$path = $params[\OC\Files\Filesystem::signal_param_path];
|
||||
$user = \OCP\User::getUser();
|
||||
|
||||
if (!isset(self::$unmountedFiles[$path])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$umountedFile = self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]];
|
||||
$path = $umountedFile['path'];
|
||||
$user = $umountedFile['uid'];
|
||||
$itemType = $umountedFile['itemType'];
|
||||
$umountedFile = self::$unmountedFiles[$path];
|
||||
$keyPath = $umountedFile['keyPath'];
|
||||
$owner = $umountedFile['owner'];
|
||||
$ownerPath = $umountedFile['ownerPath'];
|
||||
|
||||
$view = new \OC\Files\View();
|
||||
$util = new Util($view, $user);
|
||||
|
||||
// we don't need to remember the file any longer
|
||||
unset(self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]]);
|
||||
unset(self::$unmountedFiles[$path]);
|
||||
|
||||
// if we unshare a folder we need a list of all (sub-)files
|
||||
if ($itemType === 'folder') {
|
||||
$allFiles = $util->getAllFiles($path);
|
||||
} else {
|
||||
$allFiles = array($path);
|
||||
}
|
||||
|
||||
foreach ($allFiles as $path) {
|
||||
|
||||
// check if the user still has access to the file, otherwise delete share key
|
||||
$sharingUsers = \OCP\Share::getUsersSharingFile($path, $user);
|
||||
if (!in_array(\OCP\User::getUser(), $sharingUsers['users'])) {
|
||||
Keymanager::delShareKey($view, array(\OCP\User::getUser()), $path, $user);
|
||||
}
|
||||
// check if the user still has access to the file, otherwise delete share key
|
||||
$sharingUsers = \OCP\Share::getUsersSharingFile($path, $user);
|
||||
if (!in_array(\OCP\User::getUser(), $sharingUsers['users'])) {
|
||||
Keymanager::delShareKey($view, array(\OCP\User::getUser()), $keyPath, $owner, $ownerPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,9 +68,9 @@ class Helper {
|
||||
\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');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -432,47 +432,6 @@ class Helper {
|
||||
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
|
||||
|
@ -29,6 +29,9 @@ namespace OCA\Encryption;
|
||||
*/
|
||||
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
|
||||
*
|
||||
@ -42,15 +45,10 @@ class Keymanager {
|
||||
$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;
|
||||
}
|
||||
|
||||
@ -62,13 +60,8 @@ class Keymanager {
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
||||
@ -99,9 +92,7 @@ class Keymanager {
|
||||
$keys = array();
|
||||
|
||||
foreach ($userIds as $userId) {
|
||||
|
||||
$keys[$userId] = self::getPublicKey($view, $userId);
|
||||
|
||||
}
|
||||
|
||||
return $keys;
|
||||
@ -121,38 +112,103 @@ class Keymanager {
|
||||
*/
|
||||
public static function setFileKey(\OC\Files\View $view, $util, $path, $catfile) {
|
||||
|
||||
$proxyStatus = \OC_FileProxy::$enabled;
|
||||
\OC_FileProxy::$enabled = false;
|
||||
$basePath = self::getKeyPath($view, $util, $path);
|
||||
|
||||
list($owner, $filename) = $util->getUidAndFilename($path);
|
||||
self::keySetPreparation($view, $basePath);
|
||||
|
||||
// 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';
|
||||
}
|
||||
|
||||
$targetPath = self::keySetPreparation($view, $filename, $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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $path path to the file, relative to the users file directory
|
||||
* @return string
|
||||
*/
|
||||
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($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)) {
|
||||
$keyPath = self::KEYS_BASE_DIR . $filePath_f . '/';
|
||||
} else {
|
||||
$keyPath = '/' . $owner . self::KEYS_BASE_DIR . $filePath_f . '/';
|
||||
}
|
||||
|
||||
return $keyPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
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 = self::KEYS_BASE_DIR . $filePath_f . '/fileKey';
|
||||
} else {
|
||||
$keyfilePath = '/' . $owner . self::KEYS_BASE_DIR . $filePath_f . '/fileKey';
|
||||
}
|
||||
|
||||
return $keyfilePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* get path to share key for a given user
|
||||
*
|
||||
* @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 getShareKeyPath($view, $util, $path, $uid) {
|
||||
|
||||
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($path);
|
||||
$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 = self::KEYS_BASE_DIR . $filename . '/'. $uid . '.shareKey';
|
||||
} else {
|
||||
$shareKeyPath = '/' . $owner . self::KEYS_BASE_DIR . $filename . '/' . $uid . '.shareKey';
|
||||
}
|
||||
|
||||
return $shareKeyPath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* retrieve keyfile for an encrypted file
|
||||
* @param \OC\Files\View $view
|
||||
@ -165,86 +221,12 @@ class Keymanager {
|
||||
*/
|
||||
public static function getFileKey($view, $util, $filePath) {
|
||||
|
||||
|
||||
list($owner, $filename) = $util->getUidAndFilename($filePath);
|
||||
$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';
|
||||
} else {
|
||||
$keyfilePath = '/' . $owner . '/files_encryption/keyfiles/' . $filePath_f . '.key';
|
||||
}
|
||||
|
||||
$proxyStatus = \OC_FileProxy::$enabled;
|
||||
\OC_FileProxy::$enabled = false;
|
||||
$keyfilePath = self::getFileKeyPath($view, $util, $filePath);
|
||||
|
||||
if ($view->file_exists($keyfilePath)) {
|
||||
|
||||
$result = $view->file_get_contents($keyfilePath);
|
||||
|
||||
} else {
|
||||
|
||||
$result = false;
|
||||
|
||||
}
|
||||
|
||||
\OC_FileProxy::$enabled = $proxyStatus;
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a keyfile
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public static function deleteFileKey($view, $path, $userId=null) {
|
||||
|
||||
$trimmed = ltrim($path, '/');
|
||||
|
||||
if ($trimmed === '') {
|
||||
\OCP\Util::writeLog('Encryption library',
|
||||
'Can\'t delete file-key empty path given!', \OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($userId === null) {
|
||||
$userId = Helper::getUser($path);
|
||||
}
|
||||
$util = new Util($view, $userId);
|
||||
|
||||
if($util->isSystemWideMountPoint($path)) {
|
||||
$keyPath = '/files_encryption/keyfiles/' . $trimmed;
|
||||
} else {
|
||||
$keyPath = '/' . $userId . '/files_encryption/keyfiles/' . $trimmed;
|
||||
}
|
||||
|
||||
$result = false;
|
||||
$fileExists = $view->file_exists('/' . $userId . '/files/' . $trimmed);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -344,32 +326,18 @@ class Keymanager {
|
||||
* @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)) {
|
||||
|
||||
@ -392,89 +360,17 @@ class Keymanager {
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -482,45 +378,19 @@ class Keymanager {
|
||||
*
|
||||
* @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($keysPath, $userIds, $view);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\OC_FileProxy::$enabled = $proxyStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -528,35 +398,23 @@ class Keymanager {
|
||||
*
|
||||
* @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;
|
||||
if ($userId . '.shareKey' === $file) {
|
||||
\OCP\Util::writeLog('files_encryption', 'recursiveDelShareKey: delete share key: ' . $file, \OCP\Util::DEBUG);
|
||||
$view->unlink($dir . '/' . $file);
|
||||
}
|
||||
$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;
|
||||
}
|
||||
\OCP\Util::writeLog('files_encryption', 'recursiveDelShareKey: delete share key: ' . $file, \OCP\Util::DEBUG);
|
||||
$view->unlink($dir . '/' . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -567,21 +425,16 @@ class Keymanager {
|
||||
|
||||
/**
|
||||
* 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;
|
||||
@ -590,27 +443,6 @@ class Keymanager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -204,11 +204,11 @@ class Proxy extends \OC_FileProxy {
|
||||
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)
|
||||
) {
|
||||
|
||||
|
@ -44,10 +44,10 @@ class Util {
|
||||
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;
|
||||
@ -74,8 +74,7 @@ class Util {
|
||||
'/' . $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 =
|
||||
@ -99,8 +98,7 @@ class Util {
|
||||
|
||||
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)
|
||||
) {
|
||||
@ -149,8 +147,7 @@ class Util {
|
||||
$this->userDir,
|
||||
$this->publicKeyDir,
|
||||
$this->encryptionDir,
|
||||
$this->keyfilesPath,
|
||||
$this->shareKeysPath
|
||||
$this->keysPath
|
||||
);
|
||||
|
||||
// Check / create all necessary dirs
|
||||
@ -727,8 +724,8 @@ class Util {
|
||||
}
|
||||
|
||||
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;
|
||||
@ -845,9 +842,9 @@ class Util {
|
||||
|
||||
break;
|
||||
|
||||
case 'keyfilesPath':
|
||||
case 'keysPath':
|
||||
|
||||
return $this->keyfilesPath;
|
||||
return $this->keysPath;
|
||||
|
||||
break;
|
||||
|
||||
@ -1395,19 +1392,17 @@ class Util {
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1416,16 +1411,14 @@ class Util {
|
||||
* 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');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1455,27 +1448,17 @@ class Util {
|
||||
}
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1484,16 +1467,14 @@ class Util {
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1527,8 +1508,7 @@ class Util {
|
||||
$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');
|
||||
}
|
||||
|
@ -211,8 +211,6 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// Teardown
|
||||
$this->view->unlink($this->userId . '/files/' . $filename);
|
||||
|
||||
Encryption\Keymanager::deleteFileKey($this->view, $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -252,8 +250,6 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// Teardown
|
||||
$this->view->unlink($this->userId . '/files/' . $filename);
|
||||
|
||||
Encryption\Keymanager::deleteFileKey($this->view, $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -293,11 +289,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
$this->assertEquals($this->dataLong . $this->dataLong, $decrypted);
|
||||
|
||||
// Teardown
|
||||
|
||||
$this->view->unlink($this->userId . '/files/' . $filename);
|
||||
|
||||
Encryption\Keymanager::deleteFileKey($this->view, $filename);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -341,11 +333,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
$this->assertEquals($this->dataLong . $this->dataLong, $decrypted);
|
||||
|
||||
// Teardown
|
||||
|
||||
$this->view->unlink($this->userId . '/files/' . $filename);
|
||||
|
||||
Encryption\Keymanager::deleteFileKey($this->view, $filename);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -393,11 +381,7 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
$this->assertEquals($this->dataLong . $this->dataLong, $decrypted);
|
||||
|
||||
// Teardown
|
||||
|
||||
$this->view->unlink($this->userId . '/files/' . $filename);
|
||||
|
||||
Encryption\Keymanager::deleteFileKey($this->view, $filename);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,56 +125,4 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -163,10 +163,10 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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();
|
||||
@ -178,10 +178,10 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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
|
||||
@ -193,10 +193,10 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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
|
||||
@ -205,17 +205,17 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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');
|
||||
@ -244,10 +244,10 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -260,8 +260,8 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -272,10 +272,10 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -284,13 +284,13 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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
|
||||
|
||||
@ -327,12 +327,12 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
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);
|
||||
@ -351,18 +351,18 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -389,12 +389,12 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
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);
|
||||
@ -410,18 +410,18 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
|
@ -78,9 +78,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -140,27 +138,6 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
$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
|
||||
*/
|
||||
@ -180,7 +157,7 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
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);
|
||||
@ -256,70 +233,78 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
$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');
|
||||
@ -344,7 +329,12 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
$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(
|
||||
@ -362,147 +352,16 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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');
|
||||
@ -515,19 +374,12 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -178,8 +178,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -202,8 +202,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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/');
|
||||
@ -212,8 +212,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,8 +239,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -266,16 +266,16 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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/');
|
||||
@ -284,8 +284,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -335,9 +335,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -361,9 +361,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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');
|
||||
@ -372,9 +372,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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;
|
||||
@ -413,9 +413,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -444,9 +444,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -469,9 +469,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -481,9 +481,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -493,9 +493,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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');
|
||||
@ -504,9 +504,9 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -548,8 +548,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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';
|
||||
@ -572,8 +572,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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/');
|
||||
@ -582,8 +582,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -624,11 +624,11 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -648,11 +648,11 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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/');
|
||||
@ -661,8 +661,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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'));
|
||||
|
||||
}
|
||||
|
||||
@ -708,19 +708,19 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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));
|
||||
@ -730,12 +730,12 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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));
|
||||
@ -745,12 +745,12 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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/');
|
||||
@ -760,12 +760,12 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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'));
|
||||
@ -815,19 +815,19 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -859,19 +859,19 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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));
|
||||
@ -934,8 +934,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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;
|
||||
@ -947,8 +947,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
'/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
|
||||
@ -959,8 +959,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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/');
|
||||
@ -995,8 +995,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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
|
||||
@ -1068,10 +1068,10 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
$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);
|
||||
@ -1120,8 +1120,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
\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);
|
||||
@ -1133,12 +1133,12 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
$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);
|
||||
|
@ -138,22 +138,20 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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(
|
||||
@ -161,13 +159,12 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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(
|
||||
@ -175,13 +172,12 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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(
|
||||
@ -199,15 +195,16 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
// 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'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,6 +239,13 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
// 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));
|
||||
|
||||
@ -251,13 +255,12 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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(
|
||||
@ -265,13 +268,12 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -291,13 +293,12 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -308,13 +309,13 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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`'
|
||||
@ -328,13 +329,13 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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);
|
||||
@ -349,13 +350,13 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
$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 =
|
||||
@ -155,7 +155,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
$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'));
|
||||
|
||||
@ -396,16 +396,18 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
// 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');
|
||||
|
||||
}
|
||||
@ -418,38 +420,28 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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');
|
||||
}
|
||||
|
||||
|
||||
@ -473,8 +465,8 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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();
|
||||
@ -492,12 +484,13 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
$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();
|
||||
@ -515,17 +508,32 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderFortestIsMountPointApplicableToUser
|
||||
*/
|
||||
|
@ -143,11 +143,11 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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;
|
||||
@ -217,11 +217,11 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase {
|
||||
|
||||
// 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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,11 +92,8 @@ class Trashbin {
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
@ -277,78 +274,23 @@ class Trashbin {
|
||||
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/';
|
||||
$baseDir = '/files_encryption/';
|
||||
if (!$util->isSystemWideMountPoint($ownerPath)) {
|
||||
$baseDir = $owner . $baseDir;
|
||||
}
|
||||
|
||||
$keyfile = \OC\Files\Filesystem::normalizePath($baseDir . '/keyfiles/' . $ownerPath);
|
||||
$keyfiles = \OC\Files\Filesystem::normalizePath($baseDir . '/keys/' . $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);
|
||||
}
|
||||
}
|
||||
|
||||
// retain share keys
|
||||
$sharekeys = \OC\Files\Filesystem::normalizePath($baseDir . '/share-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;
|
||||
}
|
||||
@ -492,7 +434,7 @@ class Trashbin {
|
||||
* @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('/');
|
||||
@ -506,84 +448,31 @@ class Trashbin {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -678,27 +567,15 @@ class Trashbin {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user