summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2013-09-04 21:15:06 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2013-09-06 16:06:34 +0200
commit93f4dec79896cca250efc3eadbed073e4698c72c (patch)
treeac8eaa252c53479214748a6ebedb4538a5aebc6d /apps/files_encryption
parentf6830e7462888f67549a8275826e1a14c0339711 (diff)
downloadnextcloud-server-93f4dec79896cca250efc3eadbed073e4698c72c.tar.gz
nextcloud-server-93f4dec79896cca250efc3eadbed073e4698c72c.zip
fix part file handling and real size calculation, this should also solve #4581
Conflicts: apps/files_encryption/lib/stream.php
Diffstat (limited to 'apps/files_encryption')
-rwxr-xr-xapps/files_encryption/lib/keymanager.php28
-rw-r--r--apps/files_encryption/lib/stream.php36
-rw-r--r--apps/files_encryption/lib/util.php5
3 files changed, 24 insertions, 45 deletions
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php
index 5386de486e1..9be3dda7ce3 100755
--- a/apps/files_encryption/lib/keymanager.php
+++ b/apps/files_encryption/lib/keymanager.php
@@ -220,22 +220,10 @@ class Keymanager {
*/
public static function getFileKey(\OC_FilesystemView $view, $userId, $filePath) {
- // try reusing key file if part file
- if (self::isPartialFilePath($filePath)) {
-
- $result = self::getFileKey($view, $userId, self::fixPartialFilePath($filePath));
-
- if ($result) {
-
- return $result;
-
- }
-
- }
-
$util = new Util($view, \OCP\User::getUser());
list($owner, $filename) = $util->getUidAndFilename($filePath);
+ $filename = self::fixPartialFilePath($filename);
$filePath_f = ltrim($filename, '/');
// in case of system wide mount points the keys are stored directly in the data directory
@@ -424,18 +412,6 @@ class Keymanager {
public static function getShareKey(\OC_FilesystemView $view, $userId, $filePath) {
// try reusing key file if part file
- if (self::isPartialFilePath($filePath)) {
-
- $result = self::getShareKey($view, $userId, self::fixPartialFilePath($filePath));
-
- if ($result) {
-
- return $result;
-
- }
-
- }
-
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
@@ -443,7 +419,7 @@ class Keymanager {
$util = new Util($view, \OCP\User::getUser());
list($owner, $filename) = $util->getUidAndFilename($filePath);
-
+ $filename = self::fixPartialFilePath($filename);
// in case of system wide mount points the keys are stored directly in the data directory
if ($util->isSystemWideMountPoint($filename)) {
$shareKeyPath = '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey';
diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php
index 335ea3733eb..083b33c03cb 100644
--- a/apps/files_encryption/lib/stream.php
+++ b/apps/files_encryption/lib/stream.php
@@ -81,7 +81,7 @@ class Stream {
* @return bool
*/
public function stream_open($path, $mode, $options, &$opened_path) {
-
+
// assume that the file already exist before we decide it finally in getKey()
$this->newFile = false;
@@ -106,12 +106,12 @@ class Stream {
if ($this->relPath === false) {
$this->relPath = Helper::getPathToRealFile($this->rawPath);
}
-
+
if($this->relPath === false) {
\OCP\Util::writeLog('Encryption library', 'failed to open file "' . $this->rawPath . '" expecting a path to user/files or to user/files_versions', \OCP\Util::ERROR);
return false;
}
-
+
// Disable fileproxies so we can get the file size and open the source file without recursive encryption
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
@@ -188,7 +188,7 @@ class Stream {
}
// Get the data from the file handle
- $data = fread($this->handle, 8192);
+ $data = fread($this->handle, $count);
$result = null;
@@ -272,7 +272,7 @@ class Stream {
} else {
$this->newFile = true;
-
+
return false;
}
@@ -296,9 +296,9 @@ class Stream {
return strlen($data);
}
- // Disable the file proxies so that encryption is not
- // automatically attempted when the file is written to disk -
- // we are handling that separately here and we don't want to
+ // Disable the file proxies so that encryption is not
+ // automatically attempted when the file is written to disk -
+ // we are handling that separately here and we don't want to
// get into an infinite loop
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
@@ -311,7 +311,7 @@ class Stream {
$pointer = ftell($this->handle);
// Get / generate the keyfile for the file we're handling
- // If we're writing a new file (not overwriting an existing
+ // If we're writing a new file (not overwriting an existing
// one), save the newly generated keyfile
if (!$this->getKey()) {
@@ -319,7 +319,7 @@ class Stream {
}
- // If extra data is left over from the last round, make sure it
+ // If extra data is left over from the last round, make sure it
// is integrated into the next 6126 / 8192 block
if ($this->writeCache) {
@@ -344,12 +344,12 @@ class Stream {
if ($remainingLength < 6126) {
// Set writeCache to contents of $data
- // The writeCache will be carried over to the
- // next write round, and added to the start of
- // $data to ensure that written blocks are
- // always the correct length. If there is still
- // data in writeCache after the writing round
- // has finished, then the data will be written
+ // The writeCache will be carried over to the
+ // next write round, and added to the start of
+ // $data to ensure that written blocks are
+ // always the correct length. If there is still
+ // data in writeCache after the writing round
+ // has finished, then the data will be written
// to disk by $this->flush().
$this->writeCache = $data;
@@ -363,7 +363,7 @@ class Stream {
$encrypted = $this->preWriteEncrypt($chunk, $this->plainKey);
- // Write the data chunk to disk. This will be
+ // Write the data chunk to disk. This will be
// attended to the last data chunk if the file
// being handled totals more than 6126 bytes
fwrite($this->handle, $encrypted);
@@ -488,6 +488,7 @@ class Stream {
$this->meta['mode'] !== 'rb' &&
$this->size > 0
) {
+
// only write keyfiles if it was a new file
if ($this->newFile === true) {
@@ -535,6 +536,7 @@ class Stream {
// set fileinfo
$this->rootView->putFileInfo($this->rawPath, $fileInfo);
+
}
return fclose($this->handle);
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 3922f7d9d7f..5d7858569f3 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -508,10 +508,11 @@ class Util {
// get the size from filesystem
$fullPath = $this->view->getLocalFile($path);
- $size = filesize($fullPath);
+ $size = $this->view->filesize($path);
// calculate last chunk nr
$lastChunkNr = floor($size / 8192);
+ $lastChunkSize = $size - ($lastChunkNr * 8192);
// open stream
$stream = fopen('crypt://' . $path, "r");
@@ -524,7 +525,7 @@ class Util {
fseek($stream, $lastChunckPos);
// get the content of the last chunk
- $lastChunkContent = fread($stream, 8192);
+ $lastChunkContent = fread($stream, $lastChunkSize);
// calc the real file size with the size of the last chunk
$realSize = (($lastChunkNr * 6126) + strlen($lastChunkContent));