From f274833403f1b35ddbf8e6cdf13851ae813ed121 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 25 Nov 2014 10:12:10 +0100 Subject: [PATCH 1/4] remove unused variable --- apps/files_encryption/lib/proxy.php | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 55f2df783c..a358a46a6e 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -91,7 +91,6 @@ class Proxy extends \OC_FileProxy { private function shouldEncrypt($path, $mode = 'w') { $userId = Helper::getUser($path); - $session = new Session(new \OC\Files\View()); // don't call the crypt stream wrapper, if... if ( From 917bef39b7f1c0ca495ef102b7878ed5b15830c6 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 25 Nov 2014 10:12:30 +0100 Subject: [PATCH 2/4] don't store private public-share-key in session --- apps/files_encryption/lib/session.php | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php index 7bd4fd0242..3cb0270418 100644 --- a/apps/files_encryption/lib/session.php +++ b/apps/files_encryption/lib/session.php @@ -29,6 +29,7 @@ namespace OCA\Encryption; class Session { private $view; + private static $publicShareKey = false; const NOT_INITIALIZED = '0'; const INIT_EXECUTED = '1'; @@ -92,7 +93,7 @@ class Session { } - if (\OCA\Encryption\Helper::isPublicAccess()) { + if (\OCA\Encryption\Helper::isPublicAccess() && !self::getPublicSharePrivateKey()) { // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; @@ -100,9 +101,7 @@ class Session { $encryptedKey = $this->view->file_get_contents( '/owncloud_private_key/' . $publicShareKeyId . '.private.key'); $privateKey = Crypt::decryptPrivateKey($encryptedKey, ''); - $this->setPublicSharePrivateKey($privateKey); - - $this->setInitialized(\OCA\Encryption\Session::INIT_SUCCESSFUL); + self::setPublicSharePrivateKey($privateKey); \OC_FileProxy::$enabled = $proxyStatus; } @@ -164,6 +163,8 @@ class Session { public function getInitialized() { if (!is_null(\OC::$server->getSession()->get('encryptionInitialized'))) { return \OC::$server->getSession()->get('encryptionInitialized'); + } else if (\OCA\Encryption\Helper::isPublicAccess() && self::getPublicSharePrivateKey()) { + return self::INIT_SUCCESSFUL; } else { return self::NOT_INITIALIZED; } @@ -177,7 +178,7 @@ class Session { public function getPrivateKey() { // return the public share private key if this is a public access if (\OCA\Encryption\Helper::isPublicAccess()) { - return $this->getPublicSharePrivateKey(); + return self::getPublicSharePrivateKey(); } else { if (!is_null(\OC::$server->getSession()->get('privateKey'))) { return \OC::$server->getSession()->get('privateKey'); @@ -192,12 +193,9 @@ class Session { * @param string $privateKey * @return bool */ - public function setPublicSharePrivateKey($privateKey) { - - \OC::$server->getSession()->set('publicSharePrivateKey', $privateKey); - + private static function setPublicSharePrivateKey($privateKey) { + self::$publicShareKey = $privateKey; return true; - } /** @@ -205,13 +203,8 @@ class Session { * @return string $privateKey * */ - public function getPublicSharePrivateKey() { - - if (!is_null(\OC::$server->getSession()->get('publicSharePrivateKey'))) { - return \OC::$server->getSession()->get('publicSharePrivateKey'); - } else { - return false; - } + private static function getPublicSharePrivateKey() { + return self::$publicShareKey; } } From 1d3350348797deeead5b02028c4ade7c874a7021 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 25 Nov 2014 10:17:31 +0100 Subject: [PATCH 3/4] we no longer need to keep the session open for encryption --- apps/files/ajax/upload.php | 8 ++------ apps/files_sharing/lib/controllers/sharecontroller.php | 9 +-------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index b960e02ced..aeb0008a7b 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -1,5 +1,7 @@ getSession()->close(); + // Firefox and Konqueror tries to download application/json for me. --Arthur OCP\JSON::setContentTypeHeader('text/plain'); @@ -64,13 +66,7 @@ if (empty($_POST['dirToken'])) { } } - OCP\JSON::callCheck(); -if (!\OCP\App::isEnabled('files_encryption')) { - // encryption app need to create keys later, so can't close too early - \OC::$server->getSession()->close(); -} - // get array with current storage stats (e.g. max file size) $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir); diff --git a/apps/files_sharing/lib/controllers/sharecontroller.php b/apps/files_sharing/lib/controllers/sharecontroller.php index 71b5ab7f8c..5f653e5c22 100644 --- a/apps/files_sharing/lib/controllers/sharecontroller.php +++ b/apps/files_sharing/lib/controllers/sharecontroller.php @@ -205,7 +205,6 @@ class ShareController extends Controller { /** * @PublicPage * @NoCSRFRequired - * @UseSession * * @param string $token * @param string $files @@ -215,12 +214,6 @@ class ShareController extends Controller { public function downloadShare($token, $files = null, $path = '') { \OC_User::setIncognitoMode(true); - // FIXME: Use DI once there is a suitable class - if (!\OCP\App::isEnabled('files_encryption')) { - // encryption app requires the session to store the keys in - \OC::$server->getSession()->close(); - } - $linkItem = OCP\Share::getShareByToken($token, false); // Share is password protected - check whether the user is permitted to access the share @@ -246,7 +239,7 @@ class ShareController extends Controller { } // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well - // after dispatching the request which results in a "Cannot modify header information" notice. + // after dispatching the request which results in a "Cannot modify header information" notice. OC_Files::get($originalSharePath, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD'); exit(); } else { From 4643a5d2389fa5d7432dd319e9ad12d686aecfef Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 25 Nov 2014 16:15:32 +0100 Subject: [PATCH 4/4] replace \OC:: with \OC::->getSession() --- apps/files_encryption/lib/session.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php index 3cb0270418..132748b6ea 100644 --- a/apps/files_encryption/lib/session.php +++ b/apps/files_encryption/lib/session.php @@ -126,8 +126,8 @@ class Session { * remove keys from session */ public function removeKeys() { - \OC::$session->remove('publicSharePrivateKey'); - \OC::$session->remove('privateKey'); + \OC::$server->getSession()->remove('publicSharePrivateKey'); + \OC::$server->getSession()->remove('privateKey'); } /**