Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>tags/v11.0RC2
@@ -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()); |
@@ -406,9 +406,6 @@ class KeyManager { | |||
} | |||
if ($this->util->isMasterKeyEnabled()) { | |||
if ($this->session->getStatus() === Session::NOT_INITIALIZED) | |||
$this->init('', ''); | |||
$uid = $this->getMasterKeyId(); | |||
} | |||
@@ -67,6 +67,16 @@ class Session { | |||
return $status; | |||
} | |||
/** | |||
* 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 | |||
* |
@@ -279,6 +279,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 | |||
* |
@@ -133,6 +133,32 @@ class SessionTest extends TestCase { | |||
$this->assertEquals(2, $this->instance->getStatus()); | |||
} | |||
/** | |||
* @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 |