|
|
|
|
@ -55,6 +55,7 @@ class Stream {
|
|
|
|
|
private $rawPath; // The raw path relative to the data dir
|
|
|
|
|
private $relPath; // rel path to users file dir
|
|
|
|
|
private $userId;
|
|
|
|
|
private $keyId;
|
|
|
|
|
private $handle; // Resource returned by fopen
|
|
|
|
|
private $meta = array(); // Header / meta for source stream
|
|
|
|
|
private $writeCache;
|
|
|
|
|
@ -90,20 +91,21 @@ class Stream {
|
|
|
|
|
$this->rootView = new \OC_FilesystemView('/');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// rawPath is relative to the data directory
|
|
|
|
|
$this->rawPath = \OC\Files\Filesystem::normalizePath(str_replace('crypt://', '', $path));
|
|
|
|
|
|
|
|
|
|
$this->session = new \OCA\Encryption\Session($this->rootView);
|
|
|
|
|
|
|
|
|
|
$this->privateKey = $this->session->getPrivateKey();
|
|
|
|
|
|
|
|
|
|
$userId = Helper::getUser($this->rawPath);
|
|
|
|
|
// rawPath is relative to the data directory
|
|
|
|
|
$this->rawPath = \OC\Files\Filesystem::normalizePath(str_replace('crypt://', '', $path));
|
|
|
|
|
|
|
|
|
|
$this->userId = Helper::getUser($this->rawPath);
|
|
|
|
|
|
|
|
|
|
$util = new Util($this->rootView, $userId);
|
|
|
|
|
$util = new Util($this->rootView, $this->userId);
|
|
|
|
|
|
|
|
|
|
// need to get the userId once more from util, because now this can be the
|
|
|
|
|
// public share key ID
|
|
|
|
|
$this->userId = $util->getUserId();
|
|
|
|
|
// get the key ID which we want to use, canm be the users key or the
|
|
|
|
|
// public share key
|
|
|
|
|
$this->keyId = $util->getKeyId();
|
|
|
|
|
|
|
|
|
|
// Strip identifier text from path, this gives us the path relative to data/<user>/files
|
|
|
|
|
$this->relPath = Helper::stripUserFilesPath($this->rawPath);
|
|
|
|
|
@ -254,14 +256,13 @@ class Stream {
|
|
|
|
|
|
|
|
|
|
// Fetch and decrypt keyfile
|
|
|
|
|
// Fetch existing keyfile
|
|
|
|
|
$userId = Helper::getUser($this->rawPath);
|
|
|
|
|
$util = new \OCA\Encryption\Util($this->rootView, $userId);
|
|
|
|
|
$util = new \OCA\Encryption\Util($this->rootView, $this->userId);
|
|
|
|
|
$this->encKeyfile = Keymanager::getFileKey($this->rootView, $util, $this->relPath);
|
|
|
|
|
|
|
|
|
|
// If a keyfile already exists
|
|
|
|
|
if ($this->encKeyfile) {
|
|
|
|
|
|
|
|
|
|
$shareKey = Keymanager::getShareKey($this->rootView, $this->userId, $util, $this->relPath);
|
|
|
|
|
$shareKey = Keymanager::getShareKey($this->rootView, $this->keyId, $util, $this->relPath);
|
|
|
|
|
|
|
|
|
|
// if there is no valid private key return false
|
|
|
|
|
if ($this->privateKey === false) {
|
|
|
|
|
@ -508,17 +509,15 @@ class Stream {
|
|
|
|
|
\OC_FileProxy::$enabled = false;
|
|
|
|
|
|
|
|
|
|
// Fetch user's public key
|
|
|
|
|
$this->publicKey = Keymanager::getPublicKey($this->rootView, $this->userId);
|
|
|
|
|
$this->publicKey = Keymanager::getPublicKey($this->rootView, $this->keyId);
|
|
|
|
|
|
|
|
|
|
// Check if OC sharing api is enabled
|
|
|
|
|
$sharingEnabled = \OCP\Share::isEnabled();
|
|
|
|
|
|
|
|
|
|
$userId = Helper::getUser($this->rawPath);
|
|
|
|
|
|
|
|
|
|
$util = new Util($this->rootView, $userId);
|
|
|
|
|
$util = new Util($this->rootView, $this->userId);
|
|
|
|
|
|
|
|
|
|
// Get all users sharing the file includes current user
|
|
|
|
|
$uniqueUserIds = $util->getSharingUsersArray($sharingEnabled, $this->relPath, $userId);
|
|
|
|
|
$uniqueUserIds = $util->getSharingUsersArray($sharingEnabled, $this->relPath, $this->userId);
|
|
|
|
|
$checkedUserIds = $util->filterShareReadyUsers($uniqueUserIds);
|
|
|
|
|
|
|
|
|
|
// Fetch public keys for all sharing users
|
|
|
|
|
@ -528,7 +527,7 @@ class Stream {
|
|
|
|
|
$this->encKeyfiles = Crypt::multiKeyEncrypt($this->plainKey, $publicKeys);
|
|
|
|
|
|
|
|
|
|
// Save the new encrypted file key
|
|
|
|
|
Keymanager::setFileKey($this->rootView, $util, $this->relPath, $userId, $this->encKeyfiles['data']);
|
|
|
|
|
Keymanager::setFileKey($this->rootView, $util, $this->relPath, $this->keyId, $this->encKeyfiles['data']);
|
|
|
|
|
|
|
|
|
|
// Save the sharekeys
|
|
|
|
|
Keymanager::setShareKeys($this->rootView, $util, $this->relPath, $this->encKeyfiles['keys']);
|
|
|
|
|
|