Merge pull request #21612 from owncloud/fix_21598
fix public link sharing if the master key is enabled
This commit is contained in:
commit
e0aa6e01ab
|
@ -388,16 +388,17 @@ class KeyManager {
|
||||||
public function getFileKey($path, $uid) {
|
public function getFileKey($path, $uid) {
|
||||||
$encryptedFileKey = $this->keyStorage->getFileKey($path, $this->fileKeyId, Encryption::ID);
|
$encryptedFileKey = $this->keyStorage->getFileKey($path, $this->fileKeyId, Encryption::ID);
|
||||||
|
|
||||||
if ($this->util->isMasterKeyEnabled()) {
|
|
||||||
$uid = $this->getMasterKeyId();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($uid)) {
|
if (is_null($uid)) {
|
||||||
$uid = $this->getPublicShareKeyId();
|
$uid = $this->getPublicShareKeyId();
|
||||||
$shareKey = $this->getShareKey($path, $uid);
|
$shareKey = $this->getShareKey($path, $uid);
|
||||||
$privateKey = $this->keyStorage->getSystemUserKey($this->publicShareKeyId . '.privateKey', Encryption::ID);
|
$privateKey = $this->keyStorage->getSystemUserKey($this->publicShareKeyId . '.privateKey', Encryption::ID);
|
||||||
$privateKey = $this->crypt->decryptPrivateKey($privateKey);
|
$privateKey = $this->crypt->decryptPrivateKey($privateKey);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
if ($this->util->isMasterKeyEnabled()) {
|
||||||
|
$uid = $this->getMasterKeyId();
|
||||||
|
}
|
||||||
|
|
||||||
$shareKey = $this->getShareKey($path, $uid);
|
$shareKey = $this->getShareKey($path, $uid);
|
||||||
$privateKey = $this->session->getPrivateKey();
|
$privateKey = $this->session->getPrivateKey();
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,25 +342,77 @@ class KeyManagerTest extends TestCase {
|
||||||
$this->assertTrue($this->instance->getEncryptedFileKey('/'));
|
$this->assertTrue($this->instance->getEncryptedFileKey('/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetFileKey() {
|
/**
|
||||||
$this->keyStorageMock->expects($this->exactly(4))
|
* @dataProvider dataTestGetFileKey
|
||||||
|
*
|
||||||
|
* @param $uid
|
||||||
|
* @param $isMasterKeyEnabled
|
||||||
|
* @param $privateKey
|
||||||
|
* @param $expected
|
||||||
|
*/
|
||||||
|
public function testGetFileKey($uid, $isMasterKeyEnabled, $privateKey, $expected) {
|
||||||
|
|
||||||
|
$path = '/foo.txt';
|
||||||
|
|
||||||
|
if ($isMasterKeyEnabled) {
|
||||||
|
$expectedUid = 'masterKeyId';
|
||||||
|
} else {
|
||||||
|
$expectedUid = $uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->invokePrivate($this->instance, 'masterKeyId', ['masterKeyId']);
|
||||||
|
|
||||||
|
$this->keyStorageMock->expects($this->at(0))
|
||||||
->method('getFileKey')
|
->method('getFileKey')
|
||||||
|
->with($path, 'fileKey', 'OC_DEFAULT_MODULE')
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
|
|
||||||
|
$this->keyStorageMock->expects($this->at(1))
|
||||||
|
->method('getFileKey')
|
||||||
|
->with($path, $expectedUid . '.shareKey', 'OC_DEFAULT_MODULE')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
if (is_null($uid)) {
|
||||||
$this->keyStorageMock->expects($this->once())
|
$this->keyStorageMock->expects($this->once())
|
||||||
->method('getSystemUserKey')
|
->method('getSystemUserKey')
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
|
|
||||||
$this->cryptMock->expects($this->once())
|
$this->cryptMock->expects($this->once())
|
||||||
->method('decryptPrivateKey')
|
->method('decryptPrivateKey')
|
||||||
->willReturn(true);
|
->willReturn($privateKey);
|
||||||
|
} else {
|
||||||
|
$this->keyStorageMock->expects($this->never())
|
||||||
|
->method('getSystemUserKey');
|
||||||
|
$this->utilMock->expects($this->once())->method('isMasterKeyEnabled')
|
||||||
|
->willReturn($isMasterKeyEnabled);
|
||||||
|
$this->sessionMock->expects($this->once())->method('getPrivateKey')->willReturn($privateKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($privateKey) {
|
||||||
$this->cryptMock->expects($this->once())
|
$this->cryptMock->expects($this->once())
|
||||||
->method('multiKeyDecrypt')
|
->method('multiKeyDecrypt')
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
|
} else {
|
||||||
|
$this->cryptMock->expects($this->never())
|
||||||
|
->method('multiKeyDecrypt');
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertTrue($this->instance->getFileKey('/', null));
|
$this->assertSame($expected,
|
||||||
$this->assertEmpty($this->instance->getFileKey('/', $this->userId));
|
$this->instance->getFileKey($path, $uid)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dataTestGetFileKey() {
|
||||||
|
return [
|
||||||
|
['user1', false, 'privateKey', true],
|
||||||
|
['user1', false, false, ''],
|
||||||
|
['user1', true, 'privateKey', true],
|
||||||
|
['user1', true, false, ''],
|
||||||
|
['', false, 'privateKey', true],
|
||||||
|
['', false, false, ''],
|
||||||
|
['', true, 'privateKey', true],
|
||||||
|
['', true, false, '']
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDeletePrivateKey() {
|
public function testDeletePrivateKey() {
|
||||||
|
|
Loading…
Reference in New Issue