Skip to content

Commit

Permalink
feat: encryption keys location can be specified by the storage implem…
Browse files Browse the repository at this point in the history
…entation
  • Loading branch information
DeepDiver1975 committed Jul 27, 2023
1 parent 515d81b commit faae8d8
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 84 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/39091
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Change: Allow storage implementations to have their own encryption key storage

The default encryption key storage location is not suitable for all storage
implementations because e.g. the storage is not linked to a user.
This is required for files_spaces.

https://github.com/owncloud/core/pull/39091
15 changes: 14 additions & 1 deletion lib/private/Encryption/Keys/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OC\Files\Filesystem;
use OC\Files\View;
use OCP\Encryption\Keys\IStorage;
use OCP\Files\Mount\IMountManager;
use OCP\IUserSession;
use OC\User\NoUserException;

Expand Down Expand Up @@ -58,13 +59,17 @@ class Storage implements IStorage {

/** @var string */
private $currentUser = null;
/**
* @var IMountManager
*/
private $mountManager;

/**
* @param View $view view
* @param Util $util encryption util class
* @param IUserSession $session user session
*/
public function __construct(View $view, Util $util, IUserSession $session) {
public function __construct(View $view, Util $util, IUserSession $session, IMountManager $mountManager) {
$this->view = $view;
$this->util = $util;

Expand All @@ -75,6 +80,7 @@ public function __construct(View $view, Util $util, IUserSession $session) {
if ($session !== null && $session->getUser() !== null) {
$this->currentUser = $session->getUser()->getUID();
}
$this->mountManager = $mountManager;
}

/**
Expand Down Expand Up @@ -274,6 +280,13 @@ private function setKey($path, $key) {
* @return string
*/
private function getFileKeyDir($encryptionModuleId, $path) {
# ask the storage implementation for the key storage
$mount = $this->mountManager->find($path);
$keyPath = $mount ? $mount->getStorage()->getEncryptionFileKeyDirectory($encryptionModuleId, $mount->getInternalPath($path)) : null;
if ($keyPath) {
return $keyPath;
}

list($owner, $filename) = $this->util->getUidAndFilename($path);

// in case of system wide mount points the keys are stored directly in the data directory
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -797,4 +797,8 @@ public function getLocks($internalPath, $returnChildLocks = false) {
return $lock;
}, $locks);
}

public function getEncryptionFileKeyDirectory(string $encryptionModuleId, string $path): ?string {
return null;
}
}
2 changes: 2 additions & 0 deletions lib/private/Files/Storage/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@ public function releaseLock($path, $type, ILockingProvider $provider);
* @throws \OCP\Lock\LockedException
*/
public function changeLock($path, $type, ILockingProvider $provider);

public function getEncryptionFileKeyDirectory(string $encryptionModuleId, string $path): ?string;
}
4 changes: 4 additions & 0 deletions lib/private/Files/Storage/Wrapper/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,4 +651,8 @@ public function getLocks($internalPath, $returnChildLocks = false) {

return [];
}

public function getEncryptionFileKeyDirectory(string $encryptionModuleId, string $path): ?string {
return $this->getWrapperStorage()->getEncryptionFileKeyDirectory($encryptionModuleId, $path);
}
}
3 changes: 2 additions & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public function __construct($webRoot, \OC\Config $config) {
return new Encryption\Keys\Storage(
$view,
$util,
$c->getUserSession()
$c->getUserSession(),
$c->getMountManager()
);
});
$this->registerService('TagMapper', function (Server $c) {
Expand Down
Loading

0 comments on commit faae8d8

Please sign in to comment.