aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/encryption/lib/Crypto/Encryption.php8
-rw-r--r--apps/encryption/lib/KeyManager.php3
-rw-r--r--apps/encryption/lib/Session.php10
-rw-r--r--apps/encryption/tests/Crypto/EncryptionTest.php15
-rw-r--r--apps/encryption/tests/SessionTest.php26
5 files changed, 59 insertions, 3 deletions
diff --git a/apps/encryption/lib/Crypto/Encryption.php b/apps/encryption/lib/Crypto/Encryption.php
index c71e25b6442..fdcbd41a09c 100644
--- a/apps/encryption/lib/Crypto/Encryption.php
+++ b/apps/encryption/lib/Crypto/Encryption.php
@@ -177,6 +177,14 @@ class Encryption implements IEncryptionModule {
$this->isWriteOperation = false;
$this->writeCache = '';
+ if($this->session->isReady() === false) {
+ // if the master key is enabled we can initialize encryption
+ // with a empty password and user name
+ if ($this->util->isMasterKeyEnabled()) {
+ $this->keyManager->init('', '');
+ }
+ }
+
if ($this->session->decryptAllModeActivated()) {
$encryptedFileKey = $this->keyManager->getEncryptedFileKey($this->path);
$shareKey = $this->keyManager->getShareKey($this->path, $this->session->getDecryptAllUid());
diff --git a/apps/encryption/lib/KeyManager.php b/apps/encryption/lib/KeyManager.php
index 96264d01363..26f023ed8f9 100644
--- a/apps/encryption/lib/KeyManager.php
+++ b/apps/encryption/lib/KeyManager.php
@@ -406,9 +406,6 @@ class KeyManager {
}
if ($this->util->isMasterKeyEnabled()) {
- if ($this->session->getStatus() === Session::NOT_INITIALIZED)
- $this->init('', '');
-
$uid = $this->getMasterKeyId();
}
diff --git a/apps/encryption/lib/Session.php b/apps/encryption/lib/Session.php
index 92132d6080c..a61ee25fadb 100644
--- a/apps/encryption/lib/Session.php
+++ b/apps/encryption/lib/Session.php
@@ -68,6 +68,16 @@ class Session {
}
/**
+ * check if encryption was initialized successfully
+ *
+ * @return bool
+ */
+ public function isReady() {
+ $status = $this->getStatus();
+ return $status === self::INIT_SUCCESSFUL;
+ }
+
+ /**
* Gets user or public share private key from session
*
* @return string $privateKey The user's plaintext private key
diff --git a/apps/encryption/tests/Crypto/EncryptionTest.php b/apps/encryption/tests/Crypto/EncryptionTest.php
index 658f6275bb4..3525d2d4aec 100644
--- a/apps/encryption/tests/Crypto/EncryptionTest.php
+++ b/apps/encryption/tests/Crypto/EncryptionTest.php
@@ -280,6 +280,21 @@ class EncryptionTest extends TestCase {
}
/**
+ * test begin() if encryption is not initialized but the master key is enabled
+ * in this case we can initialize the encryption without a username/password
+ * and continue
+ */
+ public function testBeginInitMasterKey() {
+
+ $this->sessionMock->expects($this->once())->method('isReady')->willReturn(false);
+ $this->utilMock->expects($this->once())->method('isMasterKeyEnabled')
+ ->willReturn(true);
+ $this->keyManagerMock->expects($this->once())->method('init')->with('', '');
+
+ $this->instance->begin('/user/files/welcome.txt', 'user', 'r', [], []);
+ }
+
+ /**
* @dataProvider dataTestUpdate
*
* @param string $fileKey
diff --git a/apps/encryption/tests/SessionTest.php b/apps/encryption/tests/SessionTest.php
index 099acddbca1..3000fedf2c3 100644
--- a/apps/encryption/tests/SessionTest.php
+++ b/apps/encryption/tests/SessionTest.php
@@ -134,6 +134,32 @@ class SessionTest extends TestCase {
}
/**
+ * @dataProvider dataTestIsReady
+ *
+ * @param int $status
+ * @param bool $expected
+ */
+ public function testIsReady($status, $expected) {
+ /** @var Session | \PHPUnit_Framework_MockObject_MockObject $instance */
+ $instance = $this->getMockBuilder(Session::class)
+ ->setConstructorArgs([$this->sessionMock])
+ ->setMethods(['getStatus'])->getMock();
+
+ $instance->expects($this->once())->method('getStatus')
+ ->willReturn($status);
+
+ $this->assertSame($expected, $instance->isReady());
+ }
+
+ public function dataTestIsReady() {
+ return [
+ [Session::INIT_SUCCESSFUL, true],
+ [Session::INIT_EXECUTED, false],
+ [Session::NOT_INITIALIZED, false],
+ ];
+ }
+
+ /**
* @param $key
* @param $value
*/