read encrypted files

This commit is contained in:
Bjoern Schiessle 2015-03-26 14:13:39 +01:00 committed by Thomas Müller
parent 2244ea998d
commit 2e00acda07
3 changed files with 33 additions and 8 deletions

View File

@ -125,6 +125,7 @@ class Encryption extends \OCP\AppFramework\App {
$c->query('Crypt'),
$server->getConfig(),
$server->getUserSession(),
$server->getSession(),
$server->getMemCacheFactory(),
$server->getLogger()
);

View File

@ -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);
}

View File

@ -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);
}
/**