summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-03-06 13:35:06 +0100
committerRobin Appelman <icewind@owncloud.com>2014-03-06 13:35:06 +0100
commit84cf40ed82417f56586c46317b1280065c7091a6 (patch)
tree2f774fd12de4763b9f2a0f29a7199d2a3b05f14e /apps/files_encryption
parenta687498547448d6ff11eccc0acddcf0647873ce8 (diff)
parent1785c0c9b9fcdc6e9a8e58f13f45e5b53364882a (diff)
downloadnextcloud-server-84cf40ed82417f56586c46317b1280065c7091a6.tar.gz
nextcloud-server-84cf40ed82417f56586c46317b1280065c7091a6.zip
merge master into webdav-injection
Diffstat (limited to 'apps/files_encryption')
-rw-r--r--apps/files_encryption/js/settings-admin.js22
-rw-r--r--apps/files_encryption/lib/proxy.php34
-rw-r--r--apps/files_encryption/lib/session.php8
-rw-r--r--apps/files_encryption/lib/stream.php3
-rw-r--r--apps/files_encryption/lib/util.php9
-rwxr-xr-xapps/files_encryption/tests/util.php4
6 files changed, 48 insertions, 32 deletions
diff --git a/apps/files_encryption/js/settings-admin.js b/apps/files_encryption/js/settings-admin.js
index c2140a6f1eb..785d02002fa 100644
--- a/apps/files_encryption/js/settings-admin.js
+++ b/apps/files_encryption/js/settings-admin.js
@@ -7,28 +7,6 @@
* See the COPYING-README file.
*/
-OC.msg={
- startSaving:function(selector){
- $(selector)
- .html( t('settings', 'Saving...') )
- .removeClass('success')
- .removeClass('error')
- .stop(true, true)
- .show();
- },
- finishedSaving:function(selector, data){
- if( data.status === "success" ){
- $(selector).html( data.data.message )
- .addClass('success')
- .stop(true, true)
- .delay(3000)
- .fadeOut(900);
- }else{
- $(selector).html( data.data.message ).addClass('error');
- }
- }
-};
-
$(document).ready(function(){
// Trigger ajax on recoveryAdmin status change
var enabledStatus = $('#adminEnableRecovery').val();
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index 9d456f6c517..a2d42c22c13 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -38,6 +38,7 @@ class Proxy extends \OC_FileProxy {
private static $blackList = null; //mimetypes blacklisted from encryption
private static $unencryptedSizes = array(); // remember unencrypted size
+ private static $fopenMode = array(); // remember the fopen mode
/**
* Check if a file requires encryption
@@ -146,7 +147,7 @@ class Proxy extends \OC_FileProxy {
if ( isset(self::$unencryptedSizes[$normalizedPath]) ) {
$view = new \OC_FilesystemView('/');
$view->putFileInfo($normalizedPath,
- array('encrypted' => true, 'encrypted_size' => self::$unencryptedSizes[$normalizedPath]));
+ array('encrypted' => true, 'unencrypted_size' => self::$unencryptedSizes[$normalizedPath]));
unset(self::$unencryptedSizes[$normalizedPath]);
}
@@ -214,6 +215,16 @@ class Proxy extends \OC_FileProxy {
}
/**
+ * @brief remember initial fopen mode because sometimes it gets changed during the request
+ * @param string $path path
+ * @param string $mode type of access
+ */
+ public function preFopen($path, $mode) {
+ self::$fopenMode[$path] = $mode;
+ }
+
+
+ /**
* @param $path
* @param $result
* @return resource
@@ -240,7 +251,15 @@ class Proxy extends \OC_FileProxy {
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
- $meta = stream_get_meta_data($result);
+ // if we remember the mode from the pre proxy we re-use it
+ // oterwise we fall back to stream_get_meta_data()
+ if (isset(self::$fopenMode[$path])) {
+ $mode = self::$fopenMode[$path];
+ unset(self::$fopenMode[$path]);
+ } else {
+ $meta = stream_get_meta_data($result);
+ $mode = $meta['mode'];
+ }
$view = new \OC_FilesystemView('');
@@ -258,14 +277,15 @@ class Proxy extends \OC_FileProxy {
// Open the file using the crypto stream wrapper
// protocol and let it do the decryption work instead
- $result = fopen('crypt://' . $path, $meta['mode']);
+ $result = fopen('crypt://' . $path, $mode);
} elseif (
- self::shouldEncrypt($path)
- and $meta['mode'] !== 'r'
- and $meta['mode'] !== 'rb'
+ self::shouldEncrypt($path)
+ and $mode !== 'r'
+ and $mode !== 'rb'
+
) {
- $result = fopen('crypt://' . $path, $meta['mode']);
+ $result = fopen('crypt://' . $path, $mode);
}
// Re-enable the proxy
diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php
index aa58e33e9d2..3daaa06425f 100644
--- a/apps/files_encryption/lib/session.php
+++ b/apps/files_encryption/lib/session.php
@@ -134,6 +134,14 @@ class Session {
}
+ /**
+ * @brief remove encryption keys and init status from session
+ */
+ public function closeSession() {
+ \OC::$session->remove('encryptionInitialized');
+ \OC::$session->remove('privateKey');
+ }
+
/**
* @brief Gets status if we already tried to initialize the encryption app
diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php
index 88eacc6f136..58ac03373a7 100644
--- a/apps/files_encryption/lib/stream.php
+++ b/apps/files_encryption/lib/stream.php
@@ -167,6 +167,9 @@ class Stream {
} else {
$this->meta = stream_get_meta_data($this->handle);
+ // sometimes fopen changes the mode, e.g. for a url "r" convert to "r+"
+ // but we need to remember the original access type
+ $this->meta['mode'] = $mode;
}
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index ec06bd52f5e..3db5a423478 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -135,7 +135,6 @@ class Util {
// Set directories to check / create
$setUpDirs = array(
$this->userDir,
- $this->userFilesDir,
$this->publicKeyDir,
$this->encryptionDir,
$this->keyfilesPath,
@@ -1772,4 +1771,12 @@ class Util {
return $session;
}
+ /*
+ * @brief remove encryption related keys from the session
+ */
+ public function closeEncryptionSession() {
+ $session = new \OCA\Encryption\Session($this->view);
+ $session->closeSession();
+ }
+
}
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index 5fa96f6ad69..55a056613e4 100755
--- a/apps/files_encryption/tests/util.php
+++ b/apps/files_encryption/tests/util.php
@@ -344,7 +344,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
// check if mtime and etags unchanged
$this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
- $this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
+ $this->assertSame($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
$this->view->unlink($this->userId . '/files/' . $filename);
}
@@ -373,7 +373,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
// check if mtime and etags unchanged
$this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
- $this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
+ $this->assertSame($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
// file should no longer be encrypted
$this->assertEquals(0, $fileInfoUnencrypted['encrypted']);