if we don't have a encrypted file key we can return a empty string right away
This commit is contained in:
parent
088ffd05d7
commit
d86f8ba5f8
2 changed files with 38 additions and 5 deletions
|
@ -394,17 +394,20 @@ 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 (empty($encryptedFileKey)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,36 @@ class EncryptAllTest extends TestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEncryptAllWithMasterKey() {
|
||||||
|
/** @var EncryptAll | \PHPUnit_Framework_MockObject_MockObject $encryptAll */
|
||||||
|
$encryptAll = $this->getMockBuilder('OCA\Encryption\Crypto\EncryptAll')
|
||||||
|
->setConstructorArgs(
|
||||||
|
[
|
||||||
|
$this->setupUser,
|
||||||
|
$this->userManager,
|
||||||
|
$this->view,
|
||||||
|
$this->keyManager,
|
||||||
|
$this->util,
|
||||||
|
$this->config,
|
||||||
|
$this->mailer,
|
||||||
|
$this->l,
|
||||||
|
$this->questionHelper,
|
||||||
|
$this->secureRandom
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->setMethods(['createKeyPairs', 'encryptAllUsersFiles', 'outputPasswords'])
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(true);
|
||||||
|
$encryptAll->expects($this->never())->method('createKeyPairs');
|
||||||
|
$this->keyManager->expects($this->once())->method('validateMasterKey');
|
||||||
|
$encryptAll->expects($this->at(0))->method('encryptAllUsersFiles')->with();
|
||||||
|
$encryptAll->expects($this->never())->method('outputPasswords');
|
||||||
|
|
||||||
|
$encryptAll->encryptAll($this->inputInterface, $this->outputInterface);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testCreateKeyPairs() {
|
public function testCreateKeyPairs() {
|
||||||
/** @var EncryptAll | \PHPUnit_Framework_MockObject_MockObject $encryptAll */
|
/** @var EncryptAll | \PHPUnit_Framework_MockObject_MockObject $encryptAll */
|
||||||
$encryptAll = $this->getMockBuilder('OCA\Encryption\Crypto\EncryptAll')
|
$encryptAll = $this->getMockBuilder('OCA\Encryption\Crypto\EncryptAll')
|
||||||
|
|
Loading…
Reference in a new issue