Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/encryption/lib/Users/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@

use OCA\Encryption\Crypto\Crypt;
use OCA\Encryption\KeyManager;
use OCP\ICache;
use OCP\ICacheFactory;

class Setup {
private readonly ICache $cache;

public function __construct(
private Crypt $crypt,
private KeyManager $keyManager,
ICacheFactory $cacheFactory,
) {
$this->cache = $cacheFactory->createLocal('encryption-setup');
}

/**
Expand All @@ -35,7 +40,10 @@ public function setupUser($uid, $password) {
* make sure that all system keys exists
*/
public function setupSystem() {
$this->keyManager->validateShareKey();
$this->keyManager->validateMasterKey();
if (!$this->cache->get('keys-validated')) {
$this->keyManager->validateShareKey();
$this->keyManager->validateMasterKey();
$this->cache->set('keys-validated', true);
}
}
}
3 changes: 3 additions & 0 deletions apps/encryption/tests/Command/FixEncryptedVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use OC\Files\View;
use OCA\Encryption\Command\FixEncryptedVersion;
use OCA\Encryption\KeyManager;
use OCA\Encryption\Util;
use OCP\Encryption\IManager;
use OCP\Files\ISetupManager;
Expand Down Expand Up @@ -49,6 +50,8 @@ class FixEncryptedVersionTest extends TestCase {

public function setUp(): void {
parent::setUp();
Server::get(KeyManager::class)->validateMasterKey();
Server::get(KeyManager::class)->validateShareKey();

Server::get(IAppConfig::class)->setValueBool('encryption', 'useMasterKey', true);

Expand Down
3 changes: 3 additions & 0 deletions apps/encryption/tests/EncryptedStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\Encryption;
use OC\Files\View;
use OCA\Encryption\KeyManager;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\Server;
Expand All @@ -30,6 +31,8 @@ class EncryptedStorageTest extends TestCase {
use UserTrait;

public function testMoveFromEncrypted(): void {
Server::get(KeyManager::class)->validateMasterKey();
Server::get(KeyManager::class)->validateShareKey();
$this->createUser('test1', 'test2');
$this->setupForUser('test1', 'test2');

Expand Down
11 changes: 10 additions & 1 deletion apps/encryption/tests/Users/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use OCA\Encryption\Crypto\Crypt;
use OCA\Encryption\KeyManager;
use OCA\Encryption\Users\Setup;
use OCP\ICache;
use OCP\ICacheFactory;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

Expand All @@ -32,9 +34,16 @@ protected function setUp(): void {
->disableOriginalConstructor()
->getMock();

$cache = $this->createMock(ICache::class);
$cacheFactory = $this->createMock(ICacheFactory::class);
$cacheFactory->method('createLocal')
->willReturn($cache);

$this->instance = new Setup(
$this->cryptMock,
$this->keyManagerMock);
$this->keyManagerMock,
$cacheFactory,
);
}


Expand Down
Loading