/** * copy keys to new location * * @param string $source path relative to data/ * @param string $target path relative to data/ * @return bool */ protected function copyKeys($source, $target) { if (!$this->util->isExcluded($source)) { return $this->keyStorage->copyKeys($source, $target); } return false; }
/** * @dataProvider dataTestValidateMasterKey * * @param $masterKey */ public function testValidateMasterKey($masterKey) { /** @var \OCA\Encryption\KeyManager | \PHPUnit_Framework_MockObject_MockObject $instance */ $instance = $this->getMockBuilder('OCA\\Encryption\\KeyManager')->setConstructorArgs([$this->keyStorageMock, $this->cryptMock, $this->configMock, $this->userMock, $this->sessionMock, $this->logMock, $this->utilMock])->setMethods(['getPublicMasterKey', 'setSystemPrivateKey', 'getMasterKeyPassword'])->getMock(); $instance->expects($this->once())->method('getPublicMasterKey')->willReturn($masterKey); $instance->expects($this->any())->method('getMasterKeyPassword')->willReturn('masterKeyPassword'); $this->cryptMock->expects($this->any())->method('generateHeader')->willReturn('header'); if (empty($masterKey)) { $this->cryptMock->expects($this->once())->method('createKeyPair')->willReturn(['publicKey' => 'public', 'privateKey' => 'private']); $this->keyStorageMock->expects($this->once())->method('setSystemUserKey')->with('systemKeyId.publicKey', 'public', \OCA\Encryption\Crypto\Encryption::ID); $this->cryptMock->expects($this->once())->method('encryptPrivateKey')->with('private', 'masterKeyPassword', 'systemKeyId')->willReturn('EncryptedKey'); $instance->expects($this->once())->method('setSystemPrivateKey')->with('systemKeyId', 'headerEncryptedKey'); } else { $this->cryptMock->expects($this->never())->method('createKeyPair'); $this->keyStorageMock->expects($this->never())->method('setSystemUserKey'); $this->cryptMock->expects($this->never())->method('encryptPrivateKey'); $instance->expects($this->never())->method('setSystemPrivateKey'); } $instance->validateMasterKey(); }
/** * get public master key * * @return string */ public function getPublicMasterKey() { return $this->keyStorage->getSystemUserKey($this->masterKeyId . '.publicKey', Encryption::ID); }
/** * @param string $keyId * @param string $key * @return string returns openssl key */ public function setSystemPrivateKey($keyId, $key) { return $this->keyStorage->setSystemUserKey($keyId . '.' . $this->privateKeyId, $key, Encryption::ID); }