2016-03-30 17:20:37 -04:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2016-03-30 17:20:37 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-03-30 17:20:37 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Encryption;
|
|
|
|
|
|
|
|
|
|
use OC\Files\Filesystem;
|
|
|
|
|
use OC\Files\Storage\Wrapper\Encryption;
|
|
|
|
|
use OC\Files\View;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OC\Memcache\ArrayCache;
|
2023-08-29 19:00:29 -04:00
|
|
|
use OCP\Encryption\IFile;
|
2024-05-30 08:42:36 -04:00
|
|
|
use OCP\Encryption\Keys\IStorage as EncryptionKeysStorage;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\Files\Mount\IMountPoint;
|
2023-01-10 07:48:31 -05:00
|
|
|
use OCP\Files\Storage\IDisableEncryptionStorage;
|
|
|
|
|
use OCP\Files\Storage\IStorage;
|
2025-11-17 09:32:54 -05:00
|
|
|
use OCP\IConfig;
|
|
|
|
|
use OCP\IGroupManager;
|
|
|
|
|
use OCP\IUserManager;
|
|
|
|
|
use OCP\IUserSession;
|
|
|
|
|
use OCP\Server;
|
2021-03-11 05:32:29 -05:00
|
|
|
use Psr\Log\LoggerInterface;
|
2016-03-30 17:20:37 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class EncryptionWrapper
|
|
|
|
|
*
|
|
|
|
|
* applies the encryption storage wrapper
|
|
|
|
|
*
|
|
|
|
|
* @package OC\Encryption
|
|
|
|
|
*/
|
|
|
|
|
class EncryptionWrapper {
|
|
|
|
|
/**
|
|
|
|
|
* EncryptionWrapper constructor.
|
|
|
|
|
*/
|
2025-11-17 09:32:54 -05:00
|
|
|
public function __construct(
|
|
|
|
|
private ArrayCache $arrayCache,
|
|
|
|
|
private Manager $manager,
|
|
|
|
|
private LoggerInterface $logger,
|
2016-03-30 17:20:37 -04:00
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Wraps the given storage when it is not a shared storage
|
|
|
|
|
*
|
|
|
|
|
* @param string $mountPoint
|
2023-01-10 07:48:31 -05:00
|
|
|
* @param IStorage $storage
|
2016-03-30 17:20:37 -04:00
|
|
|
* @param IMountPoint $mount
|
2023-01-10 07:48:31 -05:00
|
|
|
* @param bool $force apply the wrapper even if the storage normally has encryption disabled, helpful for repair steps
|
|
|
|
|
* @return Encryption|IStorage
|
2016-03-30 17:20:37 -04:00
|
|
|
*/
|
2023-01-10 07:48:31 -05:00
|
|
|
public function wrapStorage(string $mountPoint, IStorage $storage, IMountPoint $mount, bool $force = false) {
|
2016-03-30 17:20:37 -04:00
|
|
|
$parameters = [
|
|
|
|
|
'storage' => $storage,
|
|
|
|
|
'mountPoint' => $mountPoint,
|
|
|
|
|
'mount' => $mount
|
|
|
|
|
];
|
|
|
|
|
|
2023-01-10 07:48:31 -05:00
|
|
|
if ($force || (!$storage->instanceOfStorage(IDisableEncryptionStorage::class) && $mountPoint !== '/')) {
|
2025-11-17 09:32:54 -05:00
|
|
|
$user = Server::get(IUserSession::class)->getUser();
|
2016-03-30 17:20:37 -04:00
|
|
|
$mountManager = Filesystem::getMountManager();
|
|
|
|
|
$uid = $user ? $user->getUID() : null;
|
2025-11-17 09:32:54 -05:00
|
|
|
$fileHelper = Server::get(IFile::class);
|
|
|
|
|
$keyStorage = Server::get(EncryptionKeysStorage::class);
|
2016-03-30 17:20:37 -04:00
|
|
|
|
|
|
|
|
$util = new Util(
|
|
|
|
|
new View(),
|
2025-11-17 09:32:54 -05:00
|
|
|
Server::get(IUserManager::class),
|
|
|
|
|
Server::get(IGroupManager::class),
|
|
|
|
|
Server::get(IConfig::class)
|
2016-03-30 17:20:37 -04:00
|
|
|
);
|
|
|
|
|
return new Encryption(
|
|
|
|
|
$parameters,
|
|
|
|
|
$this->manager,
|
|
|
|
|
$util,
|
|
|
|
|
$this->logger,
|
|
|
|
|
$fileHelper,
|
|
|
|
|
$uid,
|
|
|
|
|
$keyStorage,
|
|
|
|
|
$mountManager,
|
|
|
|
|
$this->arrayCache
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return $storage;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|