From b16b17f920f0fffcf2e97762b3cd7297d6f8c43c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 22 May 2014 15:43:42 +0200 Subject: ceanup encryption code, improved return codes --- apps/files_encryption/hooks/hooks.php | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'apps/files_encryption/hooks') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 6e375f99a8e..f538d38fada 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -51,16 +51,16 @@ class Hooks { $view = new \OC\Files\View('/'); // ensure filesystem is loaded - if(!\OC\Files\Filesystem::$loaded) { + if (!\OC\Files\Filesystem::$loaded) { \OC_Util::setupFS($params['uid']); } $privateKey = \OCA\Encryption\Keymanager::getPrivateKey($view, $params['uid']); // if no private key exists, check server configuration - if(!$privateKey) { + if (!$privateKey) { //check if all requirements are met - if(!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'); @@ -90,6 +90,8 @@ class Hooks { return false; } + $result = true; + // If migration not yet done if ($ready) { @@ -97,15 +99,12 @@ class Hooks { // Set legacy encryption key if it exists, to support // depreciated encryption system - if ( - $userView->file_exists('encryption.key') - && $encLegacyKey = $userView->file_get_contents('encryption.key') - ) { + $encLegacyKey = $userView->file_get_contents('encryption.key'); + if ($encLegacyKey) { $plainLegacyKey = Crypt::legacyDecrypt($encLegacyKey, $params['password']); $session->setLegacyKey($plainLegacyKey); - } // Encrypt existing user files @@ -113,26 +112,24 @@ class Hooks { $result = $util->encryptAll('/' . $params['uid'] . '/' . 'files', $session->getLegacyKey(), $params['password']); } catch (\Exception $ex) { \OCP\Util::writeLog('Encryption library', 'Initial encryption failed! Error: ' . $ex->getMessage(), \OCP\Util::FATAL); - $util->resetMigrationStatus(); - \OCP\User::logout(); $result = false; } if ($result) { - \OC_Log::write( - 'Encryption library', 'Encryption of existing files belonging to "' . $params['uid'] . '" completed' - , \OC_Log::INFO - ); - + 'Encryption library', 'Encryption of existing files belonging to "' . $params['uid'] . '" completed' + , \OC_Log::INFO + ); // Register successful migration in DB $util->finishMigration(); - + } else { + \OCP\Util::writeLog('Encryption library', 'Initial encryption failed!', \OCP\Util::FATAL); + $util->resetMigrationStatus(); + \OCP\User::logout(); } } - return true; - + return $result; } /** -- cgit v1.2.3