Skip to content

Commit

Permalink
feat: decrypt versions on IVersionedStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Oct 18, 2021
1 parent 10a073d commit a43b498
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 27 deletions.
1 change: 0 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
13 changes: 8 additions & 5 deletions lib/Crypto/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 (
Expand Down
1 change: 0 additions & 1 deletion lib/Factory/EncDecAllFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public function getEncryptAllObj() {
$this->encStorage,
$this->getCryptoEngine(),
$this->config,
$this->userSession,
$this->encSession,
$this->logger,
$this->encUtil
Expand Down
15 changes: 5 additions & 10 deletions lib/KeyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ class KeyManager {
* @var string
*/
private $masterKeyId;
/**
* @var string UserID
*/
private $keyId;
/**
* @var string
*/
Expand Down Expand Up @@ -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
Expand All @@ -109,7 +104,6 @@ public function __construct(
IStorage $keyStorage,
Crypt $crypt,
IConfig $config,
IUserSession $userSession,
Session $session,
ILogger $log,
Util $util
Expand All @@ -136,7 +130,6 @@ public function __construct(

$this->setPublicShareKeyIDAndMasterKeyId();

$this->keyId = $userSession !== null && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : false;
$this->log = $log;
}

Expand Down Expand Up @@ -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;
}

/**
Expand Down
1 change: 0 additions & 1 deletion tests/unit/Command/FixEncryptedVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public static function setUpBeforeClass(): void {
\OC::$server->getEncryptionKeyStorage(),
$crypt,
\OC::$server->getConfig(),
\OC::$server->getUserSession(),
$encryptionSession,
\OC::$server->getLogger(),
$encryptionUtil
Expand Down
9 changes: 0 additions & 9 deletions tests/unit/KeyManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -88,7 +84,6 @@ public function setUp(): void {
$this->keyStorageMock,
$this->cryptMock,
$this->configMock,
$this->userMock,
$this->sessionMock,
$this->logMock,
$this->utilMock
Expand Down Expand Up @@ -261,7 +256,6 @@ public function testInit($useMasterKey) {
$this->keyStorageMock,
$this->cryptMock,
$this->configMock,
$this->userMock,
$this->sessionMock,
$this->logMock,
$this->utilMock
Expand Down Expand Up @@ -518,7 +512,6 @@ public function testGetMasterKeyId() {
$this->keyStorageMock,
$this->cryptMock,
$localConfigMock,
$this->userMock,
$this->sessionMock,
$this->logMock,
$this->utilMock
Expand All @@ -538,7 +531,6 @@ public function testGetPublicMasterKey() {
$this->keyStorageMock,
$this->cryptMock,
$localConfigMock,
$this->userMock,
$this->sessionMock,
$this->logMock,
$this->utilMock
Expand Down Expand Up @@ -593,7 +585,6 @@ public function testValidateMasterKey($masterKey) {
$this->keyStorageMock,
$this->cryptMock,
$localConfigMock,
$this->userMock,
$this->sessionMock,
$this->logMock,
$this->utilMock
Expand Down

0 comments on commit a43b498

Please sign in to comment.