Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove legacy optimization when checking encryption status #868

Merged
merged 1 commit into from
Jan 16, 2025
Merged
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: 7 additions & 5 deletions lib/Connector/Sabre/APlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\File;
use OCA\EndToEndEncryption\E2EEnabledPathCache;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\IUserSession;
use Sabre\DAV\Exception\Conflict;
Expand All @@ -22,7 +22,6 @@ abstract class APlugin extends ServerPlugin {
protected ?Server $server = null;
protected IRootFolder $rootFolder;
protected IUserSession $userSession;
protected E2EEnabledPathCache $pathCache;

/**
* Should plugin be applied to the current node?
Expand All @@ -36,11 +35,9 @@ abstract class APlugin extends ServerPlugin {
public function __construct(
IRootFolder $rootFolder,
IUserSession $userSession,
E2EEnabledPathCache $pathCache,
) {
$this->rootFolder = $rootFolder;
$this->userSession = $userSession;
$this->pathCache = $pathCache;
}

/**
Expand Down Expand Up @@ -85,7 +82,12 @@ protected function getNodeForPath(string $path): INode {
*/
protected function isE2EEnabledPath(INode $node): bool {
if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
return $this->pathCache->isE2EEnabledPath($node->getNode());
$node = $node->getNode();
if ($node instanceof Folder) {
return $node->isEncrypted();
} else {
return $node->getParent()->isEncrypted();
}
}
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions lib/Connector/Sabre/LockPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
use OCA\DAV\Connector\Sabre\File;
use OCA\DAV\Upload\FutureFile;
use OCA\EndToEndEncryption\E2EEnabledPathCache;
use OCA\EndToEndEncryption\LockManager;
use OCA\EndToEndEncryption\UserAgentManager;
use OCP\AppFramework\Http;
Expand All @@ -34,8 +33,8 @@ public function __construct(IRootFolder $rootFolder,
IUserSession $userSession,
LockManager $lockManager,
UserAgentManager $userAgentManager,
E2EEnabledPathCache $pathCache) {
parent::__construct($rootFolder, $userSession, $pathCache);
) {
parent::__construct($rootFolder, $userSession);
$this->lockManager = $lockManager;
$this->userAgentManager = $userAgentManager;
}
Expand Down
21 changes: 7 additions & 14 deletions lib/Connector/Sabre/PropFindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
use OCA\DAV\Connector\Sabre\File;
use OCA\EndToEndEncryption\E2EEnabledPathCache;
use OCA\EndToEndEncryption\IMetaDataStorage;
use OCA\EndToEndEncryption\UserAgentManager;
use OCP\Files\Folder;
Expand All @@ -35,13 +34,12 @@ class PropFindPlugin extends APlugin {
public function __construct(
IRootFolder $rootFolder,
IUserSession $userSession,
E2EEnabledPathCache $pathCache,
private UserAgentManager $userAgentManager,
private IRequest $request,
private IMetaDataStorage $metaDataStorage,
private ?Folder $userFolder,
) {
parent::__construct($rootFolder, $userSession, $pathCache);
parent::__construct($rootFolder, $userSession);
}

/**
Expand All @@ -61,14 +59,14 @@ public function setE2EEProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
return;
}

// Only folders can be e2e encrypted, so we only respond for directories.
// Some properties are only for folders.
if ($node instanceof Directory) {
$propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) {
return $node->getFileInfo()->isEncrypted() ? '1' : '0';
return $this->isE2EEnabledPath($node) ? '1' : '0';
});

$propFind->handle(self::E2EE_METADATA_PROPERTYNAME, function () use ($node) {
if ($node->getFileInfo()->isEncrypted()) {
if ($this->isE2EEnabledPath($node)) {
return $this->metaDataStorage->getMetaData(
$this->userSession->getUser()->getUID(),
$node->getId(),
Expand All @@ -77,21 +75,16 @@ public function setE2EEProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
});

$propFind->handle(self::E2EE_METADATA_SIGNATURE_PROPERTYNAME, function () use ($node) {
if ($node->getFileInfo()->isEncrypted()) {
if ($this->isE2EEnabledPath($node)) {
return $this->metaDataStorage->readSignature($node->getId());
}
});
}

// This property was introduced to expose encryption status for both files and folders.
if ($this->userFolder !== null) {
$propFind->handle(self::E2EE_IS_ENCRYPTED, function () use ($node) {
if ($node instanceof File) {
$isEncrypted = $this->userFolder->getFirstNodeById($node->getFileInfo()->getParentId())->isEncrypted() ? '1' : '0';
} else {
$isEncrypted = $node->getFileInfo()->isEncrypted();
}

return $isEncrypted ? '1' : '0';
return $this->isE2EEnabledPath($node) ? '1' : '0';
});
}
}
Expand Down
111 changes: 0 additions & 111 deletions lib/E2EEnabledPathCache.php

This file was deleted.

Loading
Loading