diff options
author | Clark Tomlinson <fallen013@gmail.com> | 2015-03-24 17:29:10 -0400 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-07 13:30:27 +0200 |
commit | 0c2f9ca849ef41232511cf576cc9a9de2caa43f0 (patch) | |
tree | a75194b573985da4a68684cb5a74c9891db34696 /apps/encryption/lib/recovery.php | |
parent | 506222567e71fc0d77fa77ee7805c93fa7655b6c (diff) | |
download | nextcloud-server-0c2f9ca849ef41232511cf576cc9a9de2caa43f0.tar.gz nextcloud-server-0c2f9ca849ef41232511cf576cc9a9de2caa43f0.zip |
Updating keystorage movement and fixing hooks
Diffstat (limited to 'apps/encryption/lib/recovery.php')
-rw-r--r-- | apps/encryption/lib/recovery.php | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/apps/encryption/lib/recovery.php b/apps/encryption/lib/recovery.php index 88350e96c53..457184b4b96 100644 --- a/apps/encryption/lib/recovery.php +++ b/apps/encryption/lib/recovery.php @@ -22,11 +22,12 @@ namespace OCA\Encryption; -use OC\Files\View; use OCA\Encryption\Crypto\Crypt; -use OCP\Encryption\IKeyStorage; +use OCP\Encryption\Keys\IStorage; use OCP\IConfig; use OCP\IUser; +use OCP\IUserSession; +use OCP\PreConditionNotMetException; use OCP\Security\ISecureRandom; class Recovery { @@ -58,20 +59,20 @@ class Recovery { private $keyStorage; /** - * @param IUser $user + * @param IUserSession $user * @param Crypt $crypt * @param ISecureRandom $random * @param KeyManager $keyManager * @param IConfig $config - * @param IKeyStorage $keyStorage + * @param IStorage $keyStorage */ - public function __construct(IUser $user, + public function __construct(IUserSession $user, Crypt $crypt, ISecureRandom $random, KeyManager $keyManager, IConfig $config, - IKeyStorage $keyStorage) { - $this->user = $user; + IStorage $keyStorage) { + $this->user = $user && $user->isLoggedIn() ? $user->getUser() : false; $this->crypt = $crypt; $this->random = $random; $this->keyManager = $keyManager; @@ -97,7 +98,7 @@ class Recovery { if (!$keyManager->recoveryKeyExists()) { $keyPair = $this->crypt->createKeyPair(); - return $this->keyManager->storeKeyPair($password, $keyPair); + return $this->keyManager->storeKeyPair($this->user->getUID(), $password, $keyPair); } if ($keyManager->checkRecoveryPassword($password)) { @@ -131,4 +132,45 @@ class Recovery { // No idea new way to do this.... } + /** + * @return bool + */ + public function recoveryEnabledForUser() { + $recoveryMode = $this->config->getUserValue($this->user->getUID(), + 'encryption', + 'recoveryEnabled', + 0); + + return ($recoveryMode === '1'); + } + /** + * @param $enabled + * @return bool + */ + public function setRecoveryForUser($enabled) { + $value = $enabled ? '1' : '0'; + + try { + $this->config->setUserValue($this->user->getUID(), + 'encryption', + 'recoveryEnabled', + $value); + return true; + } catch (PreConditionNotMetException $e) { + return false; + } + } + + /** + * @param $recoveryPassword + */ + public function recoverUsersFiles($recoveryPassword) { + // todo: get system private key here +// $this->keyManager->get + $privateKey = $this->crypt->decryptPrivateKey($encryptedKey, + $recoveryPassword); + + $this->recoverAllFiles('/', $privateKey); + } + } |