summaryrefslogtreecommitdiffstats
path: root/apps/encryption/lib/crypto/encryption.php
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-02-03 14:32:04 +0100
committerLukas Reschke <lukas@owncloud.com>2016-02-09 23:43:26 +0100
commit3badf5caf579f8ff10c9917f62cb41cd9b0c68f8 (patch)
tree2251ec9415958573a4b434f0600fd48c7c29cdf6 /apps/encryption/lib/crypto/encryption.php
parentb5824f024a1008b0195b6e8f4803774cfe644b7b (diff)
downloadnextcloud-server-3badf5caf579f8ff10c9917f62cb41cd9b0c68f8.tar.gz
nextcloud-server-3badf5caf579f8ff10c9917f62cb41cd9b0c68f8.zip
Use number of chunk for HMAC as well
Prevents switching single blocks within the encrypted file.
Diffstat (limited to 'apps/encryption/lib/crypto/encryption.php')
-rw-r--r--apps/encryption/lib/crypto/encryption.php19
1 files changed, 9 insertions, 10 deletions
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);
}
/**