$server->getLogger(),
$container->query('UserSetup'),
$server->getUserSession(),
- new \OCP\Util(),
$container->query('Util'),
- $server->getSession()),
+ new \OCA\Encryption\Session($server->getSession())),
]);
$hookManager->fireHooks();
$c->query('Crypt'),
$server->getConfig(),
$server->getUserSession(),
- $server->getSession(),
+ new \OCA\Encryption\Session($server->getSession()),
$server->getLogger(),
$c->query('Recovery')
);
namespace OCA\Encryption\Hooks;
-use OCP\ISession;
use OCP\Util as OCUtil;
use OCA\Encryption\Hooks\Contracts\IHook;
use OCA\Encryption\KeyManager;
use OCP\ILogger;
use OCP\IUserSession;
use OCA\Encryption\Util;
-use Test\User;
+use OCA\Encryption\Session;
class UserHooks implements IHook {
/**
*/
private $util;
/**
- * @var ISession
+ * @var Session
*/
private $session;
* @param ILogger $logger
* @param Setup $userSetup
* @param IUserSession $user
- * @param OCUtil $ocUtil
* @param Util $util
- * @param ISession $session
+ * @param Session $session
*/
public function __construct(KeyManager $keyManager,
ILogger $logger,
Setup $userSetup,
IUserSession $user,
- OCUtil $ocUtil,
Util $util,
- ISession $session) {
+ Session $session) {
$this->keyManager = $keyManager;
$this->logger = $logger;
--- /dev/null
+<?php
+ /**
+ * @author Clark Tomlinson <clark@owncloud.com>
+ * @since 2/25/15, 9:39 AM
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+
+namespace OCA\Encryption\Exceptions;
+
+
+class PrivateKeyMissingException extends GenericEncryptionException{
+
+}
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUserSession;
-use \OCP\ISession;
+use \OCA\Encryption\Session;
class KeyManager {
/**
- * @var ISession
+ * @var Session
*/
- public static $session;
+ protected $session;
/**
* @var IStorage
*/
* @var ILogger
*/
private $log;
- /**
- * @var Recovery
- */
- private $recovery;
/**
* @param IStorage $keyStorage
* @param Crypt $crypt
* @param IConfig $config
* @param IUserSession $userSession
- * @param \OCP\ISession $session
+ * @param Session $session
* @param ILogger $log
* @param Recovery $recovery
*/
Crypt $crypt,
IConfig $config,
IUserSession $userSession,
- ISession $session,
+ Session $session,
ILogger $log,
Recovery $recovery
) {
- self::$session = $session;
+ $this->session = $session;
$this->keyStorage = $keyStorage;
$this->crypt = $crypt;
$this->config = $config;
*
* @param string $uid userid
* @param string $passPhrase users password
- * @return ISession
*/
public function init($uid, $passPhrase) {
try {
return false;
}
-
- self::$session->set('privateKey', $privateKey);
- self::$session->set('initStatus', true);
-
- return self::$session;
+ $this->session->setPrivateKey($privateKey);
+ $this->session->setStatus(Session::INIT_SUCCESSFUL);
}
/**
$encryptedFileKey = $this->keyStorage->getFileKey($path,
$this->fileKeyId);
$shareKey = $this->getShareKey($path, $uid);
- $privateKey = self::$session->get('privateKey');
+ $privateKey = $this->session->getPrivateKey();
if ($encryptedFileKey && $shareKey && $privateKey) {
$key = $this->crypt->multiKeyDecrypt($encryptedFileKey,
public function setPassphrase($params, IUserSession $user, Util $util) {
// Get existing decrypted private key
- $privateKey = self::$session->get('privateKey');
+ $privateKey = $this->session->getPrivateKey();
if ($params['uid'] === $user->getUser()->getUID() && $privateKey) {
--- /dev/null
+<?php
+
+/**
+ * ownCloud
+ *
+ * @copyright (C) 2015 ownCloud, Inc.
+ *
+ * @author Bjoern Schiessle <schiessle@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\Encryption;
+
+use \OCP\ISession;
+
+class Session {
+
+ /** @var ISession */
+ protected $session;
+
+ const NOT_INITIALIZED = '0';
+ const INIT_EXECUTED = '1';
+ const INIT_SUCCESSFUL = '2';
+
+ public function __construct(ISession $session) {
+ $this->session = $session;
+ }
+
+ /**
+ * Sets status of encryption app
+ *
+ * @param string $status INIT_SUCCESSFUL, INIT_EXECUTED, NOT_INITIALIZED
+ */
+ public function setStatus($status) {
+ $this->session->set('encryptionInitialized', $status);
+ }
+
+ /**
+ * Gets status if we already tried to initialize the encryption app
+ *
+ * @return string init status INIT_SUCCESSFUL, INIT_EXECUTED, NOT_INITIALIZED
+ */
+ public function getStatus() {
+ $status = $this->session->get('encryptionInitialized');
+ if (is_null($status)) {
+ $status = self::NOT_INITIALIZED;
+ }
+
+ return $status;
+ }
+
+ /**
+ * Gets user or public share private key from session
+ *
+ * @return string $privateKey The user's plaintext private key
+ * @throws Exceptions\PrivateKeyMissingException
+ */
+ public function getPrivateKey() {
+ $key = $this->session->get('privateKey');
+ if (is_null($key)) {
+ throw new Exceptions\PrivateKeyMissingException('no private key stored in session');
+ }
+ return $key;
+ }
+
+ /**
+ * check if private key is set
+ *
+ * @return boolean
+ */
+ public function isPrivateKeySet() {
+ $key = $this->session->get('privateKey');
+ if (is_null($key)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Sets user private key to session
+ *
+ * @param string $key users private key
+ *
+ * @note this should only be set on login
+ */
+ public function setPrivateKey($key) {
+ $this->session->set('privateKey', $key);
+ }
+
+}
\ No newline at end of file
// Add CSS stylesheet
\OC_Util::addStyle('encryption', 'settings-personal');
+$session = new \OCA\Encryption\Session(\OC::$server->getSession());
+
$tmpl = new OCP\Template('encryption', 'settings-personal');
$crypt = new \OCA\Encryption\Crypto\Crypt(
\OC::$server->getLogger(),
$crypt,
\OC::$server->getConfig(),
\OC::$server->getUserSession(),
- \OC::$server->getSession(),
- \OC::$server->getLogger(),);
+ $session,
+ \OC::$server->getLogger());
$user = \OCP\User::getUser();
$util = new \OCA\Encryption\Util(
new \OC\Files\View(), $crypt, $keymanager, \OC::$server->getLogger(), \OC::$server->getUserSession(), \OC::$server->getConfig());
-$session = \OC::$server->getSession();
-
-$privateKeySet = $session->get('privateKey') !== false;
+$privateKeySet = $session->isPrivateKeySet();
// did we tried to initialize the keys for this session?
-$initialized = $session->getInitialized();
+$initialized = $session->getStatus();
$recoveryAdminEnabled = \OC::$server->getConfig()->getAppValue('encryption', 'recoveryAdminEnabled');
$recoveryEnabledForUser = $util->recoveryEnabledForUser();
+++ /dev/null
-<?php
- /**
- * @author Clark Tomlinson <clark@owncloud.com>
- * @since 2/25/15, 9:39 AM
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-
-namespace OC\Encryption\Exceptions;
-
-
-class PrivateKeyMissingException extends GenericEncryptionException{
-
-}