From cf3a8f274f05170b69cb3872d0d8c9045a5876d3 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Tue, 5 Jan 2016 15:29:44 +0100 Subject: make it backward compatible to work with signed and un-signed files --- lib/private/files/storage/wrapper/encryption.php | 6 ++++-- lib/private/files/stream/encryption.php | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'lib/private/files') diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index f358bd59239..96d642e7780 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -343,6 +343,7 @@ class Encryption extends Wrapper { $shouldEncrypt = false; $encryptionModule = null; $header = $this->getHeader($path); + $signed = (isset($header['signed']) && $header['signed'] === 'true') ? true : false; $fullPath = $this->getFullPath($path); $encryptionModuleId = $this->util->getEncryptionModuleId($header); @@ -377,7 +378,7 @@ class Encryption extends Wrapper { || $mode === 'wb' || $mode === 'wb+' ) { - // don't overwrite encrypted files if encyption is not enabled + // don't overwrite encrypted files if encryption is not enabled if ($targetIsEncrypted && $encryptionEnabled === false) { throw new GenericEncryptionException('Tried to access encrypted file but encryption is not enabled'); } @@ -385,6 +386,7 @@ class Encryption extends Wrapper { // if $encryptionModuleId is empty, the default module will be used $encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId); $shouldEncrypt = $encryptionModule->shouldEncrypt($fullPath); + $signed = true; } } else { $info = $this->getCache()->get($path); @@ -422,7 +424,7 @@ class Encryption extends Wrapper { } $handle = \OC\Files\Stream\Encryption::wrap($source, $path, $fullPath, $header, $this->uid, $encryptionModule, $this->storage, $this, $this->util, $this->fileHelper, $mode, - $size, $unencryptedSize, $headerSize); + $size, $unencryptedSize, $headerSize, $signed); return $handle; } diff --git a/lib/private/files/stream/encryption.php b/lib/private/files/stream/encryption.php index c884cd8fa07..11e2b218d17 100644 --- a/lib/private/files/stream/encryption.php +++ b/lib/private/files/stream/encryption.php @@ -110,7 +110,8 @@ class Encryption extends Wrapper { 'size', 'unencryptedSize', 'encryptionStorage', - 'headerSize' + 'headerSize', + 'signed' ); } @@ -132,6 +133,7 @@ class Encryption extends Wrapper { * @param int $size * @param int $unencryptedSize * @param int $headerSize + * @param bool $signed * @param string $wrapper stream wrapper class * @return resource * @@ -148,6 +150,7 @@ class Encryption extends Wrapper { $size, $unencryptedSize, $headerSize, + $signed, $wrapper = 'OC\Files\Stream\Encryption') { $context = stream_context_create(array( @@ -164,7 +167,8 @@ class Encryption extends Wrapper { 'size' => $size, 'unencryptedSize' => $unencryptedSize, 'encryptionStorage' => $encStorage, - 'headerSize' => $headerSize + 'headerSize' => $headerSize, + 'signed' => $signed ) )); @@ -225,7 +229,7 @@ class Encryption extends Wrapper { $this->position = 0; $this->cache = ''; $this->writeFlag = false; - $this->unencryptedBlockSize = $this->encryptionModule->getUnencryptedBlockSize(); + $this->unencryptedBlockSize = $this->encryptionModule->getUnencryptedBlockSize($this->signed); if ( $mode === 'w' -- cgit v1.2.3 From 9bb97c714bb2158fd019ba9efc24a8bc8595b499 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Tue, 5 Jan 2016 19:01:03 +0100 Subject: fixing unit tests --- apps/encryption/lib/crypto/crypt.php | 2 +- apps/encryption/tests/lib/crypto/cryptTest.php | 63 ++++++++++++++++++---- .../encryption/tests/lib/crypto/encryptionTest.php | 2 +- lib/private/files/stream/encryption.php | 3 ++ tests/lib/files/stream/encryption.php | 1 + 5 files changed, 60 insertions(+), 11 deletions(-) (limited to 'lib/private/files') diff --git a/apps/encryption/lib/crypto/crypt.php b/apps/encryption/lib/crypto/crypt.php index d5a41c29009..f27f55619af 100644 --- a/apps/encryption/lib/crypto/crypt.php +++ b/apps/encryption/lib/crypto/crypt.php @@ -442,7 +442,7 @@ class Crypt { $catFile = $this->splitMetaData($keyFileContents, $cipher); - if ($catFile['signature']) { + if ($catFile['signature'] !== false) { $this->checkSignature($catFile['encrypted'], $passPhrase, $catFile['signature']); } diff --git a/apps/encryption/tests/lib/crypto/cryptTest.php b/apps/encryption/tests/lib/crypto/cryptTest.php index c774da1836c..d94aea463cf 100644 --- a/apps/encryption/tests/lib/crypto/cryptTest.php +++ b/apps/encryption/tests/lib/crypto/cryptTest.php @@ -204,17 +204,61 @@ class cryptTest extends TestCase { } /** - * test splitIV() + * @dataProvider dataTestSplitMetaData */ - public function testSplitIV() { - $data = 'encryptedContent00iv001234567890123456'; - $result = self::invokePrivate($this->crypt, 'splitIV', array($data)); + public function testSplitMetaData($data, $expected) { + $result = self::invokePrivate($this->crypt, 'splitMetaData', array($data, 'AES-256-CFB')); $this->assertTrue(is_array($result)); - $this->assertSame(2, count($result)); + $this->assertSame(3, count($result)); $this->assertArrayHasKey('encrypted', $result); $this->assertArrayHasKey('iv', $result); - $this->assertSame('encryptedContent', $result['encrypted']); - $this->assertSame('1234567890123456', $result['iv']); + $this->assertArrayHasKey('signature', $result); + $this->assertSame($expected['encrypted'], $result['encrypted']); + $this->assertSame($expected['iv'], $result['iv']); + $this->assertSame($expected['signature'], $result['signature']); + } + + public function dataTestSplitMetaData() { + return [ + ['encryptedContent00iv001234567890123456xx', + ['encrypted' => 'encryptedContent', 'iv' => '1234567890123456', 'signature' => false]], + ['encryptedContent00iv00123456789012345600sig00e1992521e437f6915f9173b190a512cfc38a00ac24502db44e0ba10c2bb0cc86xxx', + ['encrypted' => 'encryptedContent', 'iv' => '1234567890123456', 'signature' => 'e1992521e437f6915f9173b190a512cfc38a00ac24502db44e0ba10c2bb0cc86']], + ]; + } + + /** + * @dataProvider dataTestHasSignature + */ + public function testHasSignature($data, $expected) { + $this->assertSame($expected, + $this->invokePrivate($this->crypt, 'hasSignature', array($data, 'AES-256-CFB')) + ); + } + + public function dataTestHasSignature() { + return [ + ['encryptedContent00iv001234567890123456xx', false], + ['encryptedContent00iv00123456789012345600sig00e1992521e437f6915f9173b190a512cfc38a00ac24502db44e0ba10c2bb0cc86xxx', true] + ]; + } + + /** + * @dataProvider dataTestHasSignatureFail + * @expectedException \OC\HintException + */ + public function testHasSignatureFail($cipher) { + $data = 'encryptedContent00iv001234567890123456xx'; + $this->invokePrivate($this->crypt, 'hasSignature', array($data, $cipher)); + } + + public function dataTestHasSignatureFail() { + return [ + ['AES-256-CTR'], + ['aes-256-ctr'], + ['AES-128-CTR'], + ['ctr-256-ctr'] + ]; } /** @@ -222,7 +266,7 @@ class cryptTest extends TestCase { */ public function testAddPadding() { $result = self::invokePrivate($this->crypt, 'addPadding', array('data')); - $this->assertSame('dataxx', $result); + $this->assertSame('dataxxx', $result); } /** @@ -348,7 +392,8 @@ class cryptTest extends TestCase { [ $this->logger, $this->userSession, - $this->config + $this->config, + $this->l ] ) ->setMethods( diff --git a/apps/encryption/tests/lib/crypto/encryptionTest.php b/apps/encryption/tests/lib/crypto/encryptionTest.php index 62e77c742d8..ad943ab6e49 100644 --- a/apps/encryption/tests/lib/crypto/encryptionTest.php +++ b/apps/encryption/tests/lib/crypto/encryptionTest.php @@ -229,7 +229,7 @@ class EncryptionTest extends TestCase { public function dataTestBegin() { return array( - array('w', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'fileKey', 'myCipher'), + array('w', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'fileKey', 'defaultCipher'), array('r', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'fileKey', 'myCipher'), array('w', [], 'legacyCipher', 'defaultCipher', '', 'defaultCipher'), array('r', [], 'legacyCipher', 'defaultCipher', 'file_key', 'legacyCipher'), diff --git a/lib/private/files/stream/encryption.php b/lib/private/files/stream/encryption.php index 11e2b218d17..bc771a91ebd 100644 --- a/lib/private/files/stream/encryption.php +++ b/lib/private/files/stream/encryption.php @@ -72,6 +72,9 @@ class Encryption extends Wrapper { /** @var string */ protected $fullPath; + /** @var bool */ + protected $signed; + /** * header data returned by the encryption module, will be written to the file * in case of a write operation diff --git a/tests/lib/files/stream/encryption.php b/tests/lib/files/stream/encryption.php index f9d8f076b63..f67dd09bc4d 100644 --- a/tests/lib/files/stream/encryption.php +++ b/tests/lib/files/stream/encryption.php @@ -117,6 +117,7 @@ class Encryption extends \Test\TestCase { $header->setAccessible(true); $header->setValue($streamWrapper, array()); $header->setAccessible(false); + $this->invokePrivate($streamWrapper, 'signed', [true]); // call stream_open, that's the method we want to test $dummyVar = 'foo'; -- cgit v1.2.3 From 3badf5caf579f8ff10c9917f62cb41cd9b0c68f8 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Wed, 3 Feb 2016 14:32:04 +0100 Subject: Use number of chunk for HMAC as well Prevents switching single blocks within the encrypted file. --- apps/encryption/lib/crypto/crypt.php | 11 +++++++---- apps/encryption/lib/crypto/encryption.php | 19 +++++++++---------- lib/private/files/stream/encryption.php | 18 +++++++++++++----- 3 files changed, 29 insertions(+), 19 deletions(-) (limited to 'lib/private/files') diff --git a/apps/encryption/lib/crypto/crypt.php b/apps/encryption/lib/crypto/crypt.php index 6c3aee47a56..b4c10f42790 100644 --- a/apps/encryption/lib/crypto/crypt.php +++ b/apps/encryption/lib/crypto/crypt.php @@ -170,10 +170,11 @@ class Crypt { * @param string $plainContent * @param string $passPhrase * @param int $version + * @param int $position * @return false|string * @throws EncryptionFailedException */ - public function symmetricEncryptFileContent($plainContent, $passPhrase, $version) { + public function symmetricEncryptFileContent($plainContent, $passPhrase, $version, $position) { if (!$plainContent) { $this->logger->error('Encryption Library, symmetrical encryption failed no content given', @@ -189,7 +190,7 @@ class Crypt { $this->getCipher()); // Create a signature based on the key as well as the current version - $sig = $this->createSignature($encryptedContent, $passPhrase.$version); + $sig = $this->createSignature($encryptedContent, $passPhrase.$version.$position); // combine content to encrypt the IV identifier and actual IV $catFile = $this->concatIV($encryptedContent, $iv); @@ -368,6 +369,7 @@ class Crypt { $encryptedKey = $this->symmetricEncryptFileContent( $privateKey, $hash, + 0, 0 ); @@ -444,14 +446,15 @@ class Crypt { * @param string $passPhrase * @param string $cipher * @param int $version + * @param int $position * @return string * @throws DecryptionFailedException */ - public function symmetricDecryptFileContent($keyFileContents, $passPhrase, $cipher = self::DEFAULT_CIPHER, $version = 0) { + public function symmetricDecryptFileContent($keyFileContents, $passPhrase, $cipher = self::DEFAULT_CIPHER, $version = 0, $position = 0) { $catFile = $this->splitMetaData($keyFileContents, $cipher); if ($catFile['signature'] !== false) { - $this->checkSignature($catFile['encrypted'], $passPhrase.$version, $catFile['signature']); + $this->checkSignature($catFile['encrypted'], $passPhrase.$version.$position, $catFile['signature']); } return $this->decrypt($catFile['encrypted'], diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php index 90c60b8e0d5..d4e8087c4b0 100644 --- a/apps/encryption/lib/crypto/encryption.php +++ b/apps/encryption/lib/crypto/encryption.php @@ -215,13 +215,14 @@ class Encryption implements IEncryptionModule { * buffer. * * @param string $path to the file + * @param int $position * @return string remained data which should be written to the file in case * of a write operation * @throws PublicKeyMissingException * @throws \Exception * @throws \OCA\Encryption\Exceptions\MultiKeyEncryptException */ - public function end($path) { + public function end($path, $position = 0) { $result = ''; if ($this->isWriteOperation) { // Partial files do not increase the version @@ -230,7 +231,7 @@ class Encryption implements IEncryptionModule { } $this->keyManager->setVersion($this->path, $this->version+1); if (!empty($this->writeCache)) { - $result = $this->crypt->symmetricEncryptFileContent($this->writeCache, $this->fileKey, $this->version+1); + $result = $this->crypt->symmetricEncryptFileContent($this->writeCache, $this->fileKey, $this->version+1, $position); $this->writeCache = ''; } $publicKeys = array(); @@ -264,9 +265,10 @@ class Encryption implements IEncryptionModule { * encrypt data * * @param string $data you want to encrypt + * @param int $position * @return string encrypted data */ - public function encrypt($data) { + public function encrypt($data, $position = 0) { // If extra data is left over from the last round, make sure it // is integrated into the next block if ($this->writeCache) { @@ -314,7 +316,7 @@ class Encryption implements IEncryptionModule { if(\OC\Files\Cache\Scanner::isPartialFile($this->path)) { $this->version = $this->version - 1; } - $encrypted .= $this->crypt->symmetricEncryptFileContent($chunk, $this->fileKey, $this->version+1); + $encrypted .= $this->crypt->symmetricEncryptFileContent($chunk, $this->fileKey, $this->version+1, $position); // Remove the chunk we just processed from // $data, leaving only unprocessed data in $data @@ -332,10 +334,11 @@ class Encryption implements IEncryptionModule { * decrypt data * * @param string $data you want to decrypt + * @param int $position * @return string decrypted data * @throws DecryptionFailedException */ - public function decrypt($data) { + public function decrypt($data, $position = 0) { if (empty($this->fileKey)) { $msg = 'Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.'; $hint = $this->l->t('Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.'); @@ -344,11 +347,7 @@ class Encryption implements IEncryptionModule { throw new DecryptionFailedException($msg, $hint); } - $result = ''; - if (!empty($data)) { - $result = $this->crypt->symmetricDecryptFileContent($data, $this->fileKey, $this->cipher, $this->version); - } - return $result; + return $this->crypt->symmetricDecryptFileContent($data, $this->fileKey, $this->cipher, $this->version, $position); } /** diff --git a/lib/private/files/stream/encryption.php b/lib/private/files/stream/encryption.php index bc771a91ebd..63949035b5a 100644 --- a/lib/private/files/stream/encryption.php +++ b/lib/private/files/stream/encryption.php @@ -399,8 +399,9 @@ class Encryption extends Wrapper { } public function stream_close() { - $this->flush(); - $remainingData = $this->encryptionModule->end($this->fullPath); + $this->flush('end'); + $position = (int)floor($this->position/$this->unencryptedBlockSize); + $remainingData = $this->encryptionModule->end($this->fullPath, $position . 'end'); if ($this->readOnly === false) { if(!empty($remainingData)) { parent::stream_write($remainingData); @@ -412,15 +413,17 @@ class Encryption extends Wrapper { /** * write block to file + * @param string $positionPrefix */ - protected function flush() { + protected function flush($positionPrefix = '') { // write to disk only when writeFlag was set to 1 if ($this->writeFlag) { // 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 - $encrypted = $this->encryptionModule->encrypt($this->cache); + $position = (int)floor($this->position/$this->unencryptedBlockSize); + $encrypted = $this->encryptionModule->encrypt($this->cache, $position . $positionPrefix); $bytesWritten = parent::stream_write($encrypted); $this->writeFlag = false; // Check whether the write concerns the last block @@ -447,7 +450,12 @@ class Encryption extends Wrapper { if ($this->cache === '' && !($this->position === $this->unencryptedSize && ($this->position % $this->unencryptedBlockSize) === 0)) { // Get the data from the file handle $data = parent::stream_read($this->util->getBlockSize()); - $this->cache = $this->encryptionModule->decrypt($data); + $position = (int)floor($this->position/$this->unencryptedBlockSize); + $numberOfChunks = (int)($this->unencryptedSize / $this->unencryptedBlockSize); + if($numberOfChunks === $position) { + $position .= 'end'; + } + $this->cache = $this->encryptionModule->decrypt($data, $position); } } -- cgit v1.2.3 From 5ccb9dfa7e35d78d61d7a973ee2a5fddfda7d766 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 8 Feb 2016 20:35:33 +0100 Subject: Use database for keeping track of the version --- apps/encryption/lib/crypto/encryption.php | 11 +++++++++-- apps/encryption/lib/keymanager.php | 25 +++++++++++++++++++++--- apps/files_versions/lib/storage.php | 10 +++++++++- lib/private/files/cache/cache.php | 9 +++++++-- lib/private/files/fileinfo.php | 9 +++++++++ lib/private/files/storage/wrapper/encryption.php | 3 ++- 6 files changed, 58 insertions(+), 9 deletions(-) (limited to 'lib/private/files') diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php index d4e8087c4b0..b640f9a7a03 100644 --- a/apps/encryption/lib/crypto/encryption.php +++ b/apps/encryption/lib/crypto/encryption.php @@ -55,6 +55,9 @@ class Encryption implements IEncryptionModule { /** @var string */ private $path; + /** @var string */ + private $realPath; + /** @var string */ private $user; @@ -167,6 +170,7 @@ class Encryption implements IEncryptionModule { */ public function begin($path, $user, $mode, array $header, array $accessList) { $this->path = $this->getPathToRealFile($path); + $this->realPath = $this->path; $this->accessList = $accessList; $this->user = $user; $this->isWriteOperation = false; @@ -182,7 +186,7 @@ class Encryption implements IEncryptionModule { $this->fileKey = $this->keyManager->getFileKey($this->path, $this->user); } - $this->version = (int)$this->keyManager->getVersion($this->path); + $this->version = (int)$this->keyManager->getVersion($this->realPath); if ( $mode === 'w' @@ -360,7 +364,10 @@ class Encryption implements IEncryptionModule { */ public function update($path, $uid, array $accessList) { $fileKey = $this->keyManager->getFileKey($path, $uid); - $version = $this->keyManager->getVersion($path); + if(empty($this->realPath)) { + $this->realPath = $path; + } + $version = $this->keyManager->getVersion($this->realPath); if (!empty($fileKey)) { diff --git a/apps/encryption/lib/keymanager.php b/apps/encryption/lib/keymanager.php index 4cbb377a43c..7d8bd8485e6 100644 --- a/apps/encryption/lib/keymanager.php +++ b/apps/encryption/lib/keymanager.php @@ -25,12 +25,14 @@ namespace OCA\Encryption; use OC\Encryption\Exceptions\DecryptionFailedException; +use OC\Files\View; use OCA\Encryption\Crypto\Encryption; use OCA\Encryption\Exceptions\PrivateKeyMissingException; use OCA\Encryption\Exceptions\PublicKeyMissingException; use OCA\Encryption\Crypto\Crypt; use OCP\Encryption\Keys\IStorage; use OCP\IConfig; +use OCP\IDBConnection; use OCP\ILogger; use OCP\IUserSession; @@ -416,18 +418,35 @@ class KeyManager { * Get the current version of a file * * @param string $path - * @return mixed + * @return int */ public function getVersion($path) { - return $this->keyStorage->getFileKey($path, 'version', Encryption::ID); + $view = new \OC\Files\View(); + $fileInfo = $view->getFileInfo($path); + if($fileInfo === false) { + return 0; + } + return $fileInfo->getEncryptedVersion(); } /** + * Set the current version of a file + * * @param string $path * @param string $version */ public function setVersion($path, $version) { - $this->keyStorage->setFileKey($path, 'version', $version, Encryption::ID); + $view = new \OC\Files\View(); + $fileInfo= $view->getFileInfo($path); + + if($fileInfo !== false) { + $fileId = $fileInfo->getId(); + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb->update('filecache') + ->set('encrypted', $qb->createNamedParameter($version)) + ->where($qb->expr()->eq('fileid', $qb->createNamedParameter($fileId))) + ->execute(); + } } /** diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php index 47acec1d763..0b121c344f9 100644 --- a/apps/files_versions/lib/storage.php +++ b/apps/files_versions/lib/storage.php @@ -165,7 +165,15 @@ class Storage { $mtime = $users_view->filemtime('files/' . $filename); $users_view->copy('files/' . $filename, 'files_versions/' . $filename . '.v' . $mtime); // call getFileInfo to enforce a file cache entry for the new version - $users_view->getFileInfo('files_versions/' . $filename . '.v' . $mtime); + $newFileInfo = $users_view->getFileInfo('files_versions/' . $filename . '.v' . $mtime); + + // Keep the "encrypted" value of the original file + $oldVersion = $files_view->getFileInfo($filename)->getEncryptedVersion(); + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb->update('filecache') + ->set('encrypted', $qb->createNamedParameter($oldVersion)) + ->where($qb->expr()->eq('fileid', $qb->createNamedParameter($newFileInfo->getId()))) + ->execute(); } } diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index 22b9f49e528..b30666d48d2 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -145,6 +145,7 @@ class Cache implements ICache { $data['size'] = 0 + $data['size']; $data['mtime'] = (int)$data['mtime']; $data['storage_mtime'] = (int)$data['storage_mtime']; + $data['encryptedVersion'] = (int)$data['encrypted']; $data['encrypted'] = (bool)$data['encrypted']; $data['storage'] = $this->storageId; $data['mimetype'] = $this->mimetypeLoader->getMimetypeById($data['mimetype']); @@ -345,8 +346,12 @@ class Cache implements ICache { $queryParts[] = '`mtime`'; } } elseif ($name === 'encrypted') { - // Boolean to integer conversion - $value = $value ? 1 : 0; + if(isset($data['encryptedVersion'])) { + $value = $data['encryptedVersion']; + } else { + // Boolean to integer conversion + $value = $value ? 1 : 0; + } } $params[] = $value; $queryParts[] = '`' . $name . '`'; diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index f22e1099e26..1d722a46735 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -193,6 +193,15 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { return $this->data['encrypted']; } + /** + * Return the currently version used for the HMAC in the encryption app + * + * @return int + */ + public function getEncryptedVersion() { + return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1; + } + /** * @return int */ diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index 96d642e7780..3307599aa52 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -131,11 +131,12 @@ class Encryption extends Wrapper { // update file cache if ($info) { $info = $info->getData(); + $info['encrypted'] = $info['encryptedVersion']; } else { $info = []; + $info['encrypted'] = true; } - $info['encrypted'] = true; $info['size'] = $size; $this->getCache()->put($path, $info); -- cgit v1.2.3 From 3736f1382632716102ab2c99a1028ba7bdede5f4 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 9 Feb 2016 18:07:07 +0100 Subject: Check if partial cache entry or not in encryption wrapper --- lib/private/files/storage/wrapper/encryption.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/private/files') diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index 3307599aa52..14d3b15bbae 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -39,6 +39,7 @@ use OCP\Encryption\Keys\IStorage; use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage; use OCP\ILogger; +use OCP\Files\Cache\ICacheEntry; class Encryption extends Wrapper { @@ -129,11 +130,13 @@ class Encryption extends Wrapper { if (isset($this->unencryptedSize[$fullPath])) { $size = $this->unencryptedSize[$fullPath]; // update file cache - if ($info) { + if ($info instanceof ICacheEntry) { $info = $info->getData(); $info['encrypted'] = $info['encryptedVersion']; } else { - $info = []; + if (!is_array($info)) { + $info = []; + } $info['encrypted'] = true; } -- cgit v1.2.3