summaryrefslogtreecommitdiffstats
path: root/apps/encryption/lib
diff options
context:
space:
mode:
authorBjörn Schießle <bjoern@schiessle.org>2016-01-05 15:29:44 +0100
committerLukas Reschke <lukas@owncloud.com>2016-02-09 23:43:25 +0100
commitcf3a8f274f05170b69cb3872d0d8c9045a5876d3 (patch)
tree6edd8a9f8327d530320a6ec9a1fb9f1a74a39f48 /apps/encryption/lib
parent40a5ba72fc868207356c9143c99a947f1a6e6500 (diff)
downloadnextcloud-server-cf3a8f274f05170b69cb3872d0d8c9045a5876d3.tar.gz
nextcloud-server-cf3a8f274f05170b69cb3872d0d8c9045a5876d3.zip
make it backward compatible to work with signed and un-signed files
Diffstat (limited to 'apps/encryption/lib')
-rw-r--r--apps/encryption/lib/crypto/crypt.php4
-rw-r--r--apps/encryption/lib/crypto/encryption.php25
2 files changed, 19 insertions, 10 deletions
diff --git a/apps/encryption/lib/crypto/crypt.php b/apps/encryption/lib/crypto/crypt.php
index f4c47d33f00..e935f364551 100644
--- a/apps/encryption/lib/crypto/crypt.php
+++ b/apps/encryption/lib/crypto/crypt.php
@@ -462,7 +462,7 @@ class Crypt {
*/
private function checkSignature($data, $passPhrase, $expectedSignature) {
$signature = $this->createSignature($data, $passPhrase);
- if (hash_equals($expectedSignature, $signature)) {
+ if (!hash_equals($expectedSignature, $signature)) {
throw new HintException('Bad Signature', $this->l->t('Bad Signature'));
}
}
@@ -517,7 +517,7 @@ class Crypt {
$meta = substr($catFile, -22);
$iv = substr($meta, -16);
$sig = false;
- $encrypted = substr($catFile, 0, -93);
+ $encrypted = substr($catFile, 0, -22);
}
return [
diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php
index 7099f53e2ab..4843284f7a3 100644
--- a/apps/encryption/lib/crypto/encryption.php
+++ b/apps/encryption/lib/crypto/encryption.php
@@ -94,8 +94,12 @@ class Encryption implements IEncryptionModule {
/** @var DecryptAll */
private $decryptAll;
+ /** @var int unencrypted block size if block contains signature */
+ private $unencryptedBlockSizeSigned = 6072;
+
/** @var int unencrypted block size */
- private $unencryptedBlockSize = 6072;
+ private $unencryptedBlockSize = 6126;
+
/**
*
@@ -198,7 +202,7 @@ class Encryption implements IEncryptionModule {
$this->cipher = $this->crypt->getLegacyCipher();
}
- return array('cipher' => $this->cipher);
+ return array('cipher' => $this->cipher, 'signed' => 'true');
}
/**
@@ -278,7 +282,7 @@ class Encryption implements IEncryptionModule {
// If data remaining to be written is less than the
// size of 1 6126 byte block
- if ($remainingLength < $this->unencryptedBlockSize) {
+ if ($remainingLength < $this->unencryptedBlockSizeSigned) {
// Set writeCache to contents of $data
// The writeCache will be carried over to the
@@ -296,14 +300,14 @@ class Encryption implements IEncryptionModule {
} else {
// Read the chunk from the start of $data
- $chunk = substr($data, 0, $this->unencryptedBlockSize);
+ $chunk = substr($data, 0, $this->unencryptedBlockSizeSigned);
$encrypted .= $this->crypt->symmetricEncryptFileContent($chunk, $this->fileKey);
// Remove the chunk we just processed from
// $data, leaving only unprocessed data in $data
// var, for handling on the next round
- $data = substr($data, $this->unencryptedBlockSize);
+ $data = substr($data, $this->unencryptedBlockSizeSigned);
}
@@ -410,10 +414,15 @@ class Encryption implements IEncryptionModule {
* get size of the unencrypted payload per block.
* ownCloud read/write files with a block size of 8192 byte
*
- * @return integer
+ * @param bool $signed
+ * @return int
*/
- public function getUnencryptedBlockSize() {
- return $this->unencryptedBlockSize;
+ public function getUnencryptedBlockSize($signed = false) {
+ if ($signed === false) {
+ return $this->unencryptedBlockSize;
+ }
+
+ return $this->unencryptedBlockSizeSigned;
}
/**