diff --git a/apps/encryption/appinfo/encryption.php b/apps/encryption/appinfo/encryption.php index 8be3cae5ad..d57f1b0b7b 100644 --- a/apps/encryption/appinfo/encryption.php +++ b/apps/encryption/appinfo/encryption.php @@ -125,6 +125,7 @@ class Encryption extends \OCP\AppFramework\App { $c->query('Crypt'), $server->getConfig(), $server->getUserSession(), + $server->getSession(), $server->getMemCacheFactory(), $server->getLogger() ); diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php index 516d7b1304..43d3b84268 100644 --- a/apps/encryption/lib/crypto/encryption.php +++ b/apps/encryption/lib/crypto/encryption.php @@ -95,7 +95,7 @@ class Encryption implements IEncryptionModule { $this->writeCache = ''; $this->isWriteOperation = false; - $this->fileKey = $this->keymanager->getFileKey($path); + $this->fileKey = $this->keymanager->getFileKey($path, $this->user); return array('cipher' => $this->cipher); } diff --git a/apps/encryption/lib/keymanager.php b/apps/encryption/lib/keymanager.php index 59f904ecf1..4b898217d6 100644 --- a/apps/encryption/lib/keymanager.php +++ b/apps/encryption/lib/keymanager.php @@ -32,6 +32,7 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\ILogger; use OCP\IUserSession; +use \OCP\ISession; class KeyManager { @@ -86,16 +87,24 @@ class KeyManager { */ private $log; + /** + * @var \OCP\ISession + */ + private $session; + /** * @param IStorage $keyStorage * @param Crypt $crypt * @param IConfig $config - * @param IUserSession $userSession + * @param Session $userSession + * @param \OCP\ISession $session * @param ICacheFactory $cacheFactory * @param ILogger $log */ - public function __construct(IStorage $keyStorage, Crypt $crypt, IConfig $config, IUserSession $userSession, ICacheFactory $cacheFactory, ILogger $log) { + public function __construct(IStorage $keyStorage, Crypt $crypt, IConfig $config, + IUserSession $userSession, ISession $session ,ICacheFactory $cacheFactory, ILogger $log) { + $this->session = $session; $this->keyStorage = $keyStorage; $this->crypt = $crypt; $this->config = $config; @@ -215,6 +224,9 @@ class KeyManager { return false; } + + $this->session->set('privateKey', $privateKey); + $this->session->set('initStatus', true); self::$cacheFactory->set('privateKey', $privateKey); self::$cacheFactory->set('initStatus', true); @@ -239,18 +251,30 @@ class KeyManager { /** * @param $path - * @return mixed + * @param $uid + * @return string */ - public function getFileKey($path) { - return $this->keyStorage->getFileKey($path, $this->fileKeyId); + public function getFileKey($path, $uid) { + $key = ''; + $encryptedFileKey = $this->keyStorage->getFileKey($path, $this->fileKeyId); + $shareKey = $this->getShareKey($path, $uid); + $privateKey = $this->session->get('privateKey'); + + if ($encryptedFileKey && $shareKey && $privateKey) { + $key = $this->crypt->multiKeyDecrypt($encryptedFileKey, $shareKey, $privateKey); + } + + return $key; } /** * @param $path + * @param $uid * @return mixed */ - public function getShareKey($path) { - return $this->keyStorage->getFileKey($path, $this->keyId . $this->shareKeyId); + public function getShareKey($path, $uid) { + $keyId = $uid . '.' . $this->shareKeyId; + return $this->keyStorage->getFileKey($path, $keyId); } /**