Skip to content

Commit 296977d

Browse files
authored
Merge pull request #59315 from nextcloud/backport/59202/stable32
[stable32] fix: cache validation of system keys
2 parents 7b54174 + e1e5671 commit 296977d

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

apps/encryption/lib/Users/Setup.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99

1010
use OCA\Encryption\Crypto\Crypt;
1111
use OCA\Encryption\KeyManager;
12+
use OCP\ICache;
13+
use OCP\ICacheFactory;
1214

1315
class Setup {
16+
private readonly ICache $cache;
1417

1518
public function __construct(
1619
private Crypt $crypt,
1720
private KeyManager $keyManager,
21+
ICacheFactory $cacheFactory,
1822
) {
23+
$this->cache = $cacheFactory->createLocal('encryption-setup');
1924
}
2025

2126
/**
@@ -35,7 +40,10 @@ public function setupUser($uid, $password) {
3540
* make sure that all system keys exists
3641
*/
3742
public function setupSystem() {
38-
$this->keyManager->validateShareKey();
39-
$this->keyManager->validateMasterKey();
43+
if (!$this->cache->get('keys-validated')) {
44+
$this->keyManager->validateShareKey();
45+
$this->keyManager->validateMasterKey();
46+
$this->cache->set('keys-validated', true);
47+
}
4048
}
4149
}

apps/encryption/tests/Command/FixEncryptedVersionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use OC\Files\View;
1414
use OCA\Encryption\Command\FixEncryptedVersion;
15+
use OCA\Encryption\KeyManager;
1516
use OCA\Encryption\Util;
1617
use OCP\Files\IRootFolder;
1718
use OCP\IConfig;
@@ -47,6 +48,8 @@ class FixEncryptedVersionTest extends TestCase {
4748

4849
public function setUp(): void {
4950
parent::setUp();
51+
Server::get(KeyManager::class)->validateMasterKey();
52+
Server::get(KeyManager::class)->validateShareKey();
5053

5154
Server::get(IConfig::class)->setAppValue('encryption', 'useMasterKey', '1');
5255

apps/encryption/tests/EncryptedStorageTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OC\Files\Storage\Temporary;
1212
use OC\Files\Storage\Wrapper\Encryption;
1313
use OC\Files\View;
14+
use OCA\Encryption\KeyManager;
1415
use OCP\Files\Mount\IMountManager;
1516
use OCP\Files\Storage\IDisableEncryptionStorage;
1617
use OCP\Server;
@@ -32,6 +33,8 @@ class EncryptedStorageTest extends TestCase {
3233
use UserTrait;
3334

3435
public function testMoveFromEncrypted(): void {
36+
Server::get(KeyManager::class)->validateMasterKey();
37+
Server::get(KeyManager::class)->validateShareKey();
3538
$this->createUser('test1', 'test2');
3639
$this->setupForUser('test1', 'test2');
3740

apps/encryption/tests/Users/SetupTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use OCA\Encryption\Crypto\Crypt;
1313
use OCA\Encryption\KeyManager;
1414
use OCA\Encryption\Users\Setup;
15+
use OCP\ICache;
16+
use OCP\ICacheFactory;
1517
use PHPUnit\Framework\MockObject\MockObject;
1618
use Test\TestCase;
1719

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

37+
$cache = $this->createMock(ICache::class);
38+
$cacheFactory = $this->createMock(ICacheFactory::class);
39+
$cacheFactory->method('createLocal')
40+
->willReturn($cache);
41+
3542
$this->instance = new Setup(
3643
$this->cryptMock,
37-
$this->keyManagerMock);
44+
$this->keyManagerMock,
45+
$cacheFactory,
46+
);
3847
}
3948

4049

0 commit comments

Comments
 (0)