summaryrefslogtreecommitdiffstats
path: root/apps/encryption/lib
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2016-02-10 11:08:03 +0100
committerBjoern Schiessle <schiessle@owncloud.com>2016-02-10 11:08:03 +0100
commit43ed86313ca3e8f6820dc08c38c9d4a7c32ddf01 (patch)
tree22e3d49c6416e4352a3916e1aa54de8ecfaf8cb8 /apps/encryption/lib
parent9ebcc4ce312db574173627488887f14db2f4bc34 (diff)
downloadnextcloud-server-43ed86313ca3e8f6820dc08c38c9d4a7c32ddf01.tar.gz
nextcloud-server-43ed86313ca3e8f6820dc08c38c9d4a7c32ddf01.zip
use the version of the original file if we write the part file to have a proper version if we move the file over to the original location
Diffstat (limited to 'apps/encryption/lib')
-rw-r--r--apps/encryption/lib/crypto/encryption.php45
1 files changed, 30 insertions, 15 deletions
diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php
index a637f52a869..498c59ffa21 100644
--- a/apps/encryption/lib/crypto/encryption.php
+++ b/apps/encryption/lib/crypto/encryption.php
@@ -29,6 +29,7 @@ namespace OCA\Encryption\Crypto;
use OC\Encryption\Exceptions\DecryptionFailedException;
+use OC\Files\Cache\Scanner;
use OC\Files\View;
use OCA\Encryption\Exceptions\PublicKeyMissingException;
use OCA\Encryption\Session;
@@ -187,7 +188,10 @@ class Encryption implements IEncryptionModule {
$this->fileKey = $this->keyManager->getFileKey($this->path, $this->user);
}
- $this->version = (int)$this->keyManager->getVersion($this->realPath, new View());
+ // always use the version from the original file, also part files
+ // need to have a correct version number if they get moved over to the
+ // final location
+ $this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($this->realPath), new View());
if (
$mode === 'w'
@@ -199,6 +203,13 @@ class Encryption implements IEncryptionModule {
if (empty($this->fileKey)) {
$this->fileKey = $this->crypt->generateFileKey();
}
+ } else {
+ // if we read a part file we need to increase the version by 1
+ // because the version number was also increased by writing
+ // the part file
+ if(Scanner::isPartialFile($path)) {
+ $this->version = $this->version + 1;
+ }
}
if ($this->isWriteOperation) {
@@ -230,15 +241,9 @@ class Encryption implements IEncryptionModule {
public function end($path, $position = 0) {
$result = '';
if ($this->isWriteOperation) {
- // Partial files do not increase the version
- if(\OC\Files\Cache\Scanner::isPartialFile($path)) {
- $version = $this->version;
- } else {
- $version = $this->version + 1;
- }
$this->keyManager->setVersion($this->path, $this->version+1, new View());
if (!empty($this->writeCache)) {
- $result = $this->crypt->symmetricEncryptFileContent($this->writeCache, $this->fileKey, $version, $position);
+ $result = $this->crypt->symmetricEncryptFileContent($this->writeCache, $this->fileKey, $this->version + 1, $position);
$this->writeCache = '';
}
$publicKeys = array();
@@ -319,13 +324,7 @@ class Encryption implements IEncryptionModule {
// Read the chunk from the start of $data
$chunk = substr($data, 0, $this->unencryptedBlockSizeSigned);
- // Partial files do not increase the version
- if(\OC\Files\Cache\Scanner::isPartialFile($this->path)) {
- $version = $this->version;
- } else {
- $version = $this->version + 1;
- }
- $encrypted .= $this->crypt->symmetricEncryptFileContent($chunk, $this->fileKey, $version, $position);
+ $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
@@ -520,4 +519,20 @@ class Encryption implements IEncryptionModule {
return $realPath;
}
+ /**
+ * remove .part file extension and the ocTransferId from the file to get the
+ * original file name
+ *
+ * @param string $path
+ * @return string
+ */
+ protected function stripPartFileExtension($path) {
+ if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
+ $pos = strrpos($path, '.', -6);
+ $path = substr($path, 0, $pos);
+ }
+
+ return $path;
+ }
+
}