aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/encryption/appinfo/application.php3
-rw-r--r--apps/encryption/l10n/es.js1
-rw-r--r--apps/encryption/l10n/es.json1
-rw-r--r--apps/encryption/lib/crypto/encryption.php12
-rw-r--r--apps/encryption/tests/lib/crypto/encryptionTest.php20
-rw-r--r--lib/private/console/application.php2
-rw-r--r--lib/private/files/storage/wrapper/encryption.php8
-rw-r--r--lib/private/files/stream/encryption.php2
-rw-r--r--tests/lib/files/storage/wrapper/encryption.php81
-rw-r--r--tests/lib/files/stream/encryption.php12
10 files changed, 125 insertions, 17 deletions
diff --git a/apps/encryption/appinfo/application.php b/apps/encryption/appinfo/application.php
index 79b2ad3abaf..10ad610cd4a 100644
--- a/apps/encryption/appinfo/application.php
+++ b/apps/encryption/appinfo/application.php
@@ -104,7 +104,8 @@ class Application extends \OCP\AppFramework\App {
$container->query('Crypt'),
$container->query('KeyManager'),
$container->query('Util'),
- $container->getServer()->getLogger()
+ $container->getServer()->getLogger(),
+ $container->getServer()->getL10N($container->getAppName())
);
});
diff --git a/apps/encryption/l10n/es.js b/apps/encryption/l10n/es.js
index dd49810f03a..a5a6f086fd0 100644
--- a/apps/encryption/l10n/es.js
+++ b/apps/encryption/l10n/es.js
@@ -25,6 +25,7 @@ OC.L10N.register(
"Encryption App is enabled but your keys are not initialized, please log-out and log-in again" : "La app de cifrado está habilitada pero sus claves no se han inicializado, por favor, cierre la sesión y vuelva a iniciarla de nuevo.",
"Enable recovery key" : "Activa la clave de recuperación",
"Disable recovery key" : "Desactiva la clave de recuperación",
+ "The recovery key is an extra encryption key that is used to encrypt files. It allows recovery of a user's files if the user forgets his or her password." : "La clave de recuperación es una clave de cifrado extra que se usa para cifrar ficheros. Permite la recuperación de los ficheros de un usuario si él o ella olvida su contraseña.",
"Recovery key password" : "Contraseña de clave de recuperación",
"Repeat recovery key password" : "Repita la contraseña de recuperación",
"Change recovery key password:" : "Cambiar la contraseña de la clave de recuperación",
diff --git a/apps/encryption/l10n/es.json b/apps/encryption/l10n/es.json
index 54811d078c9..911d1f8b893 100644
--- a/apps/encryption/l10n/es.json
+++ b/apps/encryption/l10n/es.json
@@ -23,6 +23,7 @@
"Encryption App is enabled but your keys are not initialized, please log-out and log-in again" : "La app de cifrado está habilitada pero sus claves no se han inicializado, por favor, cierre la sesión y vuelva a iniciarla de nuevo.",
"Enable recovery key" : "Activa la clave de recuperación",
"Disable recovery key" : "Desactiva la clave de recuperación",
+ "The recovery key is an extra encryption key that is used to encrypt files. It allows recovery of a user's files if the user forgets his or her password." : "La clave de recuperación es una clave de cifrado extra que se usa para cifrar ficheros. Permite la recuperación de los ficheros de un usuario si él o ella olvida su contraseña.",
"Recovery key password" : "Contraseña de clave de recuperación",
"Repeat recovery key password" : "Repita la contraseña de recuperación",
"Change recovery key password:" : "Cambiar la contraseña de la clave de recuperación",
diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php
index c060bb04e53..df3f9a0997e 100644
--- a/apps/encryption/lib/crypto/encryption.php
+++ b/apps/encryption/lib/crypto/encryption.php
@@ -25,10 +25,12 @@
namespace OCA\Encryption\Crypto;
+use OC\Encryption\Exceptions\DecryptionFailedException;
use OCA\Encryption\Exceptions\PublicKeyMissingException;
use OCA\Encryption\Util;
use OCP\Encryption\IEncryptionModule;
use OCA\Encryption\KeyManager;
+use OCP\IL10N;
use OCP\ILogger;
class Encryption implements IEncryptionModule {
@@ -68,25 +70,30 @@ class Encryption implements IEncryptionModule {
/** @var Util */
private $util;
-
/** @var ILogger */
private $logger;
+ /** @var IL10N */
+ private $l;
+
/**
*
* @param Crypt $crypt
* @param KeyManager $keyManager
* @param Util $util
* @param ILogger $logger
+ * @param IL10N $il10n
*/
public function __construct(Crypt $crypt,
KeyManager $keyManager,
Util $util,
- ILogger $logger) {
+ ILogger $logger,
+ IL10N $il10n) {
$this->crypt = $crypt;
$this->keyManager = $keyManager;
$this->util = $util;
$this->logger = $logger;
+ $this->l = $il10n;
}
/**
@@ -268,6 +275,7 @@ class Encryption implements IEncryptionModule {
*
* @param string $data you want to decrypt
* @return mixed decrypted data
+ * @throws DecryptionFailedException
*/
public function decrypt($data) {
if (empty($this->fileKey)) {
diff --git a/apps/encryption/tests/lib/crypto/encryptionTest.php b/apps/encryption/tests/lib/crypto/encryptionTest.php
index 960ed112488..d33aff877bf 100644
--- a/apps/encryption/tests/lib/crypto/encryptionTest.php
+++ b/apps/encryption/tests/lib/crypto/encryptionTest.php
@@ -42,6 +42,9 @@ class EncryptionTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject */
private $loggerMock;
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ private $l10nMock;
+
public function setUp() {
parent::setUp();
@@ -57,12 +60,20 @@ class EncryptionTest extends TestCase {
$this->loggerMock = $this->getMockBuilder('OCP\ILogger')
->disableOriginalConstructor()
->getMock();
+ $this->l10nMock = $this->getMockBuilder('OCP\IL10N')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->l10nMock->expects($this->any())
+ ->method('t')
+ ->with($this->anything())
+ ->willReturnArgument(0);
$this->instance = new Encryption(
$this->cryptMock,
$this->keyManagerMock,
$this->utilMock,
- $this->loggerMock
+ $this->loggerMock,
+ $this->l10nMock
);
}
@@ -245,4 +256,11 @@ class EncryptionTest extends TestCase {
);
}
+ /**
+ * @expectedException \OC\Encryption\Exceptions\DecryptionFailedException
+ * @expectedExceptionMessage Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.
+ */
+ public function testDecrypt() {
+ $this->instance->decrypt('abc');
+ }
}
diff --git a/lib/private/console/application.php b/lib/private/console/application.php
index 6d24665e012..f2aacbfc0e6 100644
--- a/lib/private/console/application.php
+++ b/lib/private/console/application.php
@@ -35,7 +35,7 @@ class Application {
if ($this->config->getSystemValue('installed', false)) {
if (!\OCP\Util::needUpgrade()) {
OC_App::loadApps();
- foreach (OC_App::getAllApps() as $app) {
+ foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) {
$file = OC_App::getAppPath($app) . '/appinfo/register_command.php';
if (file_exists($file)) {
require $file;
diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php
index 1683ff1350f..5d146b2dd1d 100644
--- a/lib/private/files/storage/wrapper/encryption.php
+++ b/lib/private/files/storage/wrapper/encryption.php
@@ -245,8 +245,12 @@ class Encryption extends Wrapper {
*/
public function rmdir($path) {
$result = $this->storage->rmdir($path);
- if ($result && $this->encryptionManager->isEnabled()) {
- $this->keyStorage->deleteAllFileKeys($this->getFullPath($path));
+ $fullPath = $this->getFullPath($path);
+ if ($result &&
+ $this->util->isExcluded($fullPath) === false &&
+ $this->encryptionManager->isEnabled()
+ ) {
+ $this->keyStorage->deleteAllFileKeys($fullPath);
}
return $result;
diff --git a/lib/private/files/stream/encryption.php b/lib/private/files/stream/encryption.php
index e423868d82b..f2f5b9c9af7 100644
--- a/lib/private/files/stream/encryption.php
+++ b/lib/private/files/stream/encryption.php
@@ -341,8 +341,8 @@ class Encryption extends Wrapper {
} else {
$data = '';
}
+ $this->unencryptedSize = max($this->unencryptedSize, $this->position);
}
- $this->unencryptedSize = max($this->unencryptedSize, $this->position);
return $length;
}
diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php
index 361592f6ca1..39af648cb75 100644
--- a/tests/lib/files/storage/wrapper/encryption.php
+++ b/tests/lib/files/storage/wrapper/encryption.php
@@ -47,6 +47,22 @@ class Encryption extends \Test\Files\Storage\Storage {
*/
private $cache;
+ /**
+ * @var \OC\Log | \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $logger;
+
+ /**
+ * @var \OC\Encryption\File | \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $file;
+
+
+ /**
+ * @var \OC\Files\Mount\MountPoint | \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $mount;
+
/** @var integer dummy unencrypted size */
private $dummySize = -1;
@@ -77,13 +93,13 @@ class Encryption extends \Test\Files\Storage\Storage {
return ['user1', $path];
});
- $file = $this->getMockBuilder('\OC\Encryption\File')
+ $this->file = $this->getMockBuilder('\OC\Encryption\File')
->disableOriginalConstructor()
->setMethods(['getAccessList'])
->getMock();
- $file->expects($this->any())->method('getAccessList')->willReturn([]);
+ $this->file->expects($this->any())->method('getAccessList')->willReturn([]);
- $logger = $this->getMock('\OC\Log');
+ $this->logger = $this->getMock('\OC\Log');
$this->sourceStorage = new Temporary(array());
@@ -93,11 +109,11 @@ class Encryption extends \Test\Files\Storage\Storage {
$this->update = $this->getMockBuilder('\OC\Encryption\Update')
->disableOriginalConstructor()->getMock();
- $mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
+ $this->mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
->disableOriginalConstructor()
->setMethods(['getOption'])
->getMock();
- $mount->expects($this->any())->method('getOption')->willReturn(true);
+ $this->mount->expects($this->any())->method('getOption')->willReturn(true);
$this->cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
->disableOriginalConstructor()->getMock();
@@ -112,9 +128,9 @@ class Encryption extends \Test\Files\Storage\Storage {
'storage' => $this->sourceStorage,
'root' => 'foo',
'mountPoint' => '/',
- 'mount' => $mount
+ 'mount' => $this->mount
],
- $this->encryptionManager, $this->util, $logger, $file, null, $this->keyStore, $this->update
+ $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update
]
)
->setMethods(['getMetaData', 'getCache', 'getEncryptionModule'])
@@ -257,4 +273,55 @@ class Encryption extends \Test\Files\Storage\Storage {
->method('isEnabled')->willReturn(true);
$this->assertFalse($this->instance->isLocal());
}
+
+ /**
+ * @dataProvider dataTestRmdir
+ *
+ * @param string $path
+ * @param boolean $rmdirResult
+ * @param boolean $isExcluded
+ * @param boolean $encryptionEnabled
+ */
+ public function testRmdir($path, $rmdirResult, $isExcluded, $encryptionEnabled) {
+ $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage')
+ ->disableOriginalConstructor()->getMock();
+
+ $util = $this->getMockBuilder('\OC\Encryption\Util')->disableOriginalConstructor()->getMock();
+
+ $sourceStorage->expects($this->once())->method('rmdir')->willReturn($rmdirResult);
+ $util->expects($this->any())->method('isExcluded')-> willReturn($isExcluded);
+ $this->encryptionManager->expects($this->any())->method('isEnabled')->willReturn($encryptionEnabled);
+
+ $encryptionStorage = new \OC\Files\Storage\Wrapper\Encryption(
+ [
+ 'storage' => $sourceStorage,
+ 'root' => 'foo',
+ 'mountPoint' => '/mountPoint',
+ 'mount' => $this->mount
+ ],
+ $this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update
+ );
+
+
+ if ($rmdirResult === true && $isExcluded === false && $encryptionEnabled === true) {
+ $this->keyStore->expects($this->once())->method('deleteAllFileKeys')->with('/mountPoint' . $path);
+ } else {
+ $this->keyStore->expects($this->never())->method('deleteAllFileKeys');
+ }
+
+ $encryptionStorage->rmdir($path);
+ }
+
+ public function dataTestRmdir() {
+ return array(
+ array('/file.txt', true, true, true),
+ array('/file.txt', false, true, true),
+ array('/file.txt', true, false, true),
+ array('/file.txt', false, false, true),
+ array('/file.txt', true, true, false),
+ array('/file.txt', false, true, false),
+ array('/file.txt', true, false, false),
+ array('/file.txt', false, false, false),
+ );
+ }
}
diff --git a/tests/lib/files/stream/encryption.php b/tests/lib/files/stream/encryption.php
index 30c6d247236..c2388c7682a 100644
--- a/tests/lib/files/stream/encryption.php
+++ b/tests/lib/files/stream/encryption.php
@@ -7,6 +7,9 @@ use OCA\Encryption_Dummy\DummyModule;
class Encryption extends \Test\TestCase {
+ /** @var \OCP\Encryption\IEncryptionModule | \PHPUnit_Framework_MockObject_MockObject */
+ private $encryptionModule;
+
/**
* @param string $fileName
* @param string $mode
@@ -21,7 +24,7 @@ class Encryption extends \Test\TestCase {
$fullPath = $fileName;
$header = [];
$uid = '';
- $encryptionModule = $this->buildMockModule();
+ $this->encryptionModule = $this->buildMockModule();
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()->getMock();
$encStorage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
@@ -43,7 +46,7 @@ class Encryption extends \Test\TestCase {
->willReturn(['user1', $internalPath]);
return \OC\Files\Stream\Encryption::wrap($source, $internalPath,
- $fullPath, $header, $uid, $encryptionModule, $storage, $encStorage,
+ $fullPath, $header, $uid, $this->encryptionModule, $storage, $encStorage,
$util, $file, $mode, $size, $unencryptedSize, 8192);
}
@@ -221,10 +224,15 @@ class Encryption extends \Test\TestCase {
* @dataProvider dataFilesProvider
*/
public function testWriteReadBigFile($testFile) {
+
$expectedData = file_get_contents(\OC::$SERVERROOT . '/tests/data/' . $testFile);
// write it
$fileName = tempnam("/tmp", "FOO");
$stream = $this->getStream($fileName, 'w+', 0);
+ // while writing the file from the beginning to the end we should never try
+ // to read parts of the file. This should only happen for write operations
+ // in the middle of a file
+ $this->encryptionModule->expects($this->never())->method('decrypt');
fwrite($stream, $expectedData);
fclose($stream);