aboutsummaryrefslogtreecommitdiffstats
path: root/demos/effect/default.html
Commit message (Expand)AuthorAgeFilesLines
* Effect: Remove demos & visual tests of the transfer effectMichał Gołębiowski-Owczarek2024-09-161-4/+0
* Demos: Add device-width viewport meta to all demosJörn Zaefferer2015-09-301-0/+1
* Effects: Style updatesAlexander Schmitz2015-08-211-4/+4
* Effects: Update demos to use AMDAlexander Schmitz2015-07-211-20/+2
* Effects: Remove core event/alias and deprecated module dependenciesAlexander Schmitz2015-05-201-1/+1
* Effects: RewriteMike Sherov2014-12-101-2/+2
* Build: Reorganize external directoryScott González2014-06-241-1/+1
* Effect demo: Change anchor to button elementJörn Zaefferer2014-04-241-1/+1
* All: Rename jquery.js to exclude version in filenameJörn Zaefferer2014-03-051-1/+1
* All: Rename all files, removing the "jquery.ui." prefix;Rafael Xavier de Souza2014-01-241-17/+17
* Updating jQuery to 1.10.2.Bruno M. Custódio2013-07-051-1/+1
* Effect: Give puff-effect and size-effect its own files. Previously, they were...Rafael Xavier de Souza2013-06-221-0/+2
* Updating 'jQuery' to 1.9.1.Bruno M. Custódio2013-02-051-1/+1
* Updating to jQuery 1.9.0Kris Borchers2013-01-171-1/+1
* Upgrade jQuery to 1.8.3.Scott González2012-11-141-1/+1
* Upgrade jQuery to 1.8.2.Scott González2012-09-201-1/+1
* Demos: Cleanup.Scott González2012-09-101-12/+5
* Upgrade jQuery to 1.8.0.Scott González2012-08-131-1/+1
* Tests: Fixining jquery include versionCorey Frang2012-07-231-1/+1
* Build: Splitting Release Coverage build into threeCorey Frang2012-07-231-1/+1
* Effects: Renamed all files.Scott González2012-06-151-14/+14
* Upgrade jQuery to 1.7.2.Scott González2012-03-221-1/+1
* Upgrade jQuery to 1.7.1.Scott González2011-11-221-1/+1
* Upgrade jQuery to 1.7.Scott González2011-11-091-1/+1
* Upgraded jQuery to 1.6.4.Scott González2011-10-181-1/+1
* Upgrade jQuery to 1.6.2.Scott González2011-07-251-1/+1
* Switched to latest stable jQuery 1.5.1Richard Worth2011-03-021-1/+1
* Upgraded jQuery to 1.4.4.Scott González2010-11-121-1/+1
* Upgraded jQuery to 1.4.3.Scott González2010-10-211-1/+1
* Demos: Cleanup.Scott González2010-09-091-1/+1
* Effects demos (partial): Coding standards.Scott González2010-09-091-46/+48
* html pages: added HTML5 meta charset UTF-8 tag, changed DOCTYPE to uppercaseRichard Worth2010-03-121-1/+2
* Fixed #5182 - Update to jQuery 1.4.2Richard Worth2010-02-161-1/+1
* fixed #5163 - themes: css files need to be renamed to be consistent with js f...Richard Worth2010-02-161-1/+1
* switched to jQuery 1.4.1Richard Worth2010-01-271-1/+1
* switched to jQuery 1.4Richard Worth2010-01-201-1/+1
* Effects: Added fade effect. Needs documentation.Scott González2009-11-131-0/+2
* renamed all ui.*.js files to jquery.ui.*.js, all effects.*.js files to jquery...Richard Worth2009-09-171-13/+13
* demos: effects - added return false; to button click handlersRichard Worth2009-03-021-1/+2
* updated demos to a standard format - class animations do not seem to work in ...Scott Jehl2009-02-271-7/+4
* effect method demos page - possibly a good solution for thisScott Jehl2009-02-261-0/+106
9'>backport/47515/stable29 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Encryption/Manager.php
blob: a07c778bfe02a52491abbf98fd8c2b56d648eee7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php

/**
 * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
 * SPDX-License-Identifier: AGPL-3.0-only
 */
namespace OC\Encryption;

use OC\Encryption\Keys\Storage;
use OC\Files\Filesystem;
use OC\Files\View;
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;

class Manager implements IManager {
	protected array $encryptionModules;

	public function __construct(
		protected IConfig $config,
		protected LoggerInterface $logger,
		protected IL10N $l,
		protected View $rootView,
		protected Util $util,
		protected ArrayCache $arrayCache,
	) {
		$this->encryptionModules = [];
	}

	/**
	 * Check if encryption is enabled
	 *
	 * @return bool true if enabled, false if not
	 */
	public function isEnabled() {
		$installed = $this->config->getSystemValueBool('installed', false);
		if (!$installed) {
			return false;
		}

		$enabled = $this->config->getAppValue('core', 'encryption_enabled', 'no');
		return $enabled === 'yes';
	}

	/**
	 * check if new encryption is ready
	 *
	 * @return bool
	 * @throws ServiceUnavailableException
	 */
	public function isReady() {
		if ($this->isKeyStorageReady() === false) {
			throw new ServiceUnavailableException('Key Storage is not ready');
		}

		return true;
	}

	/**
	 * @param string $user
	 */
	public function isReadyForUser($user) {
		if (!$this->isReady()) {
			return false;
		}

		foreach ($this->getEncryptionModules() as $module) {
			/** @var IEncryptionModule $m */
			$m = call_user_func($module['callback']);
			if (!$m->isReadyForUser($user)) {
				return false;
			}
		}

		return true;
	}

	/**
	 * Registers an callback function which must return an encryption module instance
	 *
	 * @param string $id
	 * @param string $displayName
	 * @param callable $callback
	 * @throws Exceptions\ModuleAlreadyExistsException
	 */
	public function registerEncryptionModule($id, $displayName, callable $callback) {
		if (isset($this->encryptionModules[$id])) {
			throw new Exceptions\ModuleAlreadyExistsException($id, $displayName);
		}

		$this->encryptionModules[$id] = [
			'id' => $id,
			'displayName' => $displayName,
			'callback' => $callback,
		];

		$defaultEncryptionModuleId = $this->getDefaultEncryptionModuleId();

		if (empty($defaultEncryptionModuleId)) {
			$this->setDefaultEncryptionModule($id);
		}
	}

	/**
	 * Unregisters an encryption module
	 *
	 * @param string $moduleId
	 */
	public function unregisterEncryptionModule($moduleId) {
		unset($this->encryptionModules[$moduleId]);
	}

	/**
	 * get a list of all encryption modules
	 *
	 * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]]
	 */
	public function getEncryptionModules() {
		return $this->encryptionModules;
	}

	/**
	 * get a specific encryption module
	 *
	 * @param string $moduleId
	 * @return IEncryptionModule
	 * @throws Exceptions\ModuleDoesNotExistsException
	 */
	public function getEncryptionModule($moduleId = '') {
		if (empty($moduleId)) {
			return $this->getDefaultEncryptionModule();
		}
		if (isset($this->encryptionModules[$moduleId])) {
			return call_user_func($this->encryptionModules[$moduleId]['callback']);
		}
		$message = "Module with ID: $moduleId does not exist.";
		$hint = $this->l->t('Module with ID: %s does not exist. Please enable it in your apps settings or contact your administrator.', [$moduleId]);
		throw new Exceptions\ModuleDoesNotExistsException($message, $hint);
	}

	/**
	 * get default encryption module
	 *
	 * @return \OCP\Encryption\IEncryptionModule
	 * @throws Exceptions\ModuleDoesNotExistsException
	 */
	protected function getDefaultEncryptionModule() {
		$defaultModuleId = $this->getDefaultEncryptionModuleId();
		if (empty($defaultModuleId)) {
			$message = 'No default encryption module defined';
			throw new Exceptions\ModuleDoesNotExistsException($message);
		}
		if (isset($this->encryptionModules[$defaultModuleId])) {
			return call_user_func($this->encryptionModules[$defaultModuleId]['callback']);
		}
		$message = 'Default encryption module not loaded';
		throw new Exceptions\ModuleDoesNotExistsException($message);
	}

	/**
	 * set default encryption module Id
	 *
	 * @param string $moduleId
	 * @return bool
	 */
	public function setDefaultEncryptionModule($moduleId) {
		try {
			$this->getEncryptionModule($moduleId);
		} catch (\Exception $e) {
			return false;
		}

		$this->config->setAppValue('core', 'default_encryption_module', $moduleId);
		return true;
	}

	/**
	 * get default encryption module Id
	 *
	 * @return string
	 */
	public function getDefaultEncryptionModuleId() {
		return $this->config->getAppValue('core', 'default_encryption_module');
	}

	/**
	 * Add storage wrapper
	 */
	public function setupStorage() {
		// If encryption is disabled and there are no loaded modules it makes no sense to load the wrapper
		if (!empty($this->encryptionModules) || $this->isEnabled()) {
			$encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger);
			Filesystem::addStorageWrapper('oc_encryption', [$encryptionWrapper, 'wrapStorage'], 2);
		}
	}

	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
	 *
	 * @return bool
	 */
	protected function isKeyStorageReady() {
		$rootDir = $this->util->getKeyStorageRoot();

		// the default root is always valid
		if ($rootDir === '') {
			return true;
		}

		// check if key storage is mounted correctly
		if ($this->rootView->file_exists($rootDir . '/' . Storage::KEY_STORAGE_MARKER)) {
			return true;
		}

		return false;
	}
}