Skip to content

Commit 8ce989d

Browse files
cuppettclaude
andcommitted
fix(encryption): Refactor EncryptionWrapper with HomeMountPoint support
Rewrite conditional flow to use early-return guards: skip IDisableEncryptionStorage, skip the root mount, respect encryptHomeStorage for HomeMountPoints. Uses IAppConfig for the encryptHomeStorage setting with a legacy string fallback for the upgrade window. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Stephen Cuppett <steve@cuppett.com>
1 parent b81a45b commit 8ce989d

1 file changed

Lines changed: 62 additions & 24 deletions

File tree

lib/private/Encryption/EncryptionWrapper.php

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
namespace OC\Encryption;
99

1010
use OC\Files\Filesystem;
11+
use OC\Files\Mount\HomeMountPoint;
1112
use OC\Files\Storage\Wrapper\Encryption;
1213
use OC\Files\View;
1314
use OC\Memcache\ArrayCache;
1415
use OCP\Encryption\IFile;
1516
use OCP\Encryption\Keys\IStorage as EncryptionKeysStorage;
17+
use OCP\Exceptions\AppConfigTypeConflictException;
1618
use OCP\Files\Mount\IMountPoint;
1719
use OCP\Files\Storage\IDisableEncryptionStorage;
1820
use OCP\Files\Storage\IStorage;
21+
use OCP\IAppConfig;
1922
use OCP\IConfig;
2023
use OCP\IGroupManager;
2124
use OCP\IUserManager;
@@ -57,32 +60,67 @@ public function wrapStorage(string $mountPoint, IStorage $storage, IMountPoint $
5760
'mount' => $mount
5861
];
5962

60-
if ($force || (!$storage->instanceOfStorage(IDisableEncryptionStorage::class) && $mountPoint !== '/')) {
61-
$user = Server::get(IUserSession::class)->getUser();
62-
$mountManager = Filesystem::getMountManager();
63-
$uid = $user ? $user->getUID() : null;
64-
$fileHelper = Server::get(IFile::class);
65-
$keyStorage = Server::get(EncryptionKeysStorage::class);
63+
// Only evaluate other conditions if not forced
64+
if (!$force) {
65+
// If a disabled storage medium, return basic storage
66+
if ($storage->instanceOfStorage(IDisableEncryptionStorage::class)) {
67+
return $storage;
68+
}
6669

67-
$util = new Util(
68-
new View(),
69-
Server::get(IUserManager::class),
70-
Server::get(IGroupManager::class),
71-
Server::get(IConfig::class)
72-
);
73-
return new Encryption(
74-
$parameters,
75-
$this->manager,
76-
$util,
77-
$this->logger,
78-
$fileHelper,
79-
$uid,
80-
$keyStorage,
81-
$mountManager,
82-
$this->arrayCache
70+
// Root mount point handling: skip encryption wrapper
71+
if ($mountPoint === '/') {
72+
return $storage;
73+
}
74+
75+
// Skip encryption for home mounts if encryptHomeStorage is disabled
76+
if ($mount instanceof HomeMountPoint && !$this->shouldEncryptHomeStorage()) {
77+
return $storage;
78+
}
79+
}
80+
81+
// Apply encryption wrapper
82+
$user = Server::get(IUserSession::class)->getUser();
83+
$mountManager = Filesystem::getMountManager();
84+
$uid = $user ? $user->getUID() : null;
85+
$fileHelper = Server::get(IFile::class);
86+
$keyStorage = Server::get(EncryptionKeysStorage::class);
87+
88+
$util = new Util(
89+
new View(),
90+
Server::get(IUserManager::class),
91+
Server::get(IGroupManager::class),
92+
Server::get(IConfig::class)
93+
);
94+
return new Encryption(
95+
$parameters,
96+
$this->manager,
97+
$util,
98+
$this->logger,
99+
$fileHelper,
100+
$uid,
101+
$keyStorage,
102+
$mountManager,
103+
$this->arrayCache
104+
);
105+
}
106+
107+
private function shouldEncryptHomeStorage(): bool {
108+
$appConfig = Server::get(IAppConfig::class);
109+
try {
110+
return $appConfig->getValueBool('encryption', 'encryptHomeStorage', true);
111+
} catch (AppConfigTypeConflictException) {
112+
// Stored as VALUE_STRING from a pre-upgrade installation.
113+
// RetypeEncryptionConfigKeys repair step will fix the type on occ upgrade.
114+
return $this->parseLegacyBoolString(
115+
$appConfig->getValueString('encryption', 'encryptHomeStorage', '1')
83116
);
84-
} else {
85-
return $storage;
117+
} catch (\Throwable) {
118+
// DB not ready (e.g. oc_appconfig does not yet exist during install).
119+
return true;
86120
}
87121
}
122+
123+
private function parseLegacyBoolString(string $value): bool {
124+
return in_array(strtolower(trim($value)), ['1', 'true', 'yes', 'on'], true);
125+
}
88126
}

0 commit comments

Comments
 (0)