$newPassword = $_POST['newPassword']; | $newPassword = $_POST['newPassword']; | ||||
$view = new \OC\Files\View('/'); | $view = new \OC\Files\View('/'); | ||||
$util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), \OCP\User::getUser()); | |||||
$util = new \OCA\Encryption\Util(new \OC\Files\View('/'), \OCP\User::getUser()); | |||||
$proxyStatus = \OC_FileProxy::$enabled; | $proxyStatus = \OC_FileProxy::$enabled; | ||||
\OC_FileProxy::$enabled = false; | \OC_FileProxy::$enabled = false; |
if ($loginname !== '' && $password !== '') { | if ($loginname !== '' && $password !== '') { | ||||
$username = \OCP\User::checkPassword($loginname, $password); | $username = \OCP\User::checkPassword($loginname, $password); | ||||
if ($username) { | if ($username) { | ||||
$util = new Util(new \OC_FilesystemView('/'), $username); | |||||
$util = new Util(new \OC\Files\View('/'), $username); | |||||
$migrationStatus = $util->getMigrationStatus(); | $migrationStatus = $util->getMigrationStatus(); | ||||
} | } | ||||
} | } |
) { | ) { | ||||
$userId = \OCP\USER::getUser(); | $userId = \OCP\USER::getUser(); | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
$util = new \OCA\Encryption\Util($view, $userId); | $util = new \OCA\Encryption\Util($view, $userId); | ||||
// Save recovery preference to DB | // Save recovery preference to DB |
\OC_Util::setupFS(); | \OC_Util::setupFS(); | ||||
} | } | ||||
$view = new OC_FilesystemView('/'); | |||||
$view = new OC\Files\View('/'); | |||||
$sessionReady = OCA\Encryption\Helper::checkRequirements(); | $sessionReady = OCA\Encryption\Helper::checkRequirements(); | ||||
if($sessionReady) { | if($sessionReady) { |
$l = new \OC_L10N('files_encryption'); | $l = new \OC_L10N('files_encryption'); | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
// ensure filesystem is loaded | // ensure filesystem is loaded | ||||
if(!\OC\Files\Filesystem::$loaded) { | if(!\OC\Files\Filesystem::$loaded) { | ||||
// If migration not yet done | // If migration not yet done | ||||
if ($ready) { | if ($ready) { | ||||
$userView = new \OC_FilesystemView('/' . $params['uid']); | |||||
$userView = new \OC\Files\View('/' . $params['uid']); | |||||
// Set legacy encryption key if it exists, to support | // Set legacy encryption key if it exists, to support | ||||
// depreciated encryption system | // depreciated encryption system | ||||
public static function postCreateUser($params) { | public static function postCreateUser($params) { | ||||
if (\OCP\App::isEnabled('files_encryption')) { | if (\OCP\App::isEnabled('files_encryption')) { | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
$util = new Util($view, $params['uid']); | $util = new Util($view, $params['uid']); | ||||
Helper::setupUser($util, $params['password']); | Helper::setupUser($util, $params['password']); | ||||
} | } | ||||
public static function postDeleteUser($params) { | public static function postDeleteUser($params) { | ||||
if (\OCP\App::isEnabled('files_encryption')) { | if (\OCP\App::isEnabled('files_encryption')) { | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
// cleanup public key | // cleanup public key | ||||
$publicKey = '/public-keys/' . $params['uid'] . '.public.key'; | $publicKey = '/public-keys/' . $params['uid'] . '.public.key'; | ||||
// the necessary keys) | // the necessary keys) | ||||
if (Crypt::mode() === 'server') { | if (Crypt::mode() === 'server') { | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
if ($params['uid'] === \OCP\User::getUser()) { | if ($params['uid'] === \OCP\User::getUser()) { | ||||
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { | if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
$session = new \OCA\Encryption\Session($view); | $session = new \OCA\Encryption\Session($view); | ||||
$userId = \OCP\User::getUser(); | $userId = \OCP\User::getUser(); | ||||
$util = new Util($view, $userId); | $util = new Util($view, $userId); | ||||
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { | if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
$userId = \OCP\User::getUser(); | $userId = \OCP\User::getUser(); | ||||
$util = new Util($view, $userId); | $util = new Util($view, $userId); | ||||
$path = \OC\Files\Filesystem::getPath($params['fileSource']); | $path = \OC\Files\Filesystem::getPath($params['fileSource']); | ||||
*/ | */ | ||||
public static function preRename($params) { | public static function preRename($params) { | ||||
$user = \OCP\User::getUser(); | $user = \OCP\User::getUser(); | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
$util = new Util($view, $user); | $util = new Util($view, $user); | ||||
list($ownerOld, $pathOld) = $util->getUidAndFilename($params['oldpath']); | list($ownerOld, $pathOld) = $util->getUidAndFilename($params['oldpath']); | ||||
$proxyStatus = \OC_FileProxy::$enabled; | $proxyStatus = \OC_FileProxy::$enabled; | ||||
\OC_FileProxy::$enabled = false; | \OC_FileProxy::$enabled = false; | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
$session = new \OCA\Encryption\Session($view); | $session = new \OCA\Encryption\Session($view); | ||||
$userId = \OCP\User::getUser(); | $userId = \OCP\User::getUser(); | ||||
$util = new Util($view, $userId); | $util = new Util($view, $userId); | ||||
return true; | return true; | ||||
} | } | ||||
$util = new Util(new \OC_FilesystemView('/'), \OCP\USER::getUser()); | |||||
$util = new Util(new \OC\Files\View('/'), \OCP\USER::getUser()); | |||||
list($owner, $ownerPath) = $util->getUidAndFilename($path); | list($owner, $ownerPath) = $util->getUidAndFilename($path); | ||||
self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]] = array( | self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]] = array( |
$return = true; | $return = true; | ||||
} else { // get recovery key and check the password | } else { // get recovery key and check the password | ||||
$util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), \OCP\User::getUser()); | |||||
$util = new \OCA\Encryption\Util(new \OC\Files\View('/'), \OCP\User::getUser()); | |||||
$return = $util->checkRecoveryPassword($recoveryPassword); | $return = $util->checkRecoveryPassword($recoveryPassword); | ||||
if ($return) { | if ($return) { | ||||
$appConfig->setValue('files_encryption', 'recoveryAdminEnabled', 1); | $appConfig->setValue('files_encryption', 'recoveryAdminEnabled', 1); | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public static function adminDisableRecovery($recoveryPassword) { | public static function adminDisableRecovery($recoveryPassword) { | ||||
$util = new Util(new \OC_FilesystemView('/'), \OCP\User::getUser()); | |||||
$util = new Util(new \OC\Files\View('/'), \OCP\User::getUser()); | |||||
$return = $util->checkRecoveryPassword($recoveryPassword); | $return = $util->checkRecoveryPassword($recoveryPassword); | ||||
if ($return) { | if ($return) { |
/** | /** | ||||
* @brief retrieve the ENCRYPTED private key from a user | * @brief retrieve the ENCRYPTED private key from a user | ||||
* | * | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* @param string $user | * @param string $user | ||||
* @return string private key or false (hopefully) | * @return string private key or false (hopefully) | ||||
* @note the key returned by this method must be decrypted before use | * @note the key returned by this method must be decrypted before use | ||||
*/ | */ | ||||
public static function getPrivateKey(\OC_FilesystemView $view, $user) { | |||||
public static function getPrivateKey(\OC\Files\View $view, $user) { | |||||
$path = '/' . $user . '/' . 'files_encryption' . '/' . $user . '.private.key'; | $path = '/' . $user . '/' . 'files_encryption' . '/' . $user . '.private.key'; | ||||
$key = false; | $key = false; | ||||
/** | /** | ||||
* @brief retrieve public key for a specified user | * @brief retrieve public key for a specified user | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* @param $userId | * @param $userId | ||||
* @return string public key or false | * @return string public key or false | ||||
*/ | */ | ||||
public static function getPublicKey(\OC_FilesystemView $view, $userId) { | |||||
public static function getPublicKey(\OC\Files\View $view, $userId) { | |||||
$proxyStatus = \OC_FileProxy::$enabled; | $proxyStatus = \OC_FileProxy::$enabled; | ||||
\OC_FileProxy::$enabled = false; | \OC_FileProxy::$enabled = false; | ||||
/** | /** | ||||
* @brief Retrieve a user's public and private key | * @brief Retrieve a user's public and private key | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* @param $userId | * @param $userId | ||||
* @return array keys: privateKey, publicKey | * @return array keys: privateKey, publicKey | ||||
*/ | */ | ||||
public static function getUserKeys(\OC_FilesystemView $view, $userId) { | |||||
public static function getUserKeys(\OC\Files\View $view, $userId) { | |||||
return array( | return array( | ||||
'publicKey' => self::getPublicKey($view, $userId), | 'publicKey' => self::getPublicKey($view, $userId), | ||||
/** | /** | ||||
* @brief Retrieve public keys for given users | * @brief Retrieve public keys for given users | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* @param array $userIds | * @param array $userIds | ||||
* @return array of public keys for the specified users | * @return array of public keys for the specified users | ||||
*/ | */ | ||||
public static function getPublicKeys(\OC_FilesystemView $view, array $userIds) { | |||||
public static function getPublicKeys(\OC\Files\View $view, array $userIds) { | |||||
$keys = array(); | $keys = array(); | ||||
/** | /** | ||||
* @brief store file encryption key | * @brief store file encryption key | ||||
* | * | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* @param \OCA\Encryption\Util $util | * @param \OCA\Encryption\Util $util | ||||
* @param string $path relative path of the file, including filename | * @param string $path relative path of the file, including filename | ||||
* @param string $catfile keyfile content | * @param string $catfile keyfile content | ||||
* @note The keyfile is not encrypted here. Client code must | * @note The keyfile is not encrypted here. Client code must | ||||
* asymmetrically encrypt the keyfile before passing it to this method | * asymmetrically encrypt the keyfile before passing it to this method | ||||
*/ | */ | ||||
public static function setFileKey(\OC_FilesystemView $view, $util, $path, $catfile) { | |||||
public static function setFileKey(\OC\Files\View $view, $util, $path, $catfile) { | |||||
$proxyStatus = \OC_FileProxy::$enabled; | $proxyStatus = \OC_FileProxy::$enabled; | ||||
\OC_FileProxy::$enabled = false; | \OC_FileProxy::$enabled = false; | ||||
/** | /** | ||||
* @brief retrieve keyfile for an encrypted file | * @brief retrieve keyfile for an encrypted file | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* @param \OCA\Encryption\Util $util | * @param \OCA\Encryption\Util $util | ||||
* @param string|false $filePath | * @param string|false $filePath | ||||
* @internal param \OCA\Encryption\file $string name | * @internal param \OCA\Encryption\file $string name | ||||
/** | /** | ||||
* @brief Delete a keyfile | * @brief Delete a keyfile | ||||
* | * | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* @param string $path path of the file the key belongs to | * @param string $path path of the file the key belongs to | ||||
* @param string $userId the user to whom the file belongs | * @param string $userId the user to whom the file belongs | ||||
* @return bool Outcome of unlink operation | * @return bool Outcome of unlink operation | ||||
$user = \OCP\User::getUser(); | $user = \OCP\User::getUser(); | ||||
$view = new \OC_FilesystemView('/' . $user . '/files_encryption'); | |||||
$view = new \OC\Files\View('/' . $user . '/files_encryption'); | |||||
$proxyStatus = \OC_FileProxy::$enabled; | $proxyStatus = \OC_FileProxy::$enabled; | ||||
\OC_FileProxy::$enabled = false; | \OC_FileProxy::$enabled = false; | ||||
/** | /** | ||||
* @brief store share key | * @brief store share key | ||||
* | * | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* @param string $path where the share key is stored | * @param string $path where the share key is stored | ||||
* @param $shareKey | * @param $shareKey | ||||
* @return bool true/false | * @return bool true/false | ||||
* @note The keyfile is not encrypted here. Client code must | * @note The keyfile is not encrypted here. Client code must | ||||
* asymmetrically encrypt the keyfile before passing it to this method | * asymmetrically encrypt the keyfile before passing it to this method | ||||
*/ | */ | ||||
private static function setShareKey(\OC_FilesystemView $view, $path, $shareKey) { | |||||
private static function setShareKey(\OC\Files\View $view, $path, $shareKey) { | |||||
$proxyStatus = \OC_FileProxy::$enabled; | $proxyStatus = \OC_FileProxy::$enabled; | ||||
\OC_FileProxy::$enabled = false; | \OC_FileProxy::$enabled = false; | ||||
/** | /** | ||||
* @brief store multiple share keys for a single file | * @brief store multiple share keys for a single file | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* @param \OCA\Encryption\Util $util | * @param \OCA\Encryption\Util $util | ||||
* @param string $path | * @param string $path | ||||
* @param array $shareKeys | * @param array $shareKeys | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public static function setShareKeys(\OC_FilesystemView $view, $util, $path, array $shareKeys) { | |||||
public static function setShareKeys(\OC\Files\View $view, $util, $path, array $shareKeys) { | |||||
// $shareKeys must be an array with the following format: | // $shareKeys must be an array with the following format: | ||||
// [userId] => [encrypted key] | // [userId] => [encrypted key] | ||||
/** | /** | ||||
* @brief retrieve shareKey for an encrypted file | * @brief retrieve shareKey for an encrypted file | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* @param string $userId | * @param string $userId | ||||
* @param \OCA\Encryption\Util $util | * @param \OCA\Encryption\Util $util | ||||
* @param string $filePath | * @param string $filePath | ||||
* @note The sharekey returned is encrypted. Decryption | * @note The sharekey returned is encrypted. Decryption | ||||
* of the keyfile must be performed by client code | * of the keyfile must be performed by client code | ||||
*/ | */ | ||||
public static function getShareKey(\OC_FilesystemView $view, $userId, $util, $filePath) { | |||||
public static function getShareKey(\OC\Files\View $view, $userId, $util, $filePath) { | |||||
// try reusing key file if part file | // try reusing key file if part file | ||||
$proxyStatus = \OC_FileProxy::$enabled; | $proxyStatus = \OC_FileProxy::$enabled; | ||||
/** | /** | ||||
* @brief delete all share keys of a given file | * @brief delete all share keys of a given file | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* @param string $userId owner of the file | * @param string $userId owner of the file | ||||
* @param string $filePath path to the file, relative to the owners file dir | * @param string $filePath path to the file, relative to the owners file dir | ||||
*/ | */ | ||||
/** | /** | ||||
* @brief Delete a single user's shareKey for a single file | * @brief Delete a single user's shareKey for a single file | ||||
*/ | */ | ||||
public static function delShareKey(\OC_FilesystemView $view, $userIds, $filePath) { | |||||
public static function delShareKey(\OC\Files\View $view, $userIds, $filePath) { | |||||
$proxyStatus = \OC_FileProxy::$enabled; | $proxyStatus = \OC_FileProxy::$enabled; | ||||
\OC_FileProxy::$enabled = false; | \OC_FileProxy::$enabled = false; | ||||
* @param string|boolean $path | * @param string|boolean $path | ||||
* @param string $basePath | * @param string $basePath | ||||
*/ | */ | ||||
public static function keySetPreparation(\OC_FilesystemView $view, $path, $basePath, $userId) { | |||||
public static function keySetPreparation(\OC\Files\View $view, $path, $basePath, $userId) { | |||||
$targetPath = ltrim($path, '/'); | $targetPath = ltrim($path, '/'); | ||||
return false; | return false; | ||||
} | } | ||||
$view = new \OC_FilesystemView(''); | |||||
$view = new \OC\Files\View(''); | |||||
$util = new Util($view, $userId); | $util = new Util($view, $userId); | ||||
// for write operation we always encrypt the files, for read operations | // for write operation we always encrypt the files, for read operations | ||||
if (!is_resource($data)) { | if (!is_resource($data)) { | ||||
// get root view | // get root view | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
// get relative path | // get relative path | ||||
$relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path); | $relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path); | ||||
public function postFile_put_contents($path, $result) { | public function postFile_put_contents($path, $result) { | ||||
$normalizedPath = \OC\Files\Filesystem::normalizePath($path); | $normalizedPath = \OC\Files\Filesystem::normalizePath($path); | ||||
if ( isset(self::$unencryptedSizes[$normalizedPath]) ) { | if ( isset(self::$unencryptedSizes[$normalizedPath]) ) { | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
$view->putFileInfo($normalizedPath, | $view->putFileInfo($normalizedPath, | ||||
array('encrypted' => true, 'unencrypted_size' => self::$unencryptedSizes[$normalizedPath])); | array('encrypted' => true, 'unencrypted_size' => self::$unencryptedSizes[$normalizedPath])); | ||||
unset(self::$unencryptedSizes[$normalizedPath]); | unset(self::$unencryptedSizes[$normalizedPath]); | ||||
public function postFile_get_contents($path, $data) { | public function postFile_get_contents($path, $data) { | ||||
$plainData = null; | $plainData = null; | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
// init session | // init session | ||||
$session = new \OCA\Encryption\Session($view); | $session = new \OCA\Encryption\Session($view); | ||||
*/ | */ | ||||
public function postFileSize($path, $size) { | public function postFileSize($path, $size) { | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
$userId = Helper::getUser($path); | $userId = Helper::getUser($path); | ||||
$util = new Util($view, $userId); | $util = new Util($view, $userId); |
/** | /** | ||||
* @brief if session is started, check if ownCloud key pair is set up, if not create it | * @brief if session is started, check if ownCloud key pair is set up, if not create it | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* | * | ||||
* @note The ownCloud key pair is used to allow public link sharing even if encryption is enabled | * @note The ownCloud key pair is used to allow public link sharing even if encryption is enabled | ||||
*/ | */ |
$this->newFile = false; | $this->newFile = false; | ||||
if (!isset($this->rootView)) { | if (!isset($this->rootView)) { | ||||
$this->rootView = new \OC_FilesystemView('/'); | |||||
$this->rootView = new \OC\Files\View('/'); | |||||
} | } | ||||
$this->session = new \OCA\Encryption\Session($this->rootView); | $this->session = new \OCA\Encryption\Session($this->rootView); |
/** | /** | ||||
* @brief Class for utilities relating to encrypted file storage system | * @brief Class for utilities relating to encrypted file storage system | ||||
* @param \OC_FilesystemView $view expected to have OC '/' as root path | |||||
* @param \OC\Files\View $view expected to have OC '/' as root path | |||||
* @param string $userId ID of the logged in user | * @param string $userId ID of the logged in user | ||||
* @param int $client indicating status of client side encryption. Currently | * @param int $client indicating status of client side encryption. Currently | ||||
* unused, likely to become obsolete shortly | * unused, likely to become obsolete shortly | ||||
const MIGRATION_IN_PROGRESS = -1; // migration is running | const MIGRATION_IN_PROGRESS = -1; // migration is running | ||||
const MIGRATION_OPEN = 0; // user still needs to be migrated | const MIGRATION_OPEN = 0; // user still needs to be migrated | ||||
private $view; // OC_FilesystemView object for filesystem operations | |||||
private $view; // OC\Files\View object for filesystem operations | |||||
private $userId; // ID of the user we use to encrypt/decrypt files | private $userId; // ID of the user we use to encrypt/decrypt files | ||||
private $keyId; // ID of the key we want to manipulate | private $keyId; // ID of the key we want to manipulate | ||||
private $client; // Client side encryption mode flag | private $client; // Client side encryption mode flag | ||||
private $isPublic; | private $isPublic; | ||||
/** | /** | ||||
* @param \OC_FilesystemView $view | |||||
* @param \OC\Files\View $view | |||||
* @param $userId | * @param $userId | ||||
* @param bool $client | * @param bool $client | ||||
*/ | */ | ||||
if ($item['type'] === 'dir') { | if ($item['type'] === 'dir') { | ||||
$this->addRecoveryKeys($filePath . '/'); | $this->addRecoveryKeys($filePath . '/'); | ||||
} else { | } else { | ||||
$session = new \OCA\Encryption\Session(new \OC_FilesystemView('/')); | |||||
$session = new \OCA\Encryption\Session(new \OC\Files\View('/')); | |||||
$sharingEnabled = \OCP\Share::isEnabled(); | $sharingEnabled = \OCP\Share::isEnabled(); | ||||
// remove '.key' extension from path e.g. 'file.txt.key' to 'file.txt' | // remove '.key' extension from path e.g. 'file.txt.key' to 'file.txt' | ||||
$file = substr($filePath, 0, -4); | $file = substr($filePath, 0, -4); |
$tmpl = new OCP\Template('files_encryption', 'settings-personal'); | $tmpl = new OCP\Template('files_encryption', 'settings-personal'); | ||||
$user = \OCP\USER::getUser(); | $user = \OCP\USER::getUser(); | ||||
$view = new \OC_FilesystemView('/'); | |||||
$view = new \OC\Files\View('/'); | |||||
$util = new \OCA\Encryption\Util($view, $user); | $util = new \OCA\Encryption\Util($view, $user); | ||||
$session = new \OCA\Encryption\Session($view); | $session = new \OCA\Encryption\Session($view); | ||||
public $dataUrl; | public $dataUrl; | ||||
public $dataShort; | public $dataShort; | ||||
/** | /** | ||||
* @var OC_FilesystemView | |||||
* @var OC\Files\View | |||||
*/ | */ | ||||
public $view; | public $view; | ||||
public $legacyEncryptedData; | public $legacyEncryptedData; | ||||
$this->genPublicKey = $keypair['publicKey']; | $this->genPublicKey = $keypair['publicKey']; | ||||
$this->genPrivateKey = $keypair['privateKey']; | $this->genPrivateKey = $keypair['privateKey']; | ||||
$this->view = new \OC_FilesystemView('/'); | |||||
$this->view = new \OC\Files\View('/'); | |||||
// remember files_trashbin state | // remember files_trashbin state | ||||
$this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); | $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin'); | ||||
$filename = 'tmp-' . uniqid() . '.test'; | $filename = 'tmp-' . uniqid() . '.test'; | ||||
$util = new Encryption\Util(new \OC_FilesystemView(), $this->userId); | |||||
$util = new Encryption\Util(new \OC\Files\View(), $this->userId); | |||||
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/'. $filename, $this->dataShort); | $cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/'. $filename, $this->dataShort); | ||||
// Generate a a random filename | // Generate a a random filename | ||||
$filename = 'tmp-' . uniqid() . '.test'; | $filename = 'tmp-' . uniqid() . '.test'; | ||||
$util = new Encryption\Util(new \OC_FilesystemView(), $this->userId); | |||||
$util = new Encryption\Util(new \OC\Files\View(), $this->userId); | |||||
// Save long data as encrypted file using stream wrapper | // Save long data as encrypted file using stream wrapper | ||||
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong . $this->dataLong); | $cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong . $this->dataLong); |
const TEST_ENCRYPTION_HOOKS_USER2 = "test-encryption-hooks-user2"; | const TEST_ENCRYPTION_HOOKS_USER2 = "test-encryption-hooks-user2"; | ||||
/** | /** | ||||
* @var \OC_FilesystemView | |||||
* @var \OC\Files\View | |||||
*/ | */ | ||||
public $user1View; // view on /data/user1/files | public $user1View; // view on /data/user1/files | ||||
public $user2View; // view on /data/user2/files | public $user2View; // view on /data/user2/files | ||||
\OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1); | \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1); | ||||
// init filesystem view | // init filesystem view | ||||
$this->user1View = new \OC_FilesystemView('/'. \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '/files'); | |||||
$this->user2View = new \OC_FilesystemView('/'. \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '/files'); | |||||
$this->rootView = new \OC_FilesystemView('/'); | |||||
$this->user1View = new \OC\Files\View('/'. \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '/files'); | |||||
$this->user2View = new \OC\Files\View('/'. \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '/files'); | |||||
$this->rootView = new \OC\Files\View('/'); | |||||
// init short data | // init short data | ||||
$this->data = 'hats'; | $this->data = 'hats'; |
public $pass; | public $pass; | ||||
public $stateFilesTrashbin; | public $stateFilesTrashbin; | ||||
/** | /** | ||||
* @var OC_FilesystemView | |||||
* @var OC\Files\View | |||||
*/ | */ | ||||
public $view; | public $view; | ||||
public $randomKey; | public $randomKey; | ||||
$this->genPublicKey = $keypair['publicKey']; | $this->genPublicKey = $keypair['publicKey']; | ||||
$this->genPrivateKey = $keypair['privateKey']; | $this->genPrivateKey = $keypair['privateKey']; | ||||
$this->view = new \OC_FilesystemView('/'); | |||||
$this->view = new \OC\Files\View('/'); | |||||
\OC_User::setUserId(\Test_Encryption_Keymanager::TEST_USER); | \OC_User::setUserId(\Test_Encryption_Keymanager::TEST_USER); | ||||
$this->userId = \Test_Encryption_Keymanager::TEST_USER; | $this->userId = \Test_Encryption_Keymanager::TEST_USER; | ||||
public static function testGetFilenameFromShareKey($sharekey) { | public static function testGetFilenameFromShareKey($sharekey) { | ||||
return self::getFilenameFromShareKey($sharekey); | return self::getFilenameFromShareKey($sharekey); | ||||
} | } | ||||
} | |||||
} |
public $userId; | public $userId; | ||||
public $pass; | public $pass; | ||||
/** | /** | ||||
* @var \OC_FilesystemView | |||||
* @var \OC\Files\View | |||||
*/ | */ | ||||
public $view; // view in /data/user/files | public $view; // view in /data/user/files | ||||
public $rootView; // view on /data/user | public $rootView; // view on /data/user | ||||
$this->pass = \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1; | $this->pass = \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1; | ||||
// init filesystem view | // init filesystem view | ||||
$this->view = new \OC_FilesystemView('/'. \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files'); | |||||
$this->rootView = new \OC_FilesystemView('/'. \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 ); | |||||
$this->view = new \OC\Files\View('/'. \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files'); | |||||
$this->rootView = new \OC\Files\View('/'. \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 ); | |||||
// init short data | // init short data | ||||
$this->data = 'hats'; | $this->data = 'hats'; |
public $filename; | public $filename; | ||||
public $dataShort; | public $dataShort; | ||||
/** | /** | ||||
* @var OC_FilesystemView | |||||
* @var OC\Files\View | |||||
*/ | */ | ||||
public $view; | public $view; | ||||
public $folder1; | public $folder1; | ||||
function setUp() { | function setUp() { | ||||
$this->dataShort = 'hats'; | $this->dataShort = 'hats'; | ||||
$this->view = new \OC_FilesystemView('/'); | |||||
$this->view = new \OC\Files\View('/'); | |||||
$this->folder1 = '/folder1'; | $this->folder1 = '/folder1'; | ||||
$this->subfolder = '/subfolder1'; | $this->subfolder = '/subfolder1'; | ||||
// login as admin | // login as admin | ||||
\Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); | \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); | ||||
$util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); | |||||
$util = new \OCA\Encryption\Util(new \OC\Files\View('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); | |||||
// check if recovery password match | // check if recovery password match | ||||
$this->assertTrue($util->checkRecoveryPassword('test123')); | $this->assertTrue($util->checkRecoveryPassword('test123')); | ||||
// login as user2 | // login as user2 | ||||
\Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); | \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); | ||||
$util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); | |||||
$util = new \OCA\Encryption\Util(new \OC\Files\View('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); | |||||
// enable recovery for admin | // enable recovery for admin | ||||
$this->assertTrue($util->setRecoveryForUser(1)); | $this->assertTrue($util->setRecoveryForUser(1)); |
public $userId; | public $userId; | ||||
public $pass; | public $pass; | ||||
/** | /** | ||||
* @var \OC_FilesystemView | |||||
* @var \OC\Files\View | |||||
*/ | */ | ||||
public $view; | public $view; | ||||
public $dataShort; | public $dataShort; | ||||
$this->pass = \Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1; | $this->pass = \Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1; | ||||
// init filesystem view | // init filesystem view | ||||
$this->view = new \OC_FilesystemView('/'); | |||||
$this->view = new \OC\Files\View('/'); | |||||
// init short data | // init short data | ||||
$this->dataShort = 'hats'; | $this->dataShort = 'hats'; |
public $userId; | public $userId; | ||||
public $pass; | public $pass; | ||||
/** | /** | ||||
* @var \OC_FilesystemView | |||||
* @var \OC\Files\View | |||||
*/ | */ | ||||
public $view; | public $view; | ||||
public $dataShort; | public $dataShort; | ||||
$this->pass = \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1; | $this->pass = \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1; | ||||
// init filesystem view | // init filesystem view | ||||
$this->view = new \OC_FilesystemView('/'); | |||||
$this->view = new \OC\Files\View('/'); | |||||
// init short data | // init short data | ||||
$this->dataShort = 'hats'; | $this->dataShort = 'hats'; |
public $publicKeyDir; | public $publicKeyDir; | ||||
public $pass; | public $pass; | ||||
/** | /** | ||||
* @var OC_FilesystemView | |||||
* @var OC\Files\View | |||||
*/ | */ | ||||
public $view; | public $view; | ||||
public $keyfilesPath; | public $keyfilesPath; | ||||
$this->privateKeyPath = | $this->privateKeyPath = | ||||
$this->encryptionDir . '/' . $this->userId . '.private.key'; // e.g. data/admin/admin.private.key | $this->encryptionDir . '/' . $this->userId . '.private.key'; // e.g. data/admin/admin.private.key | ||||
$this->view = new \OC_FilesystemView('/'); | |||||
$this->view = new \OC\Files\View('/'); | |||||
$this->util = new Encryption\Util($this->view, $this->userId); | $this->util = new Encryption\Util($this->view, $this->userId); | ||||
function testIsLegacyUser() { | function testIsLegacyUser() { | ||||
\Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER); | \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER); | ||||
$userView = new \OC_FilesystemView('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER); | |||||
$userView = new \OC\Files\View('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER); | |||||
// Disable encryption proxy to prevent recursive calls | // Disable encryption proxy to prevent recursive calls | ||||
$proxyStatus = \OC_FileProxy::$enabled; | $proxyStatus = \OC_FileProxy::$enabled; | ||||
$params = array('uid' => \OCP\User::getUser(), | $params = array('uid' => \OCP\User::getUser(), | ||||
'password' => \OCP\User::getUser()); | 'password' => \OCP\User::getUser()); | ||||
$view = new OC_FilesystemView('/'); | |||||
$view = new OC\Files\View('/'); | |||||
$util = new \OCA\Encryption\Util($view, \OCP\User::getUser()); | $util = new \OCA\Encryption\Util($view, \OCP\User::getUser()); | ||||
$result = $util->initEncryption($params); | $result = $util->initEncryption($params); | ||||
function testEncryptLegacyFiles() { | function testEncryptLegacyFiles() { | ||||
\Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER); | \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER); | ||||
$userView = new \OC_FilesystemView('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER); | |||||
$view = new \OC_FilesystemView('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER . '/files'); | |||||
$userView = new \OC\Files\View('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER); | |||||
$view = new \OC\Files\View('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER . '/files'); | |||||
// Disable encryption proxy to prevent recursive calls | // Disable encryption proxy to prevent recursive calls | ||||
$proxyStatus = \OC_FileProxy::$enabled; | $proxyStatus = \OC_FileProxy::$enabled; |
public $userId; | public $userId; | ||||
public $pass; | public $pass; | ||||
/** | /** | ||||
* @var \OC_FilesystemView | |||||
* @var \OC\Files\View | |||||
*/ | */ | ||||
public $view; | public $view; | ||||
public $dataShort; | public $dataShort; | ||||
$this->pass = \Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1; | $this->pass = \Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1; | ||||
// init filesystem view | // init filesystem view | ||||
$this->view = new \OC_FilesystemView('/'); | |||||
$this->view = new \OC\Files\View('/'); | |||||
// init short data | // init short data | ||||
$this->dataShort = 'hats'; | $this->dataShort = 'hats'; |
public $filename; | public $filename; | ||||
public $data; | public $data; | ||||
/** | /** | ||||
* @var OC_FilesystemView | |||||
* @var OC\Files\View | |||||
*/ | */ | ||||
public $view; | public $view; | ||||
public $folder; | public $folder; | ||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); | self::loginHelper(self::TEST_FILES_SHARING_API_USER1); | ||||
$this->data = 'foobar'; | $this->data = 'foobar'; | ||||
$this->view = new \OC_FilesystemView('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); | |||||
$this->view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); | |||||
// remember files_encryption state | // remember files_encryption state | ||||
$this->stateFilesEncryption = \OC_App::isEnabled('files_encryption'); | $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption'); | ||||
class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base { | class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base { | ||||
/** | /** | ||||
* @var OC_FilesystemView | |||||
* @var OC\Files\View | |||||
*/ | */ | ||||
public $user2View; | public $user2View; | ||||
list($owner, $ownerPath) = self::getUidAndFilename($file_path); | list($owner, $ownerPath) = self::getUidAndFilename($file_path); | ||||
$util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), $user); | |||||
$util = new \OCA\Encryption\Util(new \OC\Files\View('/'), $user); | |||||
// disable proxy to prevent recursive calls | // disable proxy to prevent recursive calls | ||||
$proxyStatus = \OC_FileProxy::$enabled; | $proxyStatus = \OC_FileProxy::$enabled; | ||||
list($owner, $ownerPath) = self::getUidAndFilename($target); | list($owner, $ownerPath) = self::getUidAndFilename($target); | ||||
$util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), $user); | |||||
$util = new \OCA\Encryption\Util(new \OC\Files\View('/'), $user); | |||||
if ($util->isSystemWideMountPoint($ownerPath)) { | if ($util->isSystemWideMountPoint($ownerPath)) { | ||||
$baseDir = '/files_encryption/'; | $baseDir = '/files_encryption/'; | ||||
$rootView->rename($ownerShareKey, $baseDir . '/share-keys/' . $ownerPath . '.' . $user . '.shareKey'); | $rootView->rename($ownerShareKey, $baseDir . '/share-keys/' . $ownerPath . '.' . $user . '.shareKey'); | ||||
// try to re-share if file is shared | // try to re-share if file is shared | ||||
$filesystemView = new \OC_FilesystemView('/'); | |||||
$filesystemView = new \OC\Files\View('/'); | |||||
$session = new \OCA\Encryption\Session($filesystemView); | $session = new \OCA\Encryption\Session($filesystemView); | ||||
$util = new \OCA\Encryption\Util($filesystemView, $user); | $util = new \OCA\Encryption\Util($filesystemView, $user); | ||||
* working with files within that view (e.g. read, write, delete, etc.). Each | * working with files within that view (e.g. read, write, delete, etc.). Each | ||||
* view is restricted to a set of directories via a virtual root. The default view | * view is restricted to a set of directories via a virtual root. The default view | ||||
* uses the currently logged in user's data directory as root (parts of | * uses the currently logged in user's data directory as root (parts of | ||||
* OC_Filesystem are merely a wrapper for OC_FilesystemView). | |||||
* OC_Filesystem are merely a wrapper for OC\Files\View). | |||||
* | * | ||||
* Apps that need to access files outside of the user data folders (to modify files | * Apps that need to access files outside of the user data folders (to modify files | ||||
* belonging to a user other than the one currently logged in, for example) should | * belonging to a user other than the one currently logged in, for example) should |
<?php | |||||
/** | |||||
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> | |||||
* This file is licensed under the Affero General Public License version 3 or | |||||
* later. | |||||
* See the COPYING-README file. */ | |||||
class OC_FilesystemView extends \OC\Files\View {} |
$params = array('uid' => \OCP\User::getUser(), | $params = array('uid' => \OCP\User::getUser(), | ||||
'password' => $_POST['password']); | 'password' => $_POST['password']); | ||||
$view = new OC_FilesystemView('/'); | |||||
$view = new OC\Files\View('/'); | |||||
$util = new \OCA\Encryption\Util($view, \OCP\User::getUser()); | $util = new \OCA\Encryption\Util($view, \OCP\User::getUser()); | ||||
$l = \OC_L10N::get('settings'); | $l = \OC_L10N::get('settings'); | ||||
if (\OC_App::isEnabled('files_encryption')) { | if (\OC_App::isEnabled('files_encryption')) { | ||||
//handle the recovery case | //handle the recovery case | ||||
$util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), $username); | |||||
$util = new \OCA\Encryption\Util(new \OC\Files\View('/'), $username); | |||||
$recoveryAdminEnabled = \OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled'); | $recoveryAdminEnabled = \OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled'); | ||||
$validRecoveryPassword = false; | $validRecoveryPassword = false; |