From 6aa9daf4e6bec5c2c15b896f99b07ce9ebe310cf Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 14 Nov 2013 08:48:06 +0100 Subject: [PATCH 1/3] Users of getFolderContent are mostly interested in the unecrypted file size --- lib/private/files/cache/cache.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index ac50a988e3..8e682a96b7 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -178,6 +178,10 @@ class Cache { if ($file['storage_mtime'] == 0) { $file['storage_mtime'] = $file['mtime']; } + if ($file['encrypted']) { + $file['encrypted_size'] = $file['size']; + $file['size'] = $file['unencrypted_size']; + } } return $files; } else { From 40f148cc6cb42ac24c04cff6dd4472d94cc1f097 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 14 Nov 2013 08:44:14 +0100 Subject: [PATCH 2/3] Don't try to encrypt a file when the temp file isn't created --- apps/files_encryption/lib/util.php | 39 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 2ada62354c..7f09a1f1f0 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -840,32 +840,35 @@ class Util { // Open enc file handle for binary writing, with same filename as original plain file $encHandle = fopen('crypt://' . $rawPath . '.part', 'wb'); - // Move plain file to a temporary location - $size = stream_copy_to_stream($plainHandle, $encHandle); + if (is_resource($encHandle)) { + // Move plain file to a temporary location + $size = stream_copy_to_stream($plainHandle, $encHandle); - fclose($encHandle); - fclose($plainHandle); + fclose($encHandle); + fclose($plainHandle); - $fakeRoot = $this->view->getRoot(); - $this->view->chroot('/' . $this->userId . '/files'); + $fakeRoot = $this->view->getRoot(); + $this->view->chroot('/' . $this->userId . '/files'); - $this->view->rename($relPath . '.part', $relPath); + $this->view->rename($relPath . '.part', $relPath); - // set timestamp - $this->view->touch($relPath, $timestamp); + // set timestamp + $this->view->touch($relPath, $timestamp); - $this->view->chroot($fakeRoot); + $encSize = $this->view->filesize($relPath); - // Add the file to the cache - \OC\Files\Filesystem::putFileInfo($relPath, array( - 'encrypted' => true, - 'size' => $size, - 'unencrypted_size' => $size, - 'etag' => $fileInfo['etag'] - )); + $this->view->chroot($fakeRoot); - $encryptedFiles[] = $relPath; + // Add the file to the cache + \OC\Files\Filesystem::putFileInfo($relPath, array( + 'encrypted' => true, + 'size' => $encSize, + 'unencrypted_size' => $size, + 'etag' => $fileInfo['etag'] + )); + $encryptedFiles[] = $relPath; + } } // Encrypt legacy encrypted files From 4c8bc61753dd26db1a239f8a6743c662d0d83dd4 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 14 Nov 2013 08:46:15 +0100 Subject: [PATCH 3/3] XSendfile and encryption don't work together The file on disk is encrypted, and not readable on client systems --- lib/private/files.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/private/files.php b/lib/private/files.php index 8b8ff81ec5..6ffa14c0d9 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -109,6 +109,9 @@ class OC_Files { $zip = false; $filename = $dir . '/' . $files; $name = $files; + if ($xsendfile && OC_App::isEnabled('files_encryption')) { + $xsendfile = false; + } } OC_Util::obEnd(); if ($zip or \OC\Files\Filesystem::isReadable($filename)) {