From 3d49631b8d6a7cee9e4c9d4aedadf44304426fdb Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 3 Sep 2013 13:24:30 +0200 Subject: [PATCH 1/3] make sure that initial encryption also starts for a fresh installation --- apps/files_encryption/hooks/hooks.php | 20 ++++++++++---------- apps/files_encryption/lib/util.php | 3 ++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 85169e6a1d..d40ae95a44 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -44,10 +44,8 @@ class Hooks { \OC_Util::setupFS($params['uid']); } - $util = new Util($view, $params['uid']); - //check if all requirements are met - if(!$util->ready() && (!Helper::checkRequirements() || !Helper::checkConfiguration())) { + if(!Helper::checkRequirements() || !Helper::checkConfiguration()) { $error_msg = $l->t("Missing requirements."); $hint = $l->t('Please make sure that PHP 5.3.3 or newer is installed and that OpenSSL together with the PHP extension is enabled and configured properly. For now, the encryption app has been disabled.'); \OC_App::disable('files_encryption'); @@ -55,6 +53,8 @@ class Hooks { \OCP\Template::printErrorPage($error_msg, $hint); } + $util = new Util($view, $params['uid']); + // setup user, if user not ready force relogin if (Helper::setupUser($util, $params['password']) === false) { return false; @@ -73,7 +73,7 @@ class Hooks { $userView = new \OC_FilesystemView('/' . $params['uid']); - // Set legacy encryption key if it exists, to support + // Set legacy encryption key if it exists, to support // depreciated encryption system if ( $userView->file_exists('encryption.key') @@ -249,7 +249,7 @@ class Hooks { $params['run'] = false; $params['error'] = $l->t('Following users are not set up for encryption:') . ' ' . join(', ' , $notConfigured); } - + } /** @@ -260,7 +260,7 @@ class Hooks { // NOTE: $params has keys: // [itemType] => file // itemSource -> int, filecache file ID - // [parent] => + // [parent] => // [itemTarget] => /13 // shareWith -> string, uid of user being shared to // fileTarget -> path of file being shared @@ -301,13 +301,13 @@ class Hooks { // NOTE: parent is folder but shared was a file! // we try to rebuild the missing path // some examples we face here - // user1 share folder1 with user2 folder1 has - // the following structure + // user1 share folder1 with user2 folder1 has + // the following structure // /folder1/subfolder1/subsubfolder1/somefile.txt // user2 re-share subfolder2 with user3 // user3 re-share somefile.txt user4 - // so our path should be - // /Shared/subfolder1/subsubfolder1/somefile.txt + // so our path should be + // /Shared/subfolder1/subsubfolder1/somefile.txt // while user3 is sharing if ($params['itemType'] === 'file') { diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index b8d6862349..9bc5300076 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -201,10 +201,11 @@ class Util { if (false === $this->recoveryEnabledForUser()) { // create database configuration - $sql = 'INSERT INTO `*PREFIX*encryption` (`uid`,`mode`,`recovery_enabled`) VALUES (?,?,?)'; + $sql = 'INSERT INTO `*PREFIX*encryption` (`uid`,`mode`,`recovery_enabled`,`migration_status`) VALUES (?,?,?,?)'; $args = array( $this->userId, 'server-side', + 0, 0 ); $query = \OCP\DB::prepare($sql); From 4dbc78705566c3a9062fd4c4f69db60a41c5634b Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 3 Sep 2013 15:56:25 +0200 Subject: [PATCH 2/3] check if stream wrapper is already registered to avoid warning --- apps/files_encryption/appinfo/app.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php index 90a9984e27..5b62b84e22 100644 --- a/apps/files_encryption/appinfo/app.php +++ b/apps/files_encryption/appinfo/app.php @@ -25,7 +25,9 @@ if (!OC_Config::getValue('maintenance', false)) { // App manager related hooks OCA\Encryption\Helper::registerAppHooks(); - stream_wrapper_register('crypt', 'OCA\Encryption\Stream'); + if(!in_array('crypt', stream_get_wrappers())) { + stream_wrapper_register('crypt', 'OCA\Encryption\Stream'); + } // check if we are logged in if (OCP\User::isLoggedIn()) { From 72eaf2894a540bc9280e144ba493db7fcde07eac Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 17 Sep 2013 16:53:52 +0200 Subject: [PATCH 3/3] performance improvement, check configuration only if no private key exists --- apps/files_encryption/hooks/hooks.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index d40ae95a44..d9221c6e82 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -44,13 +44,18 @@ class Hooks { \OC_Util::setupFS($params['uid']); } - //check if all requirements are met - if(!Helper::checkRequirements() || !Helper::checkConfiguration()) { - $error_msg = $l->t("Missing requirements."); - $hint = $l->t('Please make sure that PHP 5.3.3 or newer is installed and that OpenSSL together with the PHP extension is enabled and configured properly. For now, the encryption app has been disabled.'); - \OC_App::disable('files_encryption'); - \OCP\Util::writeLog('Encryption library', $error_msg . ' ' . $hint, \OCP\Util::ERROR); - \OCP\Template::printErrorPage($error_msg, $hint); + $privateKey = \OCA\Encryption\Keymanager::getPrivateKey($view, $params['uid']); + + // if no private key exists, check server configuration + if(!$privateKey) { + //check if all requirements are met + if(!Helper::checkRequirements() || !Helper::checkConfiguration()) { + $error_msg = $l->t("Missing requirements."); + $hint = $l->t('Please make sure that PHP 5.3.3 or newer is installed and that OpenSSL together with the PHP extension is enabled and configured properly. For now, the encryption app has been disabled.'); + \OC_App::disable('files_encryption'); + \OCP\Util::writeLog('Encryption library', $error_msg . ' ' . $hint, \OCP\Util::ERROR); + \OCP\Template::printErrorPage($error_msg, $hint); + } } $util = new Util($view, $params['uid']);