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

[24] allow enabling encryption for groupfolders #2068

Merged
merged 1 commit into from
Aug 31, 2022
Merged
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
4 changes: 3 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ public function register(IRegistrationContext $context): void {
};
$config = $c->get(IConfig::class);
$allowRootShare = $config->getAppValue('groupfolders', 'allow_root_share', 'true') === 'true';
$enableEncryption = $config->getAppValue('groupfolders', 'enable_encryption', 'false') === 'true';

return new MountProvider(
$c->getServer()->getGroupManager(),
@@ -90,7 +91,8 @@ public function register(IRegistrationContext $context): void {
$c->get(IMountProviderCollection::class),
$c->get(IDBConnection::class),
$c->get(ICacheFactory::class)->createLocal("groupfolders"),
$allowRootShare
$allowRootShare,
$enableEncryption
);
});

29 changes: 29 additions & 0 deletions lib/Mount/GroupFolderNoEncryptionStorage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\GroupFolders\Mount;

use OCP\Files\Storage\IDisableEncryptionStorage;

class GroupFolderNoEncryptionStorage extends GroupFolderStorage implements IDisableEncryptionStorage {
}
2 changes: 1 addition & 1 deletion lib/Mount/GroupFolderStorage.php
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
use OCP\IUser;
use OCP\IUserSession;

class GroupFolderStorage extends Quota implements IDisableEncryptionStorage {
class GroupFolderStorage extends Quota {
private int $folderId;
private ICacheEntry $rootEntry;
private IUserSession $userSession;
11 changes: 0 additions & 11 deletions lib/Mount/GroupMountPoint.php
Original file line number Diff line number Diff line change
@@ -36,17 +36,6 @@ public function getMountType() {
return 'group';
}

public function getOption($name, $default) {
$options = $this->getOptions();
return isset($options[$name]) ? $options[$name] : $default;
}

public function getOptions() {
$options = parent::getOptions();
$options['encrypt'] = false;
return $options;
}

public function getFolderId(): int {
return $this->folderId;
}
32 changes: 23 additions & 9 deletions lib/Mount/MountProvider.php
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ class MountProvider implements IMountProvider {
private ICache $cache;
private ?int $rootStorageId = null;
private bool $allowRootShare;
private bool $enableEncryption;

public function __construct(
IGroupManager $groupProvider,
@@ -83,7 +84,8 @@ public function __construct(
IMountProviderCollection $mountProviderCollection,
IDBConnection $connection,
ICache $cache,
bool $allowRootShare
bool $allowRootShare,
bool $enableEncryption
) {
$this->groupProvider = $groupProvider;
$this->folderManager = $folderManager;
@@ -96,6 +98,7 @@ public function __construct(
$this->connection = $connection;
$this->cache = $cache;
$this->allowRootShare = $allowRootShare;
$this->enableEncryption = $enableEncryption;
}

private function getRootStorageId(): int {
@@ -208,14 +211,25 @@ public function getMount(int $id, string $mountPoint, int $permissions, int $quo
'storage' => $storage,
'root' => $rootPath
]);
$quotaStorage = new GroupFolderStorage([
'storage' => $baseStorage,
'quota' => $quota,
'folder_id' => $id,
'rootCacheEntry' => $cacheEntry,
'userSession' => $this->userSession,
'mountOwner' => $user,
]);
if ($this->enableEncryption) {
$quotaStorage = new GroupFolderStorage([
'storage' => $baseStorage,
'quota' => $quota,
'folder_id' => $id,
'rootCacheEntry' => $cacheEntry,
'userSession' => $this->userSession,
'mountOwner' => $user,
]);
} else {
$quotaStorage = new GroupFolderNoEncryptionStorage([
'storage' => $baseStorage,
'quota' => $quota,
'folder_id' => $id,
'rootCacheEntry' => $cacheEntry,
'userSession' => $this->userSession,
'mountOwner' => $user,
]);
}
$maskedStore = new PermissionsMask([
'storage' => $quotaStorage,
'mask' => $permissions
42 changes: 23 additions & 19 deletions tests/stub.phpstub
Original file line number Diff line number Diff line change
@@ -61,15 +61,15 @@ namespace OCA\Files_Trashbin\Trash {

interface ITrashItem extends FileInfo {
public function getTrashBackend(): ITrashBackend;

public function getOriginalLocation(): string;

public function getDeletedTime(): int;

public function getTrashPath(): string;

public function isRootItem(): bool;

public function getUser(): IUser;

public function getTitle(): string;
@@ -603,10 +603,10 @@ namespace OC\Files\Mount {
protected $class;
protected $storageId;
protected $rootId = null;

/** @var int|null */
protected $mountId;

/**
* @param string|\OCP\Files\Storage\IStorage $storage
* @param string $mountpoint
@@ -619,7 +619,7 @@ namespace OC\Files\Mount {
public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) {
throw new \Exception('stub');
}

/**
* get complete path to the mount point, relative to data/
*
@@ -628,7 +628,7 @@ namespace OC\Files\Mount {
public function getMountPoint() {
throw new \Exception('stub');
}

/**
* Sets the mount point path, relative to data/
*
@@ -637,43 +637,43 @@ namespace OC\Files\Mount {
public function setMountPoint($mountPoint) {
throw new \Exception('stub');
}

/**
* @return \OCP\Files\Storage\IStorage
*/
public function getStorage() {
throw new \Exception('stub');
}

/**
* @return string
*/
public function getStorageId() {
throw new \Exception('stub');
}

/**
* @return int
*/
public function getNumericStorageId() {
throw new \Exception('stub');
}

/**
* @param string $path
* @return string
*/
public function getInternalPath($path) {
throw new \Exception('stub');
}

/**
* @param callable $wrapper
*/
public function wrapStorage($wrapper) {
throw new \Exception('stub');
}

/**
* Get a mount option
*
@@ -684,7 +684,7 @@ namespace OC\Files\Mount {
public function getOption($name, $default) {
throw new \Exception('stub');
}

/**
* Get all options for the mount
*
@@ -693,18 +693,18 @@ namespace OC\Files\Mount {
public function getOptions() {
throw new \Exception('stub');
}

/**
* @return int
*/
public function getStorageRootId() {
throw new \Exception('stub');
}

public function getMountId() {
throw new \Exception('stub');
}

public function getMountType() {
throw new \Exception('stub');
}
@@ -915,3 +915,7 @@ namespace OC\Files\Storage\Wrapper{
public function getQuota() {}
}
}

namespace OCP\Files\Mount\ISystemMountPoint {
interface ISystemMountPoint {}
}