From 111263cfb59b06d596dc128bb6fcb2b7a6017a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <1005065+DeepDiver1975@users.noreply.github.com> Date: Mon, 18 Oct 2021 21:03:37 +0200 Subject: [PATCH 1/3] feat: decrypt versions on IVersionedStorage --- lib/AppInfo/Application.php | 1 - lib/Crypto/Encryption.php | 13 ++++++++----- lib/Factory/EncDecAllFactory.php | 1 - lib/KeyManager.php | 15 +++++---------- tests/unit/Command/FixEncryptedVersionTest.php | 1 - tests/unit/KeyManagerTest.php | 9 --------- 6 files changed, 13 insertions(+), 27 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 27164e2..8ccdcc8 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -178,7 +178,6 @@ function (IAppContainer $c) { $server->getEncryptionKeyStorage(), $c->query('Crypt'), $server->getConfig(), - $server->getUserSession(), new Session($server->getSession()), $server->getLogger(), $c->query('Util') diff --git a/lib/Crypto/Encryption.php b/lib/Crypto/Encryption.php index 8d9b797..aa4df58 100644 --- a/lib/Crypto/Encryption.php +++ b/lib/Crypto/Encryption.php @@ -171,7 +171,7 @@ public function getDisplayName() { * written to the header, in case of a write operation * or if no additional data is needed return a empty array */ - public function begin($path, $user, $mode, array $header, array $accessList, $sourceFileOfRename = null) { + public function begin($path, $user, $mode, array $header, array $accessList, $sourceFileOfRename = null, $fileEncryptionVersion = null) { $this->path = $this->getPathToRealFile($path); $this->accessList = $accessList; $this->user = $user; @@ -198,10 +198,13 @@ public function begin($path, $user, $mode, array $header, array $accessList, $so // always use the version from the original file, also part files // need to have a correct version number if they get moved over to the // final location - if ($sourceFileOfRename !== null) { - $this->version = $this->keyManager->getVersion($sourceFileOfRename, new View()); - } else { - $this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($path), new View()); + $this->version = $fileEncryptionVersion; + if (!$this->version) { + if ($sourceFileOfRename !== null) { + $this->version = $this->keyManager->getVersion($sourceFileOfRename, new View()); + } else { + $this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($path), new View()); + } } if ( diff --git a/lib/Factory/EncDecAllFactory.php b/lib/Factory/EncDecAllFactory.php index 0f98d3f..346293d 100644 --- a/lib/Factory/EncDecAllFactory.php +++ b/lib/Factory/EncDecAllFactory.php @@ -161,7 +161,6 @@ public function getEncryptAllObj() { $this->encStorage, $this->getCryptoEngine(), $this->config, - $this->userSession, $this->encSession, $this->logger, $this->encUtil diff --git a/lib/KeyManager.php b/lib/KeyManager.php index 979da9f..5d9d16d 100644 --- a/lib/KeyManager.php +++ b/lib/KeyManager.php @@ -61,10 +61,6 @@ class KeyManager { * @var string */ private $masterKeyId; - /** - * @var string UserID - */ - private $keyId; /** * @var string */ @@ -100,7 +96,6 @@ class KeyManager { * @param IStorage $keyStorage * @param Crypt $crypt * @param IConfig $config - * @param IUserSession $userSession * @param Session $session * @param ILogger $log * @param Util $util @@ -109,7 +104,6 @@ public function __construct( IStorage $keyStorage, Crypt $crypt, IConfig $config, - IUserSession $userSession, Session $session, ILogger $log, Util $util @@ -136,7 +130,6 @@ public function __construct( $this->setPublicShareKeyIDAndMasterKeyId(); - $this->keyId = $userSession !== null && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : false; $this->log = $log; } @@ -539,11 +532,13 @@ public function userHasKeys($userId) { if ($privateKey && $publicKey) { return true; - } elseif (!$privateKey && !$publicKey) { + } + + if (!$privateKey && !$publicKey) { return false; - } else { - throw $exception; } + + throw $exception; } /** diff --git a/tests/unit/Command/FixEncryptedVersionTest.php b/tests/unit/Command/FixEncryptedVersionTest.php index 5a5c58b..583877c 100644 --- a/tests/unit/Command/FixEncryptedVersionTest.php +++ b/tests/unit/Command/FixEncryptedVersionTest.php @@ -72,7 +72,6 @@ public static function setUpBeforeClass(): void { \OC::$server->getEncryptionKeyStorage(), $crypt, \OC::$server->getConfig(), - \OC::$server->getUserSession(), $encryptionSession, \OC::$server->getLogger(), $encryptionUtil diff --git a/tests/unit/KeyManagerTest.php b/tests/unit/KeyManagerTest.php index 018dd82..afe7371 100644 --- a/tests/unit/KeyManagerTest.php +++ b/tests/unit/KeyManagerTest.php @@ -48,9 +48,6 @@ class KeyManagerTest extends TestCase { /** @var \OCA\Encryption\Crypto\Crypt|\PHPUnit\Framework\MockObject\MockObject */ private $cryptMock; - /** @var \OCP\IUserSession|\PHPUnit\Framework\MockObject\MockObject */ - private $userMock; - /** @var \OCA\Encryption\Session|\PHPUnit\Framework\MockObject\MockObject */ private $sessionMock; @@ -75,7 +72,6 @@ public function setUp(): void { $this->configMock->expects($this->any()) ->method('getAppValue') ->will($this->returnCallback([$this, 'returnAppValue'])); - $this->userMock = $this->createMock('OCP\IUserSession'); $this->sessionMock = $this->getMockBuilder('OCA\Encryption\Session') ->disableOriginalConstructor() ->getMock(); @@ -88,7 +84,6 @@ public function setUp(): void { $this->keyStorageMock, $this->cryptMock, $this->configMock, - $this->userMock, $this->sessionMock, $this->logMock, $this->utilMock @@ -261,7 +256,6 @@ public function testInit($useMasterKey) { $this->keyStorageMock, $this->cryptMock, $this->configMock, - $this->userMock, $this->sessionMock, $this->logMock, $this->utilMock @@ -518,7 +512,6 @@ public function testGetMasterKeyId() { $this->keyStorageMock, $this->cryptMock, $localConfigMock, - $this->userMock, $this->sessionMock, $this->logMock, $this->utilMock @@ -538,7 +531,6 @@ public function testGetPublicMasterKey() { $this->keyStorageMock, $this->cryptMock, $localConfigMock, - $this->userMock, $this->sessionMock, $this->logMock, $this->utilMock @@ -593,7 +585,6 @@ public function testValidateMasterKey($masterKey) { $this->keyStorageMock, $this->cryptMock, $localConfigMock, - $this->userMock, $this->sessionMock, $this->logMock, $this->utilMock From 93fc9108d3a7d3dcb25ed8b5271f9e8db20495e8 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 21 Oct 2021 18:26:23 +0545 Subject: [PATCH 2/3] Run CI against core feat/storage-based-encryption-key-location-2 --- .drone.star | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.drone.star b/.drone.star index 8536ad1..33c9540 100644 --- a/.drone.star +++ b/.drone.star @@ -50,7 +50,6 @@ config = { ], "servers": [ "daily-master-qa", - "latest", ], "extraSetup": [ { @@ -76,7 +75,6 @@ config = { ], "servers": [ "daily-master-qa", - "latest", ], "extraSetup": [ { @@ -101,7 +99,6 @@ config = { ], "servers": [ "daily-master-qa", - "latest", ], "emailNeeded": True, "extraSetup": [ @@ -128,7 +125,6 @@ config = { ], "servers": [ "daily-master-qa", - "latest", ], "extraSetup": [ { @@ -153,7 +149,6 @@ config = { ], "servers": [ "daily-master-qa", - "latest", ], "emailNeeded": True, "extraSetup": [ @@ -1868,7 +1863,7 @@ def installCore(ctx, version, db, useBundledApp): "image": "owncloudci/core", "pull": "always", "settings": { - "version": version, + "git_reference": "feat/storage-based-encryption-key-location-2", "core_path": dir["server"], "db_type": dbType, "db_name": database, From dac20b224ce30bcaf3da5bae22f749e8374e6df8 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 21 Oct 2021 18:49:34 +0545 Subject: [PATCH 3/3] Use owncloudci/core:nodejs14 image to install oC10 --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index 33c9540..5b47103 100644 --- a/.drone.star +++ b/.drone.star @@ -1860,7 +1860,7 @@ def installCore(ctx, version, db, useBundledApp): stepDefinition = { "name": "install-core", - "image": "owncloudci/core", + "image": "owncloudci/core:nodejs14", "pull": "always", "settings": { "git_reference": "feat/storage-based-encryption-key-location-2",