|
8 | 8 | namespace OC\Encryption; |
9 | 9 |
|
10 | 10 | use OC\Files\Filesystem; |
| 11 | +use OC\Files\Mount\HomeMountPoint; |
11 | 12 | use OC\Files\Storage\Wrapper\Encryption; |
12 | 13 | use OC\Files\View; |
13 | 14 | use OC\Memcache\ArrayCache; |
14 | 15 | use OCP\Encryption\IFile; |
15 | 16 | use OCP\Encryption\Keys\IStorage as EncryptionKeysStorage; |
| 17 | +use OCP\Exceptions\AppConfigTypeConflictException; |
16 | 18 | use OCP\Files\Mount\IMountPoint; |
17 | 19 | use OCP\Files\Storage\IDisableEncryptionStorage; |
18 | 20 | use OCP\Files\Storage\IStorage; |
| 21 | +use OCP\IAppConfig; |
19 | 22 | use OCP\IConfig; |
20 | 23 | use OCP\IGroupManager; |
21 | 24 | use OCP\IUserManager; |
@@ -57,32 +60,67 @@ public function wrapStorage(string $mountPoint, IStorage $storage, IMountPoint $ |
57 | 60 | 'mount' => $mount |
58 | 61 | ]; |
59 | 62 |
|
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 | + } |
66 | 69 |
|
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') |
83 | 116 | ); |
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; |
86 | 120 | } |
87 | 121 | } |
| 122 | + |
| 123 | + private function parseLegacyBoolString(string $value): bool { |
| 124 | + return in_array(strtolower(trim($value)), ['1', 'true', 'yes', 'on'], true); |
| 125 | + } |
88 | 126 | } |
0 commit comments