summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption
diff options
context:
space:
mode:
authorjknockaert <jasper@knockaert.nl>2014-10-20 00:28:41 +0200
committerjknockaert <jasper@knockaert.nl>2014-10-20 00:28:41 +0200
commit1b7e9d66b31553f6a257638c868fd16f1a8e8e4b (patch)
treec820a47988a38a14eca37c95bda0146c22cd83c8 /apps/files_encryption
parent3be57d0169eaa2bc95f25c3ed070bdc9940a1531 (diff)
downloadnextcloud-server-1b7e9d66b31553f6a257638c868fd16f1a8e8e4b.tar.gz
nextcloud-server-1b7e9d66b31553f6a257638c868fd16f1a8e8e4b.zip
ok; still some bugs that had to be fixed
Diffstat (limited to 'apps/files_encryption')
-rw-r--r--apps/files_encryption/lib/util.php74
1 files changed, 35 insertions, 39 deletions
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 410d3dd1255..75cf78c5f94 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -392,59 +392,55 @@ class Util {
$size = $this->view->filesize($path);
// open stream
- $stream = fopen($path, "r");
-
- // if the file contains a encryption header we
- // we set the cipher
- // and we update the size
- if ($this->containHeader($path)) {
- $data = fread($stream,Crypt::BLOCKSIZE);
- $header = Crypt::parseHeader($data);
- $cipher = Crypt::getCipher($header);
- $size -= Crypt::BLOCKSIZE;
- }
+ $stream = $this->view->fopen($path, "r");
- // fast path, else the calculation for $lastChunkNr is bogus
- if ($size === 0) {
- \OC_FileProxy::$enabled = $proxyStatus;
- return 0;
- }
+ if (is_resource($stream)) {
- // calculate last chunk nr
- // next highest is end of chunks, one subtracted is last one
- // we have to read the last chunk, we can't just calculate it (because of padding etc)
- $lastChunkNr = ceil($size/Crypt::BLOCKSIZE)-1;
+ // if the file contains a encryption header we
+ // we set the cipher
+ // and we update the size
+ if ($this->containHeader($path)) {
+ $data = fread($stream,Crypt::BLOCKSIZE);
+ $header = Crypt::parseHeader($data);
+ $cipher = Crypt::getCipher($header);
+ $size -= Crypt::BLOCKSIZE;
+ }
+
+ // fast path, else the calculation for $lastChunkNr is bogus
+ if ($size === 0) {
+ \OC_FileProxy::$enabled = $proxyStatus;
+ return 0;
+ }
+
+ // calculate last chunk nr
+ // next highest is end of chunks, one subtracted is last one
+ // we have to read the last chunk, we can't just calculate it (because of padding etc)
+ $lastChunkNr = ceil($size/Crypt::BLOCKSIZE)-1;
- if (is_resource($stream)) {
// calculate last chunk position
$lastChunkPos = ($lastChunkNr * Crypt::BLOCKSIZE);
// get the content of the last chunk
- $lastChunkContentEncrypted='';
- $count=Crypt::BLOCKSIZE;
if (@fseek($stream, $lastChunkPos, SEEK_CUR) === 0) {
$realSize+=$lastChunkNr*6126;
- while ($count>0) {
- $data=fread($stream,Crypt::BLOCKSIZE);
- $count=strlen($data);
- $lastChunkContentEncrypted.=$data;
- }
- } else {
- while ($count>0) {
- if(strlen($lastChunkContentEncrypted)>Crypt::BLOCKSIZE) {
- $realSize+=6126;
- $lastChunkContentEncrypted=substr($lastChunkContentEncrypted,Crypt::BLOCKSIZE);
- }
- $data=fread($stream,Crypt::BLOCKSIZE);
- $count=strlen($data);
- $lastChunkContentEncrypted.=$data;
+ }
+ $lastChunkContentEncrypted='';
+ $count=Crypt::BLOCKSIZE;
+ while ($count>0) {
+ $data=fread($stream,Crypt::BLOCKSIZE);
+ $count=strlen($data);
+ $lastChunkContentEncrypted.=$data;
+ if(strlen($lastChunkContentEncrypted)>Crypt::BLOCKSIZE) {
+ $realSize+=6126;
+ $lastChunkContentEncrypted=substr($lastChunkContentEncrypted,Crypt::BLOCKSIZE);
}
}
+ $relPath = \OCA\Encryption\Helper::stripUserFilesPath($path);
$session = new \OCA\Encryption\Session(new \OC\Files\View('/'));
$privateKey = $session->getPrivateKey();
- $plainKeyfile = $this->decryptKeyfile($path, $privateKey);
- $shareKey = Keymanager::getShareKey($this->view, $this->keyId, $this, $path);
+ $plainKeyfile = $this->decryptKeyfile($relPath, $privateKey);
+ $shareKey = Keymanager::getShareKey($this->view, $this->keyId, $this, $relPath);
$plainKey = Crypt::multiKeyDecrypt($plainKeyfile, $shareKey, $privateKey);