diff options
author | Robin Appelman <robin@icewind.nl> | 2023-01-10 13:48:31 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2023-08-31 19:46:47 +0200 |
commit | e4f85226c575d7013bedf6bfcccead006d97ceb9 (patch) | |
tree | 6319ef37adf1ec247bed806c0ba357bad7c95135 /lib/private/Encryption | |
parent | a3d37c531a91f39ade3c6c9aa860744bfd452097 (diff) | |
download | nextcloud-server-e4f85226c575d7013bedf6bfcccead006d97ceb9.tar.gz nextcloud-server-e4f85226c575d7013bedf6bfcccead006d97ceb9.zip |
extend fix-key-location to handle cases from broken cross-storage moves
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Encryption')
-rw-r--r-- | lib/private/Encryption/EncryptionWrapper.php | 12 | ||||
-rw-r--r-- | lib/private/Encryption/Manager.php | 7 | ||||
-rw-r--r-- | lib/private/Encryption/Util.php | 28 |
3 files changed, 42 insertions, 5 deletions
diff --git a/lib/private/Encryption/EncryptionWrapper.php b/lib/private/Encryption/EncryptionWrapper.php index 37264e81823..e58b3656593 100644 --- a/lib/private/Encryption/EncryptionWrapper.php +++ b/lib/private/Encryption/EncryptionWrapper.php @@ -29,7 +29,8 @@ use OC\Files\Storage\Wrapper\Encryption; use OC\Files\View; use OC\Memcache\ArrayCache; use OCP\Files\Mount\IMountPoint; -use OCP\Files\Storage; +use OCP\Files\Storage\IDisableEncryptionStorage; +use OCP\Files\Storage\IStorage; use Psr\Log\LoggerInterface; /** @@ -64,18 +65,19 @@ class EncryptionWrapper { * Wraps the given storage when it is not a shared storage * * @param string $mountPoint - * @param Storage $storage + * @param IStorage $storage * @param IMountPoint $mount - * @return Encryption|Storage + * @param bool $force apply the wrapper even if the storage normally has encryption disabled, helpful for repair steps + * @return Encryption|IStorage */ - public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) { + public function wrapStorage(string $mountPoint, IStorage $storage, IMountPoint $mount, bool $force = false) { $parameters = [ 'storage' => $storage, 'mountPoint' => $mountPoint, 'mount' => $mount ]; - if (!$storage->instanceOfStorage(Storage\IDisableEncryptionStorage::class) && $mountPoint !== '/') { + if ($force || (!$storage->instanceOfStorage(IDisableEncryptionStorage::class) && $mountPoint !== '/')) { $user = \OC::$server->getUserSession()->getUser(); $mountManager = Filesystem::getMountManager(); $uid = $user ? $user->getUID() : null; diff --git a/lib/private/Encryption/Manager.php b/lib/private/Encryption/Manager.php index f751bd94b28..28bee7dacb7 100644 --- a/lib/private/Encryption/Manager.php +++ b/lib/private/Encryption/Manager.php @@ -32,6 +32,8 @@ use OC\Memcache\ArrayCache; use OC\ServiceUnavailableException; use OCP\Encryption\IEncryptionModule; use OCP\Encryption\IManager; +use OCP\Files\Mount\IMountPoint; +use OCP\Files\Storage\IStorage; use OCP\IConfig; use OCP\IL10N; use Psr\Log\LoggerInterface; @@ -234,6 +236,11 @@ class Manager implements IManager { } } + public function forceWrapStorage(IMountPoint $mountPoint, IStorage $storage) { + $encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger); + return $encryptionWrapper->wrapStorage($mountPoint->getMountPoint(), $storage, $mountPoint, true); + } + /** * check if key storage is ready diff --git a/lib/private/Encryption/Util.php b/lib/private/Encryption/Util.php index a468908ffc8..a828483265b 100644 --- a/lib/private/Encryption/Util.php +++ b/lib/private/Encryption/Util.php @@ -357,4 +357,32 @@ class Util { public function getKeyStorageRoot(): string { return $this->config->getAppValue('core', 'encryption_key_storage_root', ''); } + + /** + * parse raw header to array + * + * @param string $rawHeader + * @return array + */ + public function parseRawHeader(string $rawHeader) { + $result = []; + if (str_starts_with($rawHeader, Util::HEADER_START)) { + $header = $rawHeader; + $endAt = strpos($header, Util::HEADER_END); + if ($endAt !== false) { + $header = substr($header, 0, $endAt + strlen(Util::HEADER_END)); + + // +1 to not start with an ':' which would result in empty element at the beginning + $exploded = explode(':', substr($header, strlen(Util::HEADER_START) + 1)); + + $element = array_shift($exploded); + while ($element !== Util::HEADER_END && $element !== null) { + $result[$element] = array_shift($exploded); + $element = array_shift($exploded); + } + } + } + + return $result; + } } |