Passed
Push — master ( d23e96...1bc100 )
by Roeland
11:25 queued 10s
created
apps/encryption/lib/Command/EnableMasterKey.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -34,54 +34,54 @@
 block discarded – undo
34 34
 
35 35
 class EnableMasterKey extends Command {
36 36
 
37
-	/** @var Util */
38
-	protected $util;
39
-
40
-	/** @var IConfig */
41
-	protected $config;
42
-
43
-	/** @var  QuestionHelper */
44
-	protected $questionHelper;
45
-
46
-	/**
47
-	 * @param Util $util
48
-	 * @param IConfig $config
49
-	 * @param QuestionHelper $questionHelper
50
-	 */
51
-	public function __construct(Util $util,
52
-								IConfig $config,
53
-								QuestionHelper $questionHelper) {
54
-
55
-		$this->util = $util;
56
-		$this->config = $config;
57
-		$this->questionHelper = $questionHelper;
58
-		parent::__construct();
59
-	}
60
-
61
-	protected function configure() {
62
-		$this
63
-			->setName('encryption:enable-master-key')
64
-			->setDescription('Enable the master key. Only available for fresh installations with no existing encrypted data! There is also no way to disable it again.');
65
-	}
66
-
67
-	protected function execute(InputInterface $input, OutputInterface $output) {
68
-
69
-		$isAlreadyEnabled = $this->util->isMasterKeyEnabled();
70
-
71
-		if($isAlreadyEnabled) {
72
-			$output->writeln('Master key already enabled');
73
-		} else {
74
-			$question = new ConfirmationQuestion(
75
-				'Warning: Only available for fresh installations with no existing encrypted data! '
76
-			. 'There is also no way to disable it again. Do you want to continue? (y/n) ', false);
77
-			if ($this->questionHelper->ask($input, $output, $question)) {
78
-				$this->config->setAppValue('encryption', 'useMasterKey', '1');
79
-				$output->writeln('Master key successfully enabled.');
80
-			} else {
81
-				$output->writeln('aborted.');
82
-			}
83
-		}
84
-
85
-	}
37
+    /** @var Util */
38
+    protected $util;
39
+
40
+    /** @var IConfig */
41
+    protected $config;
42
+
43
+    /** @var  QuestionHelper */
44
+    protected $questionHelper;
45
+
46
+    /**
47
+     * @param Util $util
48
+     * @param IConfig $config
49
+     * @param QuestionHelper $questionHelper
50
+     */
51
+    public function __construct(Util $util,
52
+                                IConfig $config,
53
+                                QuestionHelper $questionHelper) {
54
+
55
+        $this->util = $util;
56
+        $this->config = $config;
57
+        $this->questionHelper = $questionHelper;
58
+        parent::__construct();
59
+    }
60
+
61
+    protected function configure() {
62
+        $this
63
+            ->setName('encryption:enable-master-key')
64
+            ->setDescription('Enable the master key. Only available for fresh installations with no existing encrypted data! There is also no way to disable it again.');
65
+    }
66
+
67
+    protected function execute(InputInterface $input, OutputInterface $output) {
68
+
69
+        $isAlreadyEnabled = $this->util->isMasterKeyEnabled();
70
+
71
+        if($isAlreadyEnabled) {
72
+            $output->writeln('Master key already enabled');
73
+        } else {
74
+            $question = new ConfirmationQuestion(
75
+                'Warning: Only available for fresh installations with no existing encrypted data! '
76
+            . 'There is also no way to disable it again. Do you want to continue? (y/n) ', false);
77
+            if ($this->questionHelper->ask($input, $output, $question)) {
78
+                $this->config->setAppValue('encryption', 'useMasterKey', '1');
79
+                $output->writeln('Master key successfully enabled.');
80
+            } else {
81
+                $output->writeln('aborted.');
82
+            }
83
+        }
84
+
85
+    }
86 86
 
87 87
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
 
69 69
 		$isAlreadyEnabled = $this->util->isMasterKeyEnabled();
70 70
 
71
-		if($isAlreadyEnabled) {
71
+		if ($isAlreadyEnabled) {
72 72
 			$output->writeln('Master key already enabled');
73 73
 		} else {
74 74
 			$question = new ConfirmationQuestion(
Please login to merge, or discard this patch.
apps/encryption/lib/Hooks/Contracts/IHook.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@
 block discarded – undo
24 24
 
25 25
 
26 26
 interface IHook {
27
-	/**
28
-	 * Connects Hooks
29
-	 *
30
-	 * @return null
31
-	 */
32
-	public function addHooks();
27
+    /**
28
+     * Connects Hooks
29
+     *
30
+     * @return null
31
+     */
32
+    public function addHooks();
33 33
 }
Please login to merge, or discard this patch.
apps/encryption/lib/Crypto/Encryption.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 		$this->isWriteOperation = false;
178 178
 		$this->writeCache = '';
179 179
 
180
-		if($this->session->isReady() === false) {
180
+		if ($this->session->isReady() === false) {
181 181
 			// if the master key is enabled we can initialize encryption
182 182
 			// with a empty password and user name
183 183
 			if ($this->util->isMasterKeyEnabled()) {
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 		// always use the version from the original file, also part files
199 199
 		// need to have a correct version number if they get moved over to the
200 200
 		// final location
201
-		$this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($path), new View());
201
+		$this->version = (int) $this->keyManager->getVersion($this->stripPartFileExtension($path), new View());
202 202
 
203 203
 		if (
204 204
 			$mode === 'w'
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 			// if we read a part file we need to increase the version by 1
215 215
 			// because the version number was also increased by writing
216 216
 			// the part file
217
-			if(Scanner::isPartialFile($path)) {
217
+			if (Scanner::isPartialFile($path)) {
218 218
 				$this->version = $this->version + 1;
219 219
 			}
220 220
 		}
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 		if ($this->writeCache) {
301 301
 
302 302
 			// Concat writeCache to start of $data
303
-			$data = $this->writeCache . $data;
303
+			$data = $this->writeCache.$data;
304 304
 
305 305
 			// Clear the write cache, ready for reuse - it has been
306 306
 			// flushed and its old contents processed
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 					try {
403 403
 						$publicKeys[$user] = $this->keyManager->getPublicKey($user);
404 404
 					} catch (PublicKeyMissingException $e) {
405
-						$this->logger->warning('Could not encrypt file for ' . $user . ': ' . $e->getMessage());
405
+						$this->logger->warning('Could not encrypt file for '.$user.': '.$e->getMessage());
406 406
 					}
407 407
 				}
408 408
 			}
@@ -489,8 +489,8 @@  discard block
 block discarded – undo
489 489
 				// error message because in this case it means that the file was
490 490
 				// shared with the user at a point where the user didn't had a
491 491
 				// valid private/public key
492
-				$msg = 'Encryption module "' . $this->getDisplayName() .
493
-					'" is not able to read ' . $path;
492
+				$msg = 'Encryption module "'.$this->getDisplayName().
493
+					'" is not able to read '.$path;
494 494
 				$hint = $this->l->t('Can not read this file, probably this is a shared file. Please ask the file owner to reshare the file with you.');
495 495
 				$this->logger->warning($msg);
496 496
 				throw new DecryptionFailedException($msg, $hint);
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 		$realPath = $path;
533 533
 		$parts = explode('/', $path);
534 534
 		if ($parts[2] === 'files_versions') {
535
-			$realPath = '/' . $parts[1] . '/files/' . implode('/', array_slice($parts, 3));
535
+			$realPath = '/'.$parts[1].'/files/'.implode('/', array_slice($parts, 3));
536 536
 			$length = strrpos($realPath, '.');
537 537
 			$realPath = substr($realPath, 0, $length);
538 538
 		}
Please login to merge, or discard this patch.
Indentation   +553 added lines, -553 removed lines patch added patch discarded remove patch
@@ -45,557 +45,557 @@
 block discarded – undo
45 45
 
46 46
 class Encryption implements IEncryptionModule {
47 47
 
48
-	const ID = 'OC_DEFAULT_MODULE';
49
-	const DISPLAY_NAME = 'Default encryption module';
50
-
51
-	/**
52
-	 * @var Crypt
53
-	 */
54
-	private $crypt;
55
-
56
-	/** @var string */
57
-	private $cipher;
58
-
59
-	/** @var string */
60
-	private $path;
61
-
62
-	/** @var string */
63
-	private $user;
64
-
65
-	/** @var  array */
66
-	private $owner;
67
-
68
-	/** @var string */
69
-	private $fileKey;
70
-
71
-	/** @var string */
72
-	private $writeCache;
73
-
74
-	/** @var KeyManager */
75
-	private $keyManager;
76
-
77
-	/** @var array */
78
-	private $accessList;
79
-
80
-	/** @var boolean */
81
-	private $isWriteOperation;
82
-
83
-	/** @var Util */
84
-	private $util;
85
-
86
-	/** @var  Session */
87
-	private $session;
88
-
89
-	/** @var  ILogger */
90
-	private $logger;
91
-
92
-	/** @var IL10N */
93
-	private $l;
94
-
95
-	/** @var EncryptAll */
96
-	private $encryptAll;
97
-
98
-	/** @var  bool */
99
-	private $useMasterPassword;
100
-
101
-	/** @var DecryptAll  */
102
-	private $decryptAll;
103
-
104
-	/** @var int unencrypted block size if block contains signature */
105
-	private $unencryptedBlockSizeSigned = 6072;
106
-
107
-	/** @var int unencrypted block size */
108
-	private $unencryptedBlockSize = 6126;
109
-
110
-	/** @var int Current version of the file */
111
-	private $version = 0;
112
-
113
-	/** @var array remember encryption signature version */
114
-	private static $rememberVersion = [];
115
-
116
-
117
-	/**
118
-	 *
119
-	 * @param Crypt $crypt
120
-	 * @param KeyManager $keyManager
121
-	 * @param Util $util
122
-	 * @param Session $session
123
-	 * @param EncryptAll $encryptAll
124
-	 * @param DecryptAll $decryptAll
125
-	 * @param ILogger $logger
126
-	 * @param IL10N $il10n
127
-	 */
128
-	public function __construct(Crypt $crypt,
129
-								KeyManager $keyManager,
130
-								Util $util,
131
-								Session $session,
132
-								EncryptAll $encryptAll,
133
-								DecryptAll $decryptAll,
134
-								ILogger $logger,
135
-								IL10N $il10n) {
136
-		$this->crypt = $crypt;
137
-		$this->keyManager = $keyManager;
138
-		$this->util = $util;
139
-		$this->session = $session;
140
-		$this->encryptAll = $encryptAll;
141
-		$this->decryptAll = $decryptAll;
142
-		$this->logger = $logger;
143
-		$this->l = $il10n;
144
-		$this->owner = [];
145
-		$this->useMasterPassword = $util->isMasterKeyEnabled();
146
-	}
147
-
148
-	/**
149
-	 * @return string defining the technical unique id
150
-	 */
151
-	public function getId() {
152
-		return self::ID;
153
-	}
154
-
155
-	/**
156
-	 * In comparison to getKey() this function returns a human readable (maybe translated) name
157
-	 *
158
-	 * @return string
159
-	 */
160
-	public function getDisplayName() {
161
-		return self::DISPLAY_NAME;
162
-	}
163
-
164
-	/**
165
-	 * start receiving chunks from a file. This is the place where you can
166
-	 * perform some initial step before starting encrypting/decrypting the
167
-	 * chunks
168
-	 *
169
-	 * @param string $path to the file
170
-	 * @param string $user who read/write the file
171
-	 * @param string $mode php stream open mode
172
-	 * @param array $header contains the header data read from the file
173
-	 * @param array $accessList who has access to the file contains the key 'users' and 'public'
174
-	 *
175
-	 * @return array $header contain data as key-value pairs which should be
176
-	 *                       written to the header, in case of a write operation
177
-	 *                       or if no additional data is needed return a empty array
178
-	 */
179
-	public function begin($path, $user, $mode, array $header, array $accessList) {
180
-		$this->path = $this->getPathToRealFile($path);
181
-		$this->accessList = $accessList;
182
-		$this->user = $user;
183
-		$this->isWriteOperation = false;
184
-		$this->writeCache = '';
185
-
186
-		if($this->session->isReady() === false) {
187
-			// if the master key is enabled we can initialize encryption
188
-			// with a empty password and user name
189
-			if ($this->util->isMasterKeyEnabled()) {
190
-				$this->keyManager->init('', '');
191
-			}
192
-		}
193
-
194
-		if ($this->session->decryptAllModeActivated()) {
195
-			$encryptedFileKey = $this->keyManager->getEncryptedFileKey($this->path);
196
-			$shareKey = $this->keyManager->getShareKey($this->path, $this->session->getDecryptAllUid());
197
-			$this->fileKey = $this->crypt->multiKeyDecrypt($encryptedFileKey,
198
-				$shareKey,
199
-				$this->session->getDecryptAllKey());
200
-		} else {
201
-			$this->fileKey = $this->keyManager->getFileKey($this->path, $this->user);
202
-		}
203
-
204
-		// always use the version from the original file, also part files
205
-		// need to have a correct version number if they get moved over to the
206
-		// final location
207
-		$this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($path), new View());
208
-
209
-		if (
210
-			$mode === 'w'
211
-			|| $mode === 'w+'
212
-			|| $mode === 'wb'
213
-			|| $mode === 'wb+'
214
-		) {
215
-			$this->isWriteOperation = true;
216
-			if (empty($this->fileKey)) {
217
-				$this->fileKey = $this->crypt->generateFileKey();
218
-			}
219
-		} else {
220
-			// if we read a part file we need to increase the version by 1
221
-			// because the version number was also increased by writing
222
-			// the part file
223
-			if(Scanner::isPartialFile($path)) {
224
-				$this->version = $this->version + 1;
225
-			}
226
-		}
227
-
228
-		if ($this->isWriteOperation) {
229
-			$this->cipher = $this->crypt->getCipher();
230
-		} elseif (isset($header['cipher'])) {
231
-			$this->cipher = $header['cipher'];
232
-		} else {
233
-			// if we read a file without a header we fall-back to the legacy cipher
234
-			// which was used in <=oC6
235
-			$this->cipher = $this->crypt->getLegacyCipher();
236
-		}
237
-
238
-		return array('cipher' => $this->cipher, 'signed' => 'true');
239
-	}
240
-
241
-	/**
242
-	 * last chunk received. This is the place where you can perform some final
243
-	 * operation and return some remaining data if something is left in your
244
-	 * buffer.
245
-	 *
246
-	 * @param string $path to the file
247
-	 * @param int $position
248
-	 * @return string remained data which should be written to the file in case
249
-	 *                of a write operation
250
-	 * @throws PublicKeyMissingException
251
-	 * @throws \Exception
252
-	 * @throws \OCA\Encryption\Exceptions\MultiKeyEncryptException
253
-	 */
254
-	public function end($path, $position = 0) {
255
-		$result = '';
256
-		if ($this->isWriteOperation) {
257
-			// in case of a part file we remember the new signature versions
258
-			// the version will be set later on update.
259
-			// This way we make sure that other apps listening to the pre-hooks
260
-			// still get the old version which should be the correct value for them
261
-			if (Scanner::isPartialFile($path)) {
262
-				self::$rememberVersion[$this->stripPartFileExtension($path)] = $this->version + 1;
263
-			}
264
-			if (!empty($this->writeCache)) {
265
-				$result = $this->crypt->symmetricEncryptFileContent($this->writeCache, $this->fileKey, $this->version + 1, $position);
266
-				$this->writeCache = '';
267
-			}
268
-			$publicKeys = array();
269
-			if ($this->useMasterPassword === true) {
270
-				$publicKeys[$this->keyManager->getMasterKeyId()] = $this->keyManager->getPublicMasterKey();
271
-			} else {
272
-				foreach ($this->accessList['users'] as $uid) {
273
-					try {
274
-						$publicKeys[$uid] = $this->keyManager->getPublicKey($uid);
275
-					} catch (PublicKeyMissingException $e) {
276
-						$this->logger->warning(
277
-							'no public key found for user "{uid}", user will not be able to read the file',
278
-							['app' => 'encryption', 'uid' => $uid]
279
-						);
280
-						// if the public key of the owner is missing we should fail
281
-						if ($uid === $this->user) {
282
-							throw $e;
283
-						}
284
-					}
285
-				}
286
-			}
287
-
288
-			$publicKeys = $this->keyManager->addSystemKeys($this->accessList, $publicKeys, $this->getOwner($path));
289
-			$encryptedKeyfiles = $this->crypt->multiKeyEncrypt($this->fileKey, $publicKeys);
290
-			$this->keyManager->setAllFileKeys($this->path, $encryptedKeyfiles);
291
-		}
292
-		return $result;
293
-	}
294
-
295
-
296
-
297
-	/**
298
-	 * encrypt data
299
-	 *
300
-	 * @param string $data you want to encrypt
301
-	 * @param int $position
302
-	 * @return string encrypted data
303
-	 */
304
-	public function encrypt($data, $position = 0) {
305
-		// If extra data is left over from the last round, make sure it
306
-		// is integrated into the next block
307
-		if ($this->writeCache) {
308
-
309
-			// Concat writeCache to start of $data
310
-			$data = $this->writeCache . $data;
311
-
312
-			// Clear the write cache, ready for reuse - it has been
313
-			// flushed and its old contents processed
314
-			$this->writeCache = '';
315
-
316
-		}
317
-
318
-		$encrypted = '';
319
-		// While there still remains some data to be processed & written
320
-		while (strlen($data) > 0) {
321
-
322
-			// Remaining length for this iteration, not of the
323
-			// entire file (may be greater than 8192 bytes)
324
-			$remainingLength = strlen($data);
325
-
326
-			// If data remaining to be written is less than the
327
-			// size of 1 6126 byte block
328
-			if ($remainingLength < $this->unencryptedBlockSizeSigned) {
329
-
330
-				// Set writeCache to contents of $data
331
-				// The writeCache will be carried over to the
332
-				// next write round, and added to the start of
333
-				// $data to ensure that written blocks are
334
-				// always the correct length. If there is still
335
-				// data in writeCache after the writing round
336
-				// has finished, then the data will be written
337
-				// to disk by $this->flush().
338
-				$this->writeCache = $data;
339
-
340
-				// Clear $data ready for next round
341
-				$data = '';
342
-
343
-			} else {
344
-
345
-				// Read the chunk from the start of $data
346
-				$chunk = substr($data, 0, $this->unencryptedBlockSizeSigned);
347
-
348
-				$encrypted .= $this->crypt->symmetricEncryptFileContent($chunk, $this->fileKey, $this->version + 1, $position);
349
-
350
-				// Remove the chunk we just processed from
351
-				// $data, leaving only unprocessed data in $data
352
-				// var, for handling on the next round
353
-				$data = substr($data, $this->unencryptedBlockSizeSigned);
354
-
355
-			}
356
-
357
-		}
358
-
359
-		return $encrypted;
360
-	}
361
-
362
-	/**
363
-	 * decrypt data
364
-	 *
365
-	 * @param string $data you want to decrypt
366
-	 * @param int $position
367
-	 * @return string decrypted data
368
-	 * @throws DecryptionFailedException
369
-	 */
370
-	public function decrypt($data, $position = 0) {
371
-		if (empty($this->fileKey)) {
372
-			$msg = 'Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.';
373
-			$hint = $this->l->t('Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.');
374
-			$this->logger->error($msg);
375
-
376
-			throw new DecryptionFailedException($msg, $hint);
377
-		}
378
-
379
-		return $this->crypt->symmetricDecryptFileContent($data, $this->fileKey, $this->cipher, $this->version, $position);
380
-	}
381
-
382
-	/**
383
-	 * update encrypted file, e.g. give additional users access to the file
384
-	 *
385
-	 * @param string $path path to the file which should be updated
386
-	 * @param string $uid of the user who performs the operation
387
-	 * @param array $accessList who has access to the file contains the key 'users' and 'public'
388
-	 * @return boolean
389
-	 */
390
-	public function update($path, $uid, array $accessList) {
391
-
392
-		if (empty($accessList)) {
393
-			if (isset(self::$rememberVersion[$path])) {
394
-				$this->keyManager->setVersion($path, self::$rememberVersion[$path], new View());
395
-				unset(self::$rememberVersion[$path]);
396
-			}
397
-			return;
398
-		}
399
-
400
-		$fileKey = $this->keyManager->getFileKey($path, $uid);
401
-
402
-		if (!empty($fileKey)) {
403
-
404
-			$publicKeys = array();
405
-			if ($this->useMasterPassword === true) {
406
-				$publicKeys[$this->keyManager->getMasterKeyId()] = $this->keyManager->getPublicMasterKey();
407
-			} else {
408
-				foreach ($accessList['users'] as $user) {
409
-					try {
410
-						$publicKeys[$user] = $this->keyManager->getPublicKey($user);
411
-					} catch (PublicKeyMissingException $e) {
412
-						$this->logger->warning('Could not encrypt file for ' . $user . ': ' . $e->getMessage());
413
-					}
414
-				}
415
-			}
416
-
417
-			$publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $this->getOwner($path));
418
-
419
-			$encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys);
420
-
421
-			$this->keyManager->deleteAllFileKeys($path);
422
-
423
-			$this->keyManager->setAllFileKeys($path, $encryptedFileKey);
424
-
425
-		} else {
426
-			$this->logger->debug('no file key found, we assume that the file "{file}" is not encrypted',
427
-				array('file' => $path, 'app' => 'encryption'));
428
-
429
-			return false;
430
-		}
431
-
432
-		return true;
433
-	}
434
-
435
-	/**
436
-	 * should the file be encrypted or not
437
-	 *
438
-	 * @param string $path
439
-	 * @return boolean
440
-	 */
441
-	public function shouldEncrypt($path) {
442
-		if ($this->util->shouldEncryptHomeStorage() === false) {
443
-			$storage = $this->util->getStorage($path);
444
-			if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) {
445
-				return false;
446
-			}
447
-		}
448
-		$parts = explode('/', $path);
449
-		if (count($parts) < 4) {
450
-			return false;
451
-		}
452
-
453
-		if ($parts[2] === 'files') {
454
-			return true;
455
-		}
456
-		if ($parts[2] === 'files_versions') {
457
-			return true;
458
-		}
459
-		if ($parts[2] === 'files_trashbin') {
460
-			return true;
461
-		}
462
-
463
-		return false;
464
-	}
465
-
466
-	/**
467
-	 * get size of the unencrypted payload per block.
468
-	 * Nextcloud read/write files with a block size of 8192 byte
469
-	 *
470
-	 * @param bool $signed
471
-	 * @return int
472
-	 */
473
-	public function getUnencryptedBlockSize($signed = false) {
474
-		if ($signed === false) {
475
-			return $this->unencryptedBlockSize;
476
-		}
477
-
478
-		return $this->unencryptedBlockSizeSigned;
479
-	}
480
-
481
-	/**
482
-	 * check if the encryption module is able to read the file,
483
-	 * e.g. if all encryption keys exists
484
-	 *
485
-	 * @param string $path
486
-	 * @param string $uid user for whom we want to check if he can read the file
487
-	 * @return bool
488
-	 * @throws DecryptionFailedException
489
-	 */
490
-	public function isReadable($path, $uid) {
491
-		$fileKey = $this->keyManager->getFileKey($path, $uid);
492
-		if (empty($fileKey)) {
493
-			$owner = $this->util->getOwner($path);
494
-			if ($owner !== $uid) {
495
-				// if it is a shared file we throw a exception with a useful
496
-				// error message because in this case it means that the file was
497
-				// shared with the user at a point where the user didn't had a
498
-				// valid private/public key
499
-				$msg = 'Encryption module "' . $this->getDisplayName() .
500
-					'" is not able to read ' . $path;
501
-				$hint = $this->l->t('Can not read this file, probably this is a shared file. Please ask the file owner to reshare the file with you.');
502
-				$this->logger->warning($msg);
503
-				throw new DecryptionFailedException($msg, $hint);
504
-			}
505
-			return false;
506
-		}
507
-
508
-		return true;
509
-	}
510
-
511
-	/**
512
-	 * Initial encryption of all files
513
-	 *
514
-	 * @param InputInterface $input
515
-	 * @param OutputInterface $output write some status information to the terminal during encryption
516
-	 */
517
-	public function encryptAll(InputInterface $input, OutputInterface $output) {
518
-		$this->encryptAll->encryptAll($input, $output);
519
-	}
520
-
521
-	/**
522
-	 * prepare module to perform decrypt all operation
523
-	 *
524
-	 * @param InputInterface $input
525
-	 * @param OutputInterface $output
526
-	 * @param string $user
527
-	 * @return bool
528
-	 */
529
-	public function prepareDecryptAll(InputInterface $input, OutputInterface $output, $user = '') {
530
-		return $this->decryptAll->prepare($input, $output, $user);
531
-	}
532
-
533
-
534
-	/**
535
-	 * @param string $path
536
-	 * @return string
537
-	 */
538
-	protected function getPathToRealFile($path) {
539
-		$realPath = $path;
540
-		$parts = explode('/', $path);
541
-		if ($parts[2] === 'files_versions') {
542
-			$realPath = '/' . $parts[1] . '/files/' . implode('/', array_slice($parts, 3));
543
-			$length = strrpos($realPath, '.');
544
-			$realPath = substr($realPath, 0, $length);
545
-		}
546
-
547
-		return $realPath;
548
-	}
549
-
550
-	/**
551
-	 * remove .part file extension and the ocTransferId from the file to get the
552
-	 * original file name
553
-	 *
554
-	 * @param string $path
555
-	 * @return string
556
-	 */
557
-	protected function stripPartFileExtension($path) {
558
-		if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
559
-			$pos = strrpos($path, '.', -6);
560
-			$path = substr($path, 0, $pos);
561
-		}
562
-
563
-		return $path;
564
-	}
565
-
566
-	/**
567
-	 * get owner of a file
568
-	 *
569
-	 * @param string $path
570
-	 * @return string
571
-	 */
572
-	protected function getOwner($path) {
573
-		if (!isset($this->owner[$path])) {
574
-			$this->owner[$path] = $this->util->getOwner($path);
575
-		}
576
-		return $this->owner[$path];
577
-	}
578
-
579
-	/**
580
-	 * Check if the module is ready to be used by that specific user.
581
-	 * In case a module is not ready - because e.g. key pairs have not been generated
582
-	 * upon login this method can return false before any operation starts and might
583
-	 * cause issues during operations.
584
-	 *
585
-	 * @param string $user
586
-	 * @return boolean
587
-	 * @since 9.1.0
588
-	 */
589
-	public function isReadyForUser($user) {
590
-		return $this->keyManager->userHasKeys($user);
591
-	}
592
-
593
-	/**
594
-	 * We only need a detailed access list if the master key is not enabled
595
-	 *
596
-	 * @return bool
597
-	 */
598
-	public function needDetailedAccessList() {
599
-		return !$this->util->isMasterKeyEnabled();
600
-	}
48
+    const ID = 'OC_DEFAULT_MODULE';
49
+    const DISPLAY_NAME = 'Default encryption module';
50
+
51
+    /**
52
+     * @var Crypt
53
+     */
54
+    private $crypt;
55
+
56
+    /** @var string */
57
+    private $cipher;
58
+
59
+    /** @var string */
60
+    private $path;
61
+
62
+    /** @var string */
63
+    private $user;
64
+
65
+    /** @var  array */
66
+    private $owner;
67
+
68
+    /** @var string */
69
+    private $fileKey;
70
+
71
+    /** @var string */
72
+    private $writeCache;
73
+
74
+    /** @var KeyManager */
75
+    private $keyManager;
76
+
77
+    /** @var array */
78
+    private $accessList;
79
+
80
+    /** @var boolean */
81
+    private $isWriteOperation;
82
+
83
+    /** @var Util */
84
+    private $util;
85
+
86
+    /** @var  Session */
87
+    private $session;
88
+
89
+    /** @var  ILogger */
90
+    private $logger;
91
+
92
+    /** @var IL10N */
93
+    private $l;
94
+
95
+    /** @var EncryptAll */
96
+    private $encryptAll;
97
+
98
+    /** @var  bool */
99
+    private $useMasterPassword;
100
+
101
+    /** @var DecryptAll  */
102
+    private $decryptAll;
103
+
104
+    /** @var int unencrypted block size if block contains signature */
105
+    private $unencryptedBlockSizeSigned = 6072;
106
+
107
+    /** @var int unencrypted block size */
108
+    private $unencryptedBlockSize = 6126;
109
+
110
+    /** @var int Current version of the file */
111
+    private $version = 0;
112
+
113
+    /** @var array remember encryption signature version */
114
+    private static $rememberVersion = [];
115
+
116
+
117
+    /**
118
+     *
119
+     * @param Crypt $crypt
120
+     * @param KeyManager $keyManager
121
+     * @param Util $util
122
+     * @param Session $session
123
+     * @param EncryptAll $encryptAll
124
+     * @param DecryptAll $decryptAll
125
+     * @param ILogger $logger
126
+     * @param IL10N $il10n
127
+     */
128
+    public function __construct(Crypt $crypt,
129
+                                KeyManager $keyManager,
130
+                                Util $util,
131
+                                Session $session,
132
+                                EncryptAll $encryptAll,
133
+                                DecryptAll $decryptAll,
134
+                                ILogger $logger,
135
+                                IL10N $il10n) {
136
+        $this->crypt = $crypt;
137
+        $this->keyManager = $keyManager;
138
+        $this->util = $util;
139
+        $this->session = $session;
140
+        $this->encryptAll = $encryptAll;
141
+        $this->decryptAll = $decryptAll;
142
+        $this->logger = $logger;
143
+        $this->l = $il10n;
144
+        $this->owner = [];
145
+        $this->useMasterPassword = $util->isMasterKeyEnabled();
146
+    }
147
+
148
+    /**
149
+     * @return string defining the technical unique id
150
+     */
151
+    public function getId() {
152
+        return self::ID;
153
+    }
154
+
155
+    /**
156
+     * In comparison to getKey() this function returns a human readable (maybe translated) name
157
+     *
158
+     * @return string
159
+     */
160
+    public function getDisplayName() {
161
+        return self::DISPLAY_NAME;
162
+    }
163
+
164
+    /**
165
+     * start receiving chunks from a file. This is the place where you can
166
+     * perform some initial step before starting encrypting/decrypting the
167
+     * chunks
168
+     *
169
+     * @param string $path to the file
170
+     * @param string $user who read/write the file
171
+     * @param string $mode php stream open mode
172
+     * @param array $header contains the header data read from the file
173
+     * @param array $accessList who has access to the file contains the key 'users' and 'public'
174
+     *
175
+     * @return array $header contain data as key-value pairs which should be
176
+     *                       written to the header, in case of a write operation
177
+     *                       or if no additional data is needed return a empty array
178
+     */
179
+    public function begin($path, $user, $mode, array $header, array $accessList) {
180
+        $this->path = $this->getPathToRealFile($path);
181
+        $this->accessList = $accessList;
182
+        $this->user = $user;
183
+        $this->isWriteOperation = false;
184
+        $this->writeCache = '';
185
+
186
+        if($this->session->isReady() === false) {
187
+            // if the master key is enabled we can initialize encryption
188
+            // with a empty password and user name
189
+            if ($this->util->isMasterKeyEnabled()) {
190
+                $this->keyManager->init('', '');
191
+            }
192
+        }
193
+
194
+        if ($this->session->decryptAllModeActivated()) {
195
+            $encryptedFileKey = $this->keyManager->getEncryptedFileKey($this->path);
196
+            $shareKey = $this->keyManager->getShareKey($this->path, $this->session->getDecryptAllUid());
197
+            $this->fileKey = $this->crypt->multiKeyDecrypt($encryptedFileKey,
198
+                $shareKey,
199
+                $this->session->getDecryptAllKey());
200
+        } else {
201
+            $this->fileKey = $this->keyManager->getFileKey($this->path, $this->user);
202
+        }
203
+
204
+        // always use the version from the original file, also part files
205
+        // need to have a correct version number if they get moved over to the
206
+        // final location
207
+        $this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($path), new View());
208
+
209
+        if (
210
+            $mode === 'w'
211
+            || $mode === 'w+'
212
+            || $mode === 'wb'
213
+            || $mode === 'wb+'
214
+        ) {
215
+            $this->isWriteOperation = true;
216
+            if (empty($this->fileKey)) {
217
+                $this->fileKey = $this->crypt->generateFileKey();
218
+            }
219
+        } else {
220
+            // if we read a part file we need to increase the version by 1
221
+            // because the version number was also increased by writing
222
+            // the part file
223
+            if(Scanner::isPartialFile($path)) {
224
+                $this->version = $this->version + 1;
225
+            }
226
+        }
227
+
228
+        if ($this->isWriteOperation) {
229
+            $this->cipher = $this->crypt->getCipher();
230
+        } elseif (isset($header['cipher'])) {
231
+            $this->cipher = $header['cipher'];
232
+        } else {
233
+            // if we read a file without a header we fall-back to the legacy cipher
234
+            // which was used in <=oC6
235
+            $this->cipher = $this->crypt->getLegacyCipher();
236
+        }
237
+
238
+        return array('cipher' => $this->cipher, 'signed' => 'true');
239
+    }
240
+
241
+    /**
242
+     * last chunk received. This is the place where you can perform some final
243
+     * operation and return some remaining data if something is left in your
244
+     * buffer.
245
+     *
246
+     * @param string $path to the file
247
+     * @param int $position
248
+     * @return string remained data which should be written to the file in case
249
+     *                of a write operation
250
+     * @throws PublicKeyMissingException
251
+     * @throws \Exception
252
+     * @throws \OCA\Encryption\Exceptions\MultiKeyEncryptException
253
+     */
254
+    public function end($path, $position = 0) {
255
+        $result = '';
256
+        if ($this->isWriteOperation) {
257
+            // in case of a part file we remember the new signature versions
258
+            // the version will be set later on update.
259
+            // This way we make sure that other apps listening to the pre-hooks
260
+            // still get the old version which should be the correct value for them
261
+            if (Scanner::isPartialFile($path)) {
262
+                self::$rememberVersion[$this->stripPartFileExtension($path)] = $this->version + 1;
263
+            }
264
+            if (!empty($this->writeCache)) {
265
+                $result = $this->crypt->symmetricEncryptFileContent($this->writeCache, $this->fileKey, $this->version + 1, $position);
266
+                $this->writeCache = '';
267
+            }
268
+            $publicKeys = array();
269
+            if ($this->useMasterPassword === true) {
270
+                $publicKeys[$this->keyManager->getMasterKeyId()] = $this->keyManager->getPublicMasterKey();
271
+            } else {
272
+                foreach ($this->accessList['users'] as $uid) {
273
+                    try {
274
+                        $publicKeys[$uid] = $this->keyManager->getPublicKey($uid);
275
+                    } catch (PublicKeyMissingException $e) {
276
+                        $this->logger->warning(
277
+                            'no public key found for user "{uid}", user will not be able to read the file',
278
+                            ['app' => 'encryption', 'uid' => $uid]
279
+                        );
280
+                        // if the public key of the owner is missing we should fail
281
+                        if ($uid === $this->user) {
282
+                            throw $e;
283
+                        }
284
+                    }
285
+                }
286
+            }
287
+
288
+            $publicKeys = $this->keyManager->addSystemKeys($this->accessList, $publicKeys, $this->getOwner($path));
289
+            $encryptedKeyfiles = $this->crypt->multiKeyEncrypt($this->fileKey, $publicKeys);
290
+            $this->keyManager->setAllFileKeys($this->path, $encryptedKeyfiles);
291
+        }
292
+        return $result;
293
+    }
294
+
295
+
296
+
297
+    /**
298
+     * encrypt data
299
+     *
300
+     * @param string $data you want to encrypt
301
+     * @param int $position
302
+     * @return string encrypted data
303
+     */
304
+    public function encrypt($data, $position = 0) {
305
+        // If extra data is left over from the last round, make sure it
306
+        // is integrated into the next block
307
+        if ($this->writeCache) {
308
+
309
+            // Concat writeCache to start of $data
310
+            $data = $this->writeCache . $data;
311
+
312
+            // Clear the write cache, ready for reuse - it has been
313
+            // flushed and its old contents processed
314
+            $this->writeCache = '';
315
+
316
+        }
317
+
318
+        $encrypted = '';
319
+        // While there still remains some data to be processed & written
320
+        while (strlen($data) > 0) {
321
+
322
+            // Remaining length for this iteration, not of the
323
+            // entire file (may be greater than 8192 bytes)
324
+            $remainingLength = strlen($data);
325
+
326
+            // If data remaining to be written is less than the
327
+            // size of 1 6126 byte block
328
+            if ($remainingLength < $this->unencryptedBlockSizeSigned) {
329
+
330
+                // Set writeCache to contents of $data
331
+                // The writeCache will be carried over to the
332
+                // next write round, and added to the start of
333
+                // $data to ensure that written blocks are
334
+                // always the correct length. If there is still
335
+                // data in writeCache after the writing round
336
+                // has finished, then the data will be written
337
+                // to disk by $this->flush().
338
+                $this->writeCache = $data;
339
+
340
+                // Clear $data ready for next round
341
+                $data = '';
342
+
343
+            } else {
344
+
345
+                // Read the chunk from the start of $data
346
+                $chunk = substr($data, 0, $this->unencryptedBlockSizeSigned);
347
+
348
+                $encrypted .= $this->crypt->symmetricEncryptFileContent($chunk, $this->fileKey, $this->version + 1, $position);
349
+
350
+                // Remove the chunk we just processed from
351
+                // $data, leaving only unprocessed data in $data
352
+                // var, for handling on the next round
353
+                $data = substr($data, $this->unencryptedBlockSizeSigned);
354
+
355
+            }
356
+
357
+        }
358
+
359
+        return $encrypted;
360
+    }
361
+
362
+    /**
363
+     * decrypt data
364
+     *
365
+     * @param string $data you want to decrypt
366
+     * @param int $position
367
+     * @return string decrypted data
368
+     * @throws DecryptionFailedException
369
+     */
370
+    public function decrypt($data, $position = 0) {
371
+        if (empty($this->fileKey)) {
372
+            $msg = 'Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.';
373
+            $hint = $this->l->t('Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you.');
374
+            $this->logger->error($msg);
375
+
376
+            throw new DecryptionFailedException($msg, $hint);
377
+        }
378
+
379
+        return $this->crypt->symmetricDecryptFileContent($data, $this->fileKey, $this->cipher, $this->version, $position);
380
+    }
381
+
382
+    /**
383
+     * update encrypted file, e.g. give additional users access to the file
384
+     *
385
+     * @param string $path path to the file which should be updated
386
+     * @param string $uid of the user who performs the operation
387
+     * @param array $accessList who has access to the file contains the key 'users' and 'public'
388
+     * @return boolean
389
+     */
390
+    public function update($path, $uid, array $accessList) {
391
+
392
+        if (empty($accessList)) {
393
+            if (isset(self::$rememberVersion[$path])) {
394
+                $this->keyManager->setVersion($path, self::$rememberVersion[$path], new View());
395
+                unset(self::$rememberVersion[$path]);
396
+            }
397
+            return;
398
+        }
399
+
400
+        $fileKey = $this->keyManager->getFileKey($path, $uid);
401
+
402
+        if (!empty($fileKey)) {
403
+
404
+            $publicKeys = array();
405
+            if ($this->useMasterPassword === true) {
406
+                $publicKeys[$this->keyManager->getMasterKeyId()] = $this->keyManager->getPublicMasterKey();
407
+            } else {
408
+                foreach ($accessList['users'] as $user) {
409
+                    try {
410
+                        $publicKeys[$user] = $this->keyManager->getPublicKey($user);
411
+                    } catch (PublicKeyMissingException $e) {
412
+                        $this->logger->warning('Could not encrypt file for ' . $user . ': ' . $e->getMessage());
413
+                    }
414
+                }
415
+            }
416
+
417
+            $publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $this->getOwner($path));
418
+
419
+            $encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys);
420
+
421
+            $this->keyManager->deleteAllFileKeys($path);
422
+
423
+            $this->keyManager->setAllFileKeys($path, $encryptedFileKey);
424
+
425
+        } else {
426
+            $this->logger->debug('no file key found, we assume that the file "{file}" is not encrypted',
427
+                array('file' => $path, 'app' => 'encryption'));
428
+
429
+            return false;
430
+        }
431
+
432
+        return true;
433
+    }
434
+
435
+    /**
436
+     * should the file be encrypted or not
437
+     *
438
+     * @param string $path
439
+     * @return boolean
440
+     */
441
+    public function shouldEncrypt($path) {
442
+        if ($this->util->shouldEncryptHomeStorage() === false) {
443
+            $storage = $this->util->getStorage($path);
444
+            if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) {
445
+                return false;
446
+            }
447
+        }
448
+        $parts = explode('/', $path);
449
+        if (count($parts) < 4) {
450
+            return false;
451
+        }
452
+
453
+        if ($parts[2] === 'files') {
454
+            return true;
455
+        }
456
+        if ($parts[2] === 'files_versions') {
457
+            return true;
458
+        }
459
+        if ($parts[2] === 'files_trashbin') {
460
+            return true;
461
+        }
462
+
463
+        return false;
464
+    }
465
+
466
+    /**
467
+     * get size of the unencrypted payload per block.
468
+     * Nextcloud read/write files with a block size of 8192 byte
469
+     *
470
+     * @param bool $signed
471
+     * @return int
472
+     */
473
+    public function getUnencryptedBlockSize($signed = false) {
474
+        if ($signed === false) {
475
+            return $this->unencryptedBlockSize;
476
+        }
477
+
478
+        return $this->unencryptedBlockSizeSigned;
479
+    }
480
+
481
+    /**
482
+     * check if the encryption module is able to read the file,
483
+     * e.g. if all encryption keys exists
484
+     *
485
+     * @param string $path
486
+     * @param string $uid user for whom we want to check if he can read the file
487
+     * @return bool
488
+     * @throws DecryptionFailedException
489
+     */
490
+    public function isReadable($path, $uid) {
491
+        $fileKey = $this->keyManager->getFileKey($path, $uid);
492
+        if (empty($fileKey)) {
493
+            $owner = $this->util->getOwner($path);
494
+            if ($owner !== $uid) {
495
+                // if it is a shared file we throw a exception with a useful
496
+                // error message because in this case it means that the file was
497
+                // shared with the user at a point where the user didn't had a
498
+                // valid private/public key
499
+                $msg = 'Encryption module "' . $this->getDisplayName() .
500
+                    '" is not able to read ' . $path;
501
+                $hint = $this->l->t('Can not read this file, probably this is a shared file. Please ask the file owner to reshare the file with you.');
502
+                $this->logger->warning($msg);
503
+                throw new DecryptionFailedException($msg, $hint);
504
+            }
505
+            return false;
506
+        }
507
+
508
+        return true;
509
+    }
510
+
511
+    /**
512
+     * Initial encryption of all files
513
+     *
514
+     * @param InputInterface $input
515
+     * @param OutputInterface $output write some status information to the terminal during encryption
516
+     */
517
+    public function encryptAll(InputInterface $input, OutputInterface $output) {
518
+        $this->encryptAll->encryptAll($input, $output);
519
+    }
520
+
521
+    /**
522
+     * prepare module to perform decrypt all operation
523
+     *
524
+     * @param InputInterface $input
525
+     * @param OutputInterface $output
526
+     * @param string $user
527
+     * @return bool
528
+     */
529
+    public function prepareDecryptAll(InputInterface $input, OutputInterface $output, $user = '') {
530
+        return $this->decryptAll->prepare($input, $output, $user);
531
+    }
532
+
533
+
534
+    /**
535
+     * @param string $path
536
+     * @return string
537
+     */
538
+    protected function getPathToRealFile($path) {
539
+        $realPath = $path;
540
+        $parts = explode('/', $path);
541
+        if ($parts[2] === 'files_versions') {
542
+            $realPath = '/' . $parts[1] . '/files/' . implode('/', array_slice($parts, 3));
543
+            $length = strrpos($realPath, '.');
544
+            $realPath = substr($realPath, 0, $length);
545
+        }
546
+
547
+        return $realPath;
548
+    }
549
+
550
+    /**
551
+     * remove .part file extension and the ocTransferId from the file to get the
552
+     * original file name
553
+     *
554
+     * @param string $path
555
+     * @return string
556
+     */
557
+    protected function stripPartFileExtension($path) {
558
+        if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
559
+            $pos = strrpos($path, '.', -6);
560
+            $path = substr($path, 0, $pos);
561
+        }
562
+
563
+        return $path;
564
+    }
565
+
566
+    /**
567
+     * get owner of a file
568
+     *
569
+     * @param string $path
570
+     * @return string
571
+     */
572
+    protected function getOwner($path) {
573
+        if (!isset($this->owner[$path])) {
574
+            $this->owner[$path] = $this->util->getOwner($path);
575
+        }
576
+        return $this->owner[$path];
577
+    }
578
+
579
+    /**
580
+     * Check if the module is ready to be used by that specific user.
581
+     * In case a module is not ready - because e.g. key pairs have not been generated
582
+     * upon login this method can return false before any operation starts and might
583
+     * cause issues during operations.
584
+     *
585
+     * @param string $user
586
+     * @return boolean
587
+     * @since 9.1.0
588
+     */
589
+    public function isReadyForUser($user) {
590
+        return $this->keyManager->userHasKeys($user);
591
+    }
592
+
593
+    /**
594
+     * We only need a detailed access list if the master key is not enabled
595
+     *
596
+     * @return bool
597
+     */
598
+    public function needDetailedAccessList() {
599
+        return !$this->util->isMasterKeyEnabled();
600
+    }
601 601
 }
Please login to merge, or discard this patch.
apps/encryption/lib/Crypto/DecryptAll.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -35,127 +35,127 @@
 block discarded – undo
35 35
 
36 36
 class DecryptAll {
37 37
 
38
-	/** @var Util  */
39
-	protected $util;
40
-
41
-	/** @var QuestionHelper  */
42
-	protected $questionHelper;
43
-
44
-	/** @var  Crypt */
45
-	protected $crypt;
46
-
47
-	/** @var  KeyManager */
48
-	protected $keyManager;
49
-
50
-	/** @var Session  */
51
-	protected $session;
52
-
53
-	/**
54
-	 * @param Util $util
55
-	 * @param KeyManager $keyManager
56
-	 * @param Crypt $crypt
57
-	 * @param Session $session
58
-	 * @param QuestionHelper $questionHelper
59
-	 */
60
-	public function __construct(
61
-		Util $util,
62
-		KeyManager $keyManager,
63
-		Crypt $crypt,
64
-		Session $session,
65
-		QuestionHelper $questionHelper
66
-	) {
67
-		$this->util = $util;
68
-		$this->keyManager = $keyManager;
69
-		$this->crypt = $crypt;
70
-		$this->session = $session;
71
-		$this->questionHelper = $questionHelper;
72
-	}
73
-
74
-	/**
75
-	 * prepare encryption module to decrypt all files
76
-	 *
77
-	 * @param InputInterface $input
78
-	 * @param OutputInterface $output
79
-	 * @param $user
80
-	 * @return bool
81
-	 */
82
-	public function prepare(InputInterface $input, OutputInterface $output, $user) {
83
-
84
-		$question = new Question('Please enter the recovery key password: ');
85
-
86
-		if($this->util->isMasterKeyEnabled()) {
87
-			$output->writeln('Use master key to decrypt all files');
88
-			$user = $this->keyManager->getMasterKeyId();
89
-			$password =$this->keyManager->getMasterKeyPassword();
90
-		} else {
91
-			$recoveryKeyId = $this->keyManager->getRecoveryKeyId();
92
-			if (!empty($user)) {
93
-				$output->writeln('You can only decrypt the users files if you know');
94
-				$output->writeln('the users password or if he activated the recovery key.');
95
-				$output->writeln('');
96
-				$questionUseLoginPassword = new ConfirmationQuestion(
97
-					'Do you want to use the users login password to decrypt all files? (y/n) ',
98
-					false
99
-				);
100
-				$useLoginPassword = $this->questionHelper->ask($input, $output, $questionUseLoginPassword);
101
-				if ($useLoginPassword) {
102
-					$question = new Question('Please enter the user\'s login password: ');
103
-				} else if ($this->util->isRecoveryEnabledForUser($user) === false) {
104
-					$output->writeln('No recovery key available for user ' . $user);
105
-					return false;
106
-				} else {
107
-					$user = $recoveryKeyId;
108
-				}
109
-			} else {
110
-				$output->writeln('You can only decrypt the files of all users if the');
111
-				$output->writeln('recovery key is enabled by the admin and activated by the users.');
112
-				$output->writeln('');
113
-				$user = $recoveryKeyId;
114
-			}
115
-
116
-			$question->setHidden(true);
117
-			$question->setHiddenFallback(false);
118
-			$password = $this->questionHelper->ask($input, $output, $question);
119
-		}
120
-
121
-		$privateKey = $this->getPrivateKey($user, $password);
122
-		if ($privateKey !== false) {
123
-			$this->updateSession($user, $privateKey);
124
-			return true;
125
-		} else {
126
-			$output->writeln('Could not decrypt private key, maybe you entered the wrong password?');
127
-		}
128
-
129
-
130
-		return false;
131
-	}
132
-
133
-	/**
134
-	 * get the private key which will be used to decrypt all files
135
-	 *
136
-	 * @param string $user
137
-	 * @param string $password
138
-	 * @return bool|string
139
-	 * @throws \OCA\Encryption\Exceptions\PrivateKeyMissingException
140
-	 */
141
-	protected function getPrivateKey($user, $password) {
142
-		$recoveryKeyId = $this->keyManager->getRecoveryKeyId();
143
-		$masterKeyId = $this->keyManager->getMasterKeyId();
144
-		if ($user === $recoveryKeyId) {
145
-			$recoveryKey = $this->keyManager->getSystemPrivateKey($recoveryKeyId);
146
-			$privateKey = $this->crypt->decryptPrivateKey($recoveryKey, $password);
147
-		} elseif ($user === $masterKeyId) {
148
-			$masterKey = $this->keyManager->getSystemPrivateKey($masterKeyId);
149
-			$privateKey = $this->crypt->decryptPrivateKey($masterKey, $password, $masterKeyId);
150
-		} else {
151
-			$userKey = $this->keyManager->getPrivateKey($user);
152
-			$privateKey = $this->crypt->decryptPrivateKey($userKey, $password, $user);
153
-		}
154
-
155
-		return $privateKey;
156
-	}
157
-
158
-	protected function updateSession($user, $privateKey) {
159
-		$this->session->prepareDecryptAll($user, $privateKey);
160
-	}
38
+    /** @var Util  */
39
+    protected $util;
40
+
41
+    /** @var QuestionHelper  */
42
+    protected $questionHelper;
43
+
44
+    /** @var  Crypt */
45
+    protected $crypt;
46
+
47
+    /** @var  KeyManager */
48
+    protected $keyManager;
49
+
50
+    /** @var Session  */
51
+    protected $session;
52
+
53
+    /**
54
+     * @param Util $util
55
+     * @param KeyManager $keyManager
56
+     * @param Crypt $crypt
57
+     * @param Session $session
58
+     * @param QuestionHelper $questionHelper
59
+     */
60
+    public function __construct(
61
+        Util $util,
62
+        KeyManager $keyManager,
63
+        Crypt $crypt,
64
+        Session $session,
65
+        QuestionHelper $questionHelper
66
+    ) {
67
+        $this->util = $util;
68
+        $this->keyManager = $keyManager;
69
+        $this->crypt = $crypt;
70
+        $this->session = $session;
71
+        $this->questionHelper = $questionHelper;
72
+    }
73
+
74
+    /**
75
+     * prepare encryption module to decrypt all files
76
+     *
77
+     * @param InputInterface $input
78
+     * @param OutputInterface $output
79
+     * @param $user
80
+     * @return bool
81
+     */
82
+    public function prepare(InputInterface $input, OutputInterface $output, $user) {
83
+
84
+        $question = new Question('Please enter the recovery key password: ');
85
+
86
+        if($this->util->isMasterKeyEnabled()) {
87
+            $output->writeln('Use master key to decrypt all files');
88
+            $user = $this->keyManager->getMasterKeyId();
89
+            $password =$this->keyManager->getMasterKeyPassword();
90
+        } else {
91
+            $recoveryKeyId = $this->keyManager->getRecoveryKeyId();
92
+            if (!empty($user)) {
93
+                $output->writeln('You can only decrypt the users files if you know');
94
+                $output->writeln('the users password or if he activated the recovery key.');
95
+                $output->writeln('');
96
+                $questionUseLoginPassword = new ConfirmationQuestion(
97
+                    'Do you want to use the users login password to decrypt all files? (y/n) ',
98
+                    false
99
+                );
100
+                $useLoginPassword = $this->questionHelper->ask($input, $output, $questionUseLoginPassword);
101
+                if ($useLoginPassword) {
102
+                    $question = new Question('Please enter the user\'s login password: ');
103
+                } else if ($this->util->isRecoveryEnabledForUser($user) === false) {
104
+                    $output->writeln('No recovery key available for user ' . $user);
105
+                    return false;
106
+                } else {
107
+                    $user = $recoveryKeyId;
108
+                }
109
+            } else {
110
+                $output->writeln('You can only decrypt the files of all users if the');
111
+                $output->writeln('recovery key is enabled by the admin and activated by the users.');
112
+                $output->writeln('');
113
+                $user = $recoveryKeyId;
114
+            }
115
+
116
+            $question->setHidden(true);
117
+            $question->setHiddenFallback(false);
118
+            $password = $this->questionHelper->ask($input, $output, $question);
119
+        }
120
+
121
+        $privateKey = $this->getPrivateKey($user, $password);
122
+        if ($privateKey !== false) {
123
+            $this->updateSession($user, $privateKey);
124
+            return true;
125
+        } else {
126
+            $output->writeln('Could not decrypt private key, maybe you entered the wrong password?');
127
+        }
128
+
129
+
130
+        return false;
131
+    }
132
+
133
+    /**
134
+     * get the private key which will be used to decrypt all files
135
+     *
136
+     * @param string $user
137
+     * @param string $password
138
+     * @return bool|string
139
+     * @throws \OCA\Encryption\Exceptions\PrivateKeyMissingException
140
+     */
141
+    protected function getPrivateKey($user, $password) {
142
+        $recoveryKeyId = $this->keyManager->getRecoveryKeyId();
143
+        $masterKeyId = $this->keyManager->getMasterKeyId();
144
+        if ($user === $recoveryKeyId) {
145
+            $recoveryKey = $this->keyManager->getSystemPrivateKey($recoveryKeyId);
146
+            $privateKey = $this->crypt->decryptPrivateKey($recoveryKey, $password);
147
+        } elseif ($user === $masterKeyId) {
148
+            $masterKey = $this->keyManager->getSystemPrivateKey($masterKeyId);
149
+            $privateKey = $this->crypt->decryptPrivateKey($masterKey, $password, $masterKeyId);
150
+        } else {
151
+            $userKey = $this->keyManager->getPrivateKey($user);
152
+            $privateKey = $this->crypt->decryptPrivateKey($userKey, $password, $user);
153
+        }
154
+
155
+        return $privateKey;
156
+    }
157
+
158
+    protected function updateSession($user, $privateKey) {
159
+        $this->session->prepareDecryptAll($user, $privateKey);
160
+    }
161 161
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
 
84 84
 		$question = new Question('Please enter the recovery key password: ');
85 85
 
86
-		if($this->util->isMasterKeyEnabled()) {
86
+		if ($this->util->isMasterKeyEnabled()) {
87 87
 			$output->writeln('Use master key to decrypt all files');
88 88
 			$user = $this->keyManager->getMasterKeyId();
89
-			$password =$this->keyManager->getMasterKeyPassword();
89
+			$password = $this->keyManager->getMasterKeyPassword();
90 90
 		} else {
91 91
 			$recoveryKeyId = $this->keyManager->getRecoveryKeyId();
92 92
 			if (!empty($user)) {
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 				if ($useLoginPassword) {
102 102
 					$question = new Question('Please enter the user\'s login password: ');
103 103
 				} else if ($this->util->isRecoveryEnabledForUser($user) === false) {
104
-					$output->writeln('No recovery key available for user ' . $user);
104
+					$output->writeln('No recovery key available for user '.$user);
105 105
 					return false;
106 106
 				} else {
107 107
 					$user = $recoveryKeyId;
Please login to merge, or discard this patch.
apps/encryption/lib/HookManager.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -28,38 +28,38 @@
 block discarded – undo
28 28
 
29 29
 class HookManager {
30 30
 
31
-	private $hookInstances = [];
31
+    private $hookInstances = [];
32 32
 
33
-	/**
34
-	 * @param array|IHook $instances
35
-	 *        - This accepts either a single instance of IHook or an array of instances of IHook
36
-	 * @return bool
37
-	 */
38
-	public function registerHook($instances) {
39
-		if (is_array($instances)) {
40
-			foreach ($instances as $instance) {
41
-				if (!$instance instanceof IHook) {
42
-					return false;
43
-				}
44
-				$this->hookInstances[] = $instance;
45
-			}
33
+    /**
34
+     * @param array|IHook $instances
35
+     *        - This accepts either a single instance of IHook or an array of instances of IHook
36
+     * @return bool
37
+     */
38
+    public function registerHook($instances) {
39
+        if (is_array($instances)) {
40
+            foreach ($instances as $instance) {
41
+                if (!$instance instanceof IHook) {
42
+                    return false;
43
+                }
44
+                $this->hookInstances[] = $instance;
45
+            }
46 46
 
47
-		} elseif ($instances instanceof IHook) {
48
-			$this->hookInstances[] = $instances;
49
-		}
50
-		return true;
51
-	}
47
+        } elseif ($instances instanceof IHook) {
48
+            $this->hookInstances[] = $instances;
49
+        }
50
+        return true;
51
+    }
52 52
 
53
-	public function fireHooks() {
54
-		foreach ($this->hookInstances as $instance) {
55
-			/**
56
-			 * Fire off the add hooks method of each instance stored in cache
57
-			 *
58
-			 * @var $instance IHook
59
-			 */
60
-			$instance->addHooks();
61
-		}
53
+    public function fireHooks() {
54
+        foreach ($this->hookInstances as $instance) {
55
+            /**
56
+             * Fire off the add hooks method of each instance stored in cache
57
+             *
58
+             * @var $instance IHook
59
+             */
60
+            $instance->addHooks();
61
+        }
62 62
 
63
-	}
63
+    }
64 64
 
65 65
 }
Please login to merge, or discard this patch.
apps/encryption/appinfo/routes.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -26,36 +26,36 @@
 block discarded – undo
26 26
 
27 27
 (new Application())->registerRoutes($this, array('routes' => array(
28 28
 
29
-	[
30
-		'name' => 'Recovery#adminRecovery',
31
-		'url' => '/ajax/adminRecovery',
32
-		'verb' => 'POST'
33
-	],
34
-	[
35
-		'name' => 'Settings#updatePrivateKeyPassword',
36
-		'url' => '/ajax/updatePrivateKeyPassword',
37
-		'verb' => 'POST'
38
-	],
39
-	[
40
-		'name' => 'Settings#setEncryptHomeStorage',
41
-		'url' => '/ajax/setEncryptHomeStorage',
42
-		'verb' => 'POST'
43
-	],
44
-	[
45
-		'name' => 'Recovery#changeRecoveryPassword',
46
-		'url' => '/ajax/changeRecoveryPassword',
47
-		'verb' => 'POST'
48
-	],
49
-	[
50
-		'name' => 'Recovery#userSetRecovery',
51
-		'url' => '/ajax/userSetRecovery',
52
-		'verb' => 'POST'
53
-	],
54
-	[
55
-		'name' => 'Status#getStatus',
56
-		'url' => '/ajax/getStatus',
57
-		'verb' => 'GET'
58
-	]
29
+    [
30
+        'name' => 'Recovery#adminRecovery',
31
+        'url' => '/ajax/adminRecovery',
32
+        'verb' => 'POST'
33
+    ],
34
+    [
35
+        'name' => 'Settings#updatePrivateKeyPassword',
36
+        'url' => '/ajax/updatePrivateKeyPassword',
37
+        'verb' => 'POST'
38
+    ],
39
+    [
40
+        'name' => 'Settings#setEncryptHomeStorage',
41
+        'url' => '/ajax/setEncryptHomeStorage',
42
+        'verb' => 'POST'
43
+    ],
44
+    [
45
+        'name' => 'Recovery#changeRecoveryPassword',
46
+        'url' => '/ajax/changeRecoveryPassword',
47
+        'verb' => 'POST'
48
+    ],
49
+    [
50
+        'name' => 'Recovery#userSetRecovery',
51
+        'url' => '/ajax/userSetRecovery',
52
+        'verb' => 'POST'
53
+    ],
54
+    [
55
+        'name' => 'Status#getStatus',
56
+        'url' => '/ajax/getStatus',
57
+        'verb' => 'GET'
58
+    ]
59 59
 
60 60
 
61 61
 )));
Please login to merge, or discard this patch.
apps/comments/lib/Activity/Setting.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -27,72 +27,72 @@
 block discarded – undo
27 27
 
28 28
 class Setting implements ISetting {
29 29
 
30
-	/** @var IL10N */
31
-	protected $l;
30
+    /** @var IL10N */
31
+    protected $l;
32 32
 
33
-	/**
34
-	 * @param IL10N $l
35
-	 */
36
-	public function __construct(IL10N $l) {
37
-		$this->l = $l;
38
-	}
33
+    /**
34
+     * @param IL10N $l
35
+     */
36
+    public function __construct(IL10N $l) {
37
+        $this->l = $l;
38
+    }
39 39
 
40
-	/**
41
-	 * @return string Lowercase a-z and underscore only identifier
42
-	 * @since 11.0.0
43
-	 */
44
-	public function getIdentifier() {
45
-		return 'comments';
46
-	}
40
+    /**
41
+     * @return string Lowercase a-z and underscore only identifier
42
+     * @since 11.0.0
43
+     */
44
+    public function getIdentifier() {
45
+        return 'comments';
46
+    }
47 47
 
48
-	/**
49
-	 * @return string A translated string
50
-	 * @since 11.0.0
51
-	 */
52
-	public function getName() {
53
-		return $this->l->t('<strong>Comments</strong> for files');
54
-	}
48
+    /**
49
+     * @return string A translated string
50
+     * @since 11.0.0
51
+     */
52
+    public function getName() {
53
+        return $this->l->t('<strong>Comments</strong> for files');
54
+    }
55 55
 
56
-	/**
57
-	 * @return int whether the filter should be rather on the top or bottom of
58
-	 * the admin section. The filters are arranged in ascending order of the
59
-	 * priority values. It is required to return a value between 0 and 100.
60
-	 * @since 11.0.0
61
-	 */
62
-	public function getPriority() {
63
-		return 50;
64
-	}
56
+    /**
57
+     * @return int whether the filter should be rather on the top or bottom of
58
+     * the admin section. The filters are arranged in ascending order of the
59
+     * priority values. It is required to return a value between 0 and 100.
60
+     * @since 11.0.0
61
+     */
62
+    public function getPriority() {
63
+        return 50;
64
+    }
65 65
 
66
-	/**
67
-	 * @return bool True when the option can be changed for the stream
68
-	 * @since 11.0.0
69
-	 */
70
-	public function canChangeStream() {
71
-		return true;
72
-	}
66
+    /**
67
+     * @return bool True when the option can be changed for the stream
68
+     * @since 11.0.0
69
+     */
70
+    public function canChangeStream() {
71
+        return true;
72
+    }
73 73
 
74
-	/**
75
-	 * @return bool True when the option can be changed for the stream
76
-	 * @since 11.0.0
77
-	 */
78
-	public function isDefaultEnabledStream() {
79
-		return true;
80
-	}
74
+    /**
75
+     * @return bool True when the option can be changed for the stream
76
+     * @since 11.0.0
77
+     */
78
+    public function isDefaultEnabledStream() {
79
+        return true;
80
+    }
81 81
 
82
-	/**
83
-	 * @return bool True when the option can be changed for the mail
84
-	 * @since 11.0.0
85
-	 */
86
-	public function canChangeMail() {
87
-		return true;
88
-	}
82
+    /**
83
+     * @return bool True when the option can be changed for the mail
84
+     * @since 11.0.0
85
+     */
86
+    public function canChangeMail() {
87
+        return true;
88
+    }
89 89
 
90
-	/**
91
-	 * @return bool True when the option can be changed for the stream
92
-	 * @since 11.0.0
93
-	 */
94
-	public function isDefaultEnabledMail() {
95
-		return false;
96
-	}
90
+    /**
91
+     * @return bool True when the option can be changed for the stream
92
+     * @since 11.0.0
93
+     */
94
+    public function isDefaultEnabledMail() {
95
+        return false;
96
+    }
97 97
 }
98 98
 
Please login to merge, or discard this patch.
apps/comments/lib/Activity/Filter.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -28,63 +28,63 @@
 block discarded – undo
28 28
 
29 29
 class Filter implements IFilter {
30 30
 
31
-	/** @var IL10N */
32
-	protected $l;
31
+    /** @var IL10N */
32
+    protected $l;
33 33
 
34
-	/** @var IURLGenerator */
35
-	protected $url;
34
+    /** @var IURLGenerator */
35
+    protected $url;
36 36
 
37
-	public function __construct(IL10N $l, IURLGenerator $url) {
38
-		$this->l = $l;
39
-		$this->url = $url;
40
-	}
37
+    public function __construct(IL10N $l, IURLGenerator $url) {
38
+        $this->l = $l;
39
+        $this->url = $url;
40
+    }
41 41
 
42
-	/**
43
-	 * @return string Lowercase a-z only identifier
44
-	 * @since 11.0.0
45
-	 */
46
-	public function getIdentifier() {
47
-		return 'comments';
48
-	}
42
+    /**
43
+     * @return string Lowercase a-z only identifier
44
+     * @since 11.0.0
45
+     */
46
+    public function getIdentifier() {
47
+        return 'comments';
48
+    }
49 49
 
50
-	/**
51
-	 * @return string A translated string
52
-	 * @since 11.0.0
53
-	 */
54
-	public function getName() {
55
-		return $this->l->t('Comments');
56
-	}
50
+    /**
51
+     * @return string A translated string
52
+     * @since 11.0.0
53
+     */
54
+    public function getName() {
55
+        return $this->l->t('Comments');
56
+    }
57 57
 
58
-	/**
59
-	 * @return int
60
-	 * @since 11.0.0
61
-	 */
62
-	public function getPriority() {
63
-		return 40;
64
-	}
58
+    /**
59
+     * @return int
60
+     * @since 11.0.0
61
+     */
62
+    public function getPriority() {
63
+        return 40;
64
+    }
65 65
 
66
-	/**
67
-	 * @return string Full URL to an icon, empty string when none is given
68
-	 * @since 11.0.0
69
-	 */
70
-	public function getIcon() {
71
-		return $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg'));
72
-	}
66
+    /**
67
+     * @return string Full URL to an icon, empty string when none is given
68
+     * @since 11.0.0
69
+     */
70
+    public function getIcon() {
71
+        return $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg'));
72
+    }
73 73
 
74
-	/**
75
-	 * @param string[] $types
76
-	 * @return string[] An array of allowed apps from which activities should be displayed
77
-	 * @since 11.0.0
78
-	 */
79
-	public function filterTypes(array $types) {
80
-		return $types;
81
-	}
74
+    /**
75
+     * @param string[] $types
76
+     * @return string[] An array of allowed apps from which activities should be displayed
77
+     * @since 11.0.0
78
+     */
79
+    public function filterTypes(array $types) {
80
+        return $types;
81
+    }
82 82
 
83
-	/**
84
-	 * @return string[] An array of allowed apps from which activities should be displayed
85
-	 * @since 11.0.0
86
-	 */
87
-	public function allowedApps() {
88
-		return ['comments'];
89
-	}
83
+    /**
84
+     * @return string[] An array of allowed apps from which activities should be displayed
85
+     * @since 11.0.0
86
+     */
87
+    public function allowedApps() {
88
+        return ['comments'];
89
+    }
90 90
 }
Please login to merge, or discard this patch.
apps/comments/lib/Notification/Listener.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -27,93 +27,93 @@
 block discarded – undo
27 27
 use OCP\Notification\IManager;
28 28
 
29 29
 class Listener {
30
-	/** @var IManager */
31
-	protected $notificationManager;
30
+    /** @var IManager */
31
+    protected $notificationManager;
32 32
 
33
-	/** @var IUserManager */
34
-	protected $userManager;
33
+    /** @var IUserManager */
34
+    protected $userManager;
35 35
 
36
-	/**
37
-	 * Listener constructor.
38
-	 *
39
-	 * @param IManager $notificationManager
40
-	 * @param IUserManager $userManager
41
-	 */
42
-	public function __construct(
43
-		IManager $notificationManager,
44
-		IUserManager $userManager
45
-	) {
36
+    /**
37
+     * Listener constructor.
38
+     *
39
+     * @param IManager $notificationManager
40
+     * @param IUserManager $userManager
41
+     */
42
+    public function __construct(
43
+        IManager $notificationManager,
44
+        IUserManager $userManager
45
+    ) {
46 46
 
47
-		$this->notificationManager = $notificationManager;
48
-		$this->userManager = $userManager;
49
-	}
47
+        $this->notificationManager = $notificationManager;
48
+        $this->userManager = $userManager;
49
+    }
50 50
 
51
-	/**
52
-	 * @param CommentsEvent $event
53
-	 */
54
-	public function evaluate(CommentsEvent $event) {
55
-		$comment = $event->getComment();
51
+    /**
52
+     * @param CommentsEvent $event
53
+     */
54
+    public function evaluate(CommentsEvent $event) {
55
+        $comment = $event->getComment();
56 56
 
57
-		$mentions = $this->extractMentions($comment->getMentions());
58
-		if(empty($mentions)) {
59
-			// no one to notify
60
-			return;
61
-		}
57
+        $mentions = $this->extractMentions($comment->getMentions());
58
+        if(empty($mentions)) {
59
+            // no one to notify
60
+            return;
61
+        }
62 62
 
63
-		$notification = $this->instantiateNotification($comment);
63
+        $notification = $this->instantiateNotification($comment);
64 64
 
65
-		foreach($mentions as $uid) {
66
-			if( ($comment->getActorType() === 'users' && $uid === $comment->getActorId())
67
-				|| !$this->userManager->userExists($uid)
68
-			) {
69
-				// do not notify unknown users or yourself
70
-				continue;
71
-			}
65
+        foreach($mentions as $uid) {
66
+            if( ($comment->getActorType() === 'users' && $uid === $comment->getActorId())
67
+                || !$this->userManager->userExists($uid)
68
+            ) {
69
+                // do not notify unknown users or yourself
70
+                continue;
71
+            }
72 72
 
73
-			$notification->setUser($uid);
74
-			if(    $event->getEvent() === CommentsEvent::EVENT_DELETE
75
-				|| $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE)
76
-			{
77
-				$this->notificationManager->markProcessed($notification);
78
-			} else {
79
-				$this->notificationManager->notify($notification);
80
-			}
81
-		}
82
-	}
73
+            $notification->setUser($uid);
74
+            if(    $event->getEvent() === CommentsEvent::EVENT_DELETE
75
+                || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE)
76
+            {
77
+                $this->notificationManager->markProcessed($notification);
78
+            } else {
79
+                $this->notificationManager->notify($notification);
80
+            }
81
+        }
82
+    }
83 83
 
84
-	/**
85
-	 * creates a notification instance and fills it with comment data
86
-	 *
87
-	 * @param IComment $comment
88
-	 * @return \OCP\Notification\INotification
89
-	 */
90
-	public function instantiateNotification(IComment $comment) {
91
-		$notification = $this->notificationManager->createNotification();
92
-		$notification
93
-			->setApp('comments')
94
-			->setObject('comment', $comment->getId())
95
-			->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ])
96
-			->setDateTime($comment->getCreationDateTime());
84
+    /**
85
+     * creates a notification instance and fills it with comment data
86
+     *
87
+     * @param IComment $comment
88
+     * @return \OCP\Notification\INotification
89
+     */
90
+    public function instantiateNotification(IComment $comment) {
91
+        $notification = $this->notificationManager->createNotification();
92
+        $notification
93
+            ->setApp('comments')
94
+            ->setObject('comment', $comment->getId())
95
+            ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ])
96
+            ->setDateTime($comment->getCreationDateTime());
97 97
 
98
-		return $notification;
99
-	}
98
+        return $notification;
99
+    }
100 100
 
101
-	/**
102
-	 * flattens the mention array returned from comments to a list of user ids.
103
-	 *
104
-	 * @param array $mentions
105
-	 * @return string[] containing the mentions, e.g. ['alice', 'bob']
106
-	 */
107
-	public function extractMentions(array $mentions) {
108
-		if(empty($mentions)) {
109
-			return [];
110
-		}
111
-		$uids = [];
112
-		foreach($mentions as $mention) {
113
-			if($mention['type'] === 'user') {
114
-				$uids[] = $mention['id'];
115
-			}
116
-		}
117
-		return $uids;
118
-	}
101
+    /**
102
+     * flattens the mention array returned from comments to a list of user ids.
103
+     *
104
+     * @param array $mentions
105
+     * @return string[] containing the mentions, e.g. ['alice', 'bob']
106
+     */
107
+    public function extractMentions(array $mentions) {
108
+        if(empty($mentions)) {
109
+            return [];
110
+        }
111
+        $uids = [];
112
+        foreach($mentions as $mention) {
113
+            if($mention['type'] === 'user') {
114
+                $uids[] = $mention['id'];
115
+            }
116
+        }
117
+        return $uids;
118
+    }
119 119
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -55,15 +55,15 @@  discard block
 block discarded – undo
55 55
 		$comment = $event->getComment();
56 56
 
57 57
 		$mentions = $this->extractMentions($comment->getMentions());
58
-		if(empty($mentions)) {
58
+		if (empty($mentions)) {
59 59
 			// no one to notify
60 60
 			return;
61 61
 		}
62 62
 
63 63
 		$notification = $this->instantiateNotification($comment);
64 64
 
65
-		foreach($mentions as $uid) {
66
-			if( ($comment->getActorType() === 'users' && $uid === $comment->getActorId())
65
+		foreach ($mentions as $uid) {
66
+			if (($comment->getActorType() === 'users' && $uid === $comment->getActorId())
67 67
 				|| !$this->userManager->userExists($uid)
68 68
 			) {
69 69
 				// do not notify unknown users or yourself
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 			}
72 72
 
73 73
 			$notification->setUser($uid);
74
-			if(    $event->getEvent() === CommentsEvent::EVENT_DELETE
74
+			if ($event->getEvent() === CommentsEvent::EVENT_DELETE
75 75
 				|| $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE)
76 76
 			{
77 77
 				$this->notificationManager->markProcessed($notification);
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 		$notification
93 93
 			->setApp('comments')
94 94
 			->setObject('comment', $comment->getId())
95
-			->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ])
95
+			->setSubject('mention', [$comment->getObjectType(), $comment->getObjectId()])
96 96
 			->setDateTime($comment->getCreationDateTime());
97 97
 
98 98
 		return $notification;
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
 	 * @return string[] containing the mentions, e.g. ['alice', 'bob']
106 106
 	 */
107 107
 	public function extractMentions(array $mentions) {
108
-		if(empty($mentions)) {
108
+		if (empty($mentions)) {
109 109
 			return [];
110 110
 		}
111 111
 		$uids = [];
112
-		foreach($mentions as $mention) {
113
-			if($mention['type'] === 'user') {
112
+		foreach ($mentions as $mention) {
113
+			if ($mention['type'] === 'user') {
114 114
 				$uids[] = $mention['id'];
115 115
 			}
116 116
 		}
Please login to merge, or discard this patch.