Completed
Pull Request — master (#5174)
by Björn
17:50
created
apps/encryption/templates/settings-admin.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,19 +7,19 @@  discard block
 block discarded – undo
7 7
 ?>
8 8
 <form id="ocDefaultEncryptionModule" class="sub-section">
9 9
 	<h3><?php p($l->t("Default encryption module")); ?></h3>
10
-	<?php if(!$_["initStatus"] && $_['masterKeyEnabled'] === false): ?>
10
+	<?php if (!$_["initStatus"] && $_['masterKeyEnabled'] === false): ?>
11 11
 		<?php p($l->t("Encryption app is enabled but your keys are not initialized, please log-out and log-in again")); ?>
12 12
 	<?php else: ?>
13 13
 		<p id="encryptHomeStorageSetting">
14 14
 			<input type="checkbox" class="checkbox" name="encrypt_home_storage" id="encryptHomeStorage"
15 15
 				   value="1" <?php if ($_['encryptHomeStorage']) print_unescaped('checked="checked"'); ?> />
16
-			<label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage'));?></label></br>
17
-			<em><?php p( $l->t( "Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted" ) ); ?></em>
16
+			<label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage')); ?></label></br>
17
+			<em><?php p($l->t("Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted")); ?></em>
18 18
 		</p>
19 19
 		<br />
20
-		<?php if($_['masterKeyEnabled'] === false): ?>
20
+		<?php if ($_['masterKeyEnabled'] === false): ?>
21 21
 			<p id="encryptionSetRecoveryKey">
22
-				<?php $_["recoveryEnabled"] === '0' ?  p($l->t("Enable recovery key")) : p($l->t("Disable recovery key")); ?>
22
+				<?php $_["recoveryEnabled"] === '0' ? p($l->t("Enable recovery key")) : p($l->t("Disable recovery key")); ?>
23 23
 				<span class="msg"></span>
24 24
 				<br/>
25 25
 				<em>
@@ -38,11 +38,11 @@  discard block
 block discarded – undo
38 38
 					   name="enableRecoveryKey"
39 39
 					   id="enableRecoveryKey"
40 40
 					   status="<?php p($_["recoveryEnabled"]) ?>"
41
-					   value="<?php $_["recoveryEnabled"] === '0' ?  p($l->t("Enable recovery key")) : p($l->t("Disable recovery key")); ?>"/>
41
+					   value="<?php $_["recoveryEnabled"] === '0' ? p($l->t("Enable recovery key")) : p($l->t("Disable recovery key")); ?>"/>
42 42
 			</p>
43 43
 			<br/><br/>
44 44
 
45
-			<p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"');?>>
45
+			<p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if ($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"'); ?>>
46 46
 				<?php p($l->t("Change recovery key password:")); ?>
47 47
 				<span class="msg"></span>
48 48
 				<br/>
Please login to merge, or discard this patch.
apps/encryption/lib/Controller/StatusController.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -70,34 +70,34 @@
 block discarded – undo
70 70
 
71 71
 		$status = 'error';
72 72
 		$message = 'no valid init status';
73
-		switch( $this->session->getStatus()) {
73
+		switch ($this->session->getStatus()) {
74 74
 			case Session::RUN_MIGRATION:
75 75
 				$status = 'interactionNeeded';
76
-				$message = (string)$this->l->t(
76
+				$message = (string) $this->l->t(
77 77
 					'You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one. Please run \'occ encryption:migrate\' or contact your administrator'
78 78
 				);
79 79
 				break;
80 80
 			case Session::INIT_EXECUTED:
81 81
 				$status = 'interactionNeeded';
82
-				$message = (string)$this->l->t(
82
+				$message = (string) $this->l->t(
83 83
 					'Invalid private key for encryption app. Please update your private key password in your personal settings to recover access to your encrypted files.'
84 84
 				);
85 85
 				break;
86 86
 			case Session::NOT_INITIALIZED:
87 87
 				$status = 'interactionNeeded';
88 88
 				if ($this->encryptionManager->isEnabled()) {
89
-					$message = (string)$this->l->t(
89
+					$message = (string) $this->l->t(
90 90
 						'Encryption App is enabled, but your keys are not initialized. Please log-out and log-in again.'
91 91
 					);
92 92
 				} else {
93
-					$message = (string)$this->l->t(
93
+					$message = (string) $this->l->t(
94 94
 						'Please enable server side encryption in the admin settings in order to use the encryption module.'
95 95
 					);
96 96
 				}
97 97
 				break;
98 98
 			case Session::INIT_SUCCESSFUL:
99 99
 				$status = 'success';
100
-				$message = (string)$this->l->t('Encryption app is enabled and ready');
100
+				$message = (string) $this->l->t('Encryption app is enabled and ready');
101 101
 		}
102 102
 
103 103
 		return new DataResponse(
Please login to merge, or discard this patch.
apps/encryption/lib/Command/DisableMasterKey.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
 
68 68
 		$isMasterKeyEnabled = $this->util->isMasterKeyEnabled();
69 69
 
70
-		if(!$isMasterKeyEnabled) {
70
+		if (!$isMasterKeyEnabled) {
71 71
 			$output->writeln('Master key already disabled');
72 72
 		} else {
73 73
 			$question = new ConfirmationQuestion(
Please login to merge, or discard this patch.
apps/encryption/lib/KeyManager.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		$this->recoveryKeyId = $this->config->getAppValue('encryption',
127 127
 			'recoveryKeyId');
128 128
 		if (empty($this->recoveryKeyId)) {
129
-			$this->recoveryKeyId = 'recoveryKey_' . substr(md5(time()), 0, 8);
129
+			$this->recoveryKeyId = 'recoveryKey_'.substr(md5(time()), 0, 8);
130 130
 			$this->config->setAppValue('encryption',
131 131
 				'recoveryKeyId',
132 132
 				$this->recoveryKeyId);
@@ -135,14 +135,14 @@  discard block
 block discarded – undo
135 135
 		$this->publicShareKeyId = $this->config->getAppValue('encryption',
136 136
 			'publicShareKeyId');
137 137
 		if (empty($this->publicShareKeyId)) {
138
-			$this->publicShareKeyId = 'pubShare_' . substr(md5(time()), 0, 8);
138
+			$this->publicShareKeyId = 'pubShare_'.substr(md5(time()), 0, 8);
139 139
 			$this->config->setAppValue('encryption', 'publicShareKeyId', $this->publicShareKeyId);
140 140
 		}
141 141
 
142 142
 		$this->masterKeyId = $this->config->getAppValue('encryption',
143 143
 			'masterKeyId');
144 144
 		if (empty($this->masterKeyId)) {
145
-			$this->masterKeyId = 'master_' . substr(md5(time()), 0, 8);
145
+			$this->masterKeyId = 'master_'.substr(md5(time()), 0, 8);
146 146
 			$this->config->setAppValue('encryption', 'masterKeyId', $this->masterKeyId);
147 147
 		}
148 148
 
@@ -160,13 +160,13 @@  discard block
 block discarded – undo
160 160
 
161 161
 			// Save public key
162 162
 			$this->keyStorage->setSystemUserKey(
163
-				$this->publicShareKeyId . '.publicKey', $keyPair['publicKey'],
163
+				$this->publicShareKeyId.'.publicKey', $keyPair['publicKey'],
164 164
 				Encryption::ID);
165 165
 
166 166
 			// Encrypt private key empty passphrase
167 167
 			$encryptedKey = $this->crypt->encryptPrivateKey($keyPair['privateKey'], '');
168 168
 			$header = $this->crypt->generateHeader();
169
-			$this->setSystemPrivateKey($this->publicShareKeyId, $header . $encryptedKey);
169
+			$this->setSystemPrivateKey($this->publicShareKeyId, $header.$encryptedKey);
170 170
 		}
171 171
 	}
172 172
 
@@ -185,13 +185,13 @@  discard block
 block discarded – undo
185 185
 
186 186
 			// Save public key
187 187
 			$this->keyStorage->setSystemUserKey(
188
-				$this->masterKeyId . '.publicKey', $keyPair['publicKey'],
188
+				$this->masterKeyId.'.publicKey', $keyPair['publicKey'],
189 189
 				Encryption::ID);
190 190
 
191 191
 			// Encrypt private key with system password
192 192
 			$encryptedKey = $this->crypt->encryptPrivateKey($keyPair['privateKey'], $this->getMasterKeyPassword(), $this->masterKeyId);
193 193
 			$header = $this->crypt->generateHeader();
194
-			$this->setSystemPrivateKey($this->masterKeyId, $header . $encryptedKey);
194
+			$this->setSystemPrivateKey($this->masterKeyId, $header.$encryptedKey);
195 195
 		}
196 196
 
197 197
 		if (!$this->session->isPrivateKeySet()) {
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	 * @return string
219 219
 	 */
220 220
 	public function getRecoveryKey() {
221
-		return $this->keyStorage->getSystemUserKey($this->recoveryKeyId . '.publicKey', Encryption::ID);
221
+		return $this->keyStorage->getSystemUserKey($this->recoveryKeyId.'.publicKey', Encryption::ID);
222 222
 	}
223 223
 
224 224
 	/**
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	 * @return bool
236 236
 	 */
237 237
 	public function checkRecoveryPassword($password) {
238
-		$recoveryKey = $this->keyStorage->getSystemUserKey($this->recoveryKeyId . '.privateKey', Encryption::ID);
238
+		$recoveryKey = $this->keyStorage->getSystemUserKey($this->recoveryKeyId.'.privateKey', Encryption::ID);
239 239
 		$decryptedRecoveryKey = $this->crypt->decryptPrivateKey($recoveryKey, $password);
240 240
 
241 241
 		if ($decryptedRecoveryKey) {
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 		$header = $this->crypt->generateHeader();
260 260
 
261 261
 		if ($encryptedKey) {
262
-			$this->setPrivateKey($uid, $header . $encryptedKey);
262
+			$this->setPrivateKey($uid, $header.$encryptedKey);
263 263
 			return true;
264 264
 		}
265 265
 		return false;
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 		$header = $this->crypt->generateHeader();
282 282
 
283 283
 		if ($encryptedKey) {
284
-			$this->setSystemPrivateKey($this->getRecoveryKeyId(), $header . $encryptedKey);
284
+			$this->setSystemPrivateKey($this->getRecoveryKeyId(), $header.$encryptedKey);
285 285
 			return true;
286 286
 		}
287 287
 		return false;
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 	 * @return boolean
342 342
 	 */
343 343
 	public function setShareKey($path, $uid, $key) {
344
-		$keyId = $uid . '.' . $this->shareKeyId;
344
+		$keyId = $uid.'.'.$this->shareKeyId;
345 345
 		return $this->keyStorage->setFileKey($path, $keyId, $key, Encryption::ID);
346 346
 	}
347 347
 
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 		$this->session->setStatus(Session::INIT_EXECUTED);
358 358
 
359 359
 		try {
360
-			if($this->util->isMasterKeyEnabled()) {
360
+			if ($this->util->isMasterKeyEnabled()) {
361 361
 				$uid = $this->getMasterKeyId();
362 362
 				$passPhrase = $this->getMasterKeyPassword();
363 363
 				$privateKey = $this->getSystemPrivateKey($uid);
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 			return false;
372 372
 		} catch (\Exception $e) {
373 373
 			$this->log->warning(
374
-				'Could not decrypt the private key from user "' . $uid . '"" during login. ' .
374
+				'Could not decrypt the private key from user "'.$uid.'"" during login. '.
375 375
 				'Assume password change on the user back-end. Error message: '
376 376
 				. $e->getMessage()
377 377
 			);
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 			// use public share key for public links
433 433
 			$uid = $this->getPublicShareKeyId();
434 434
 			$shareKey = $this->getShareKey($path, $uid);
435
-			$privateKey = $this->keyStorage->getSystemUserKey($this->publicShareKeyId . '.privateKey', Encryption::ID);
435
+			$privateKey = $this->keyStorage->getSystemUserKey($this->publicShareKeyId.'.privateKey', Encryption::ID);
436 436
 			$privateKey = $this->crypt->decryptPrivateKey($privateKey);
437 437
 		} else {
438 438
 			$shareKey = $this->getShareKey($path, $uid);
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 	 */
458 458
 	public function getVersion($path, View $view) {
459 459
 		$fileInfo = $view->getFileInfo($path);
460
-		if($fileInfo === false) {
460
+		if ($fileInfo === false) {
461 461
 			return 0;
462 462
 		}
463 463
 		return $fileInfo->getEncryptedVersion();
@@ -471,9 +471,9 @@  discard block
 block discarded – undo
471 471
 	 * @param View $view
472 472
 	 */
473 473
 	public function setVersion($path, $version, View $view) {
474
-		$fileInfo= $view->getFileInfo($path);
474
+		$fileInfo = $view->getFileInfo($path);
475 475
 
476
-		if($fileInfo !== false) {
476
+		if ($fileInfo !== false) {
477 477
 			$cache = $fileInfo->getStorage()->getCache();
478 478
 			$cache->update($fileInfo->getId(), ['encrypted' => $version, 'encryptedVersion' => $version]);
479 479
 		}
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 	public function deleteShareKey($path, $keyId) {
503 503
 		return $this->keyStorage->deleteFileKey(
504 504
 			$path,
505
-			$keyId . '.' . $this->shareKeyId,
505
+			$keyId.'.'.$this->shareKeyId,
506 506
 			Encryption::ID);
507 507
 	}
508 508
 
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 	 * @return mixed
514 514
 	 */
515 515
 	public function getShareKey($path, $uid) {
516
-		$keyId = $uid . '.' . $this->shareKeyId;
516
+		$keyId = $uid.'.'.$this->shareKeyId;
517 517
 		return $this->keyStorage->getFileKey($path, $keyId, Encryption::ID);
518 518
 	}
519 519
 
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
 	 * @return string
576 576
 	 */
577 577
 	public function getPublicShareKey() {
578
-		return $this->keyStorage->getSystemUserKey($this->publicShareKeyId . '.publicKey', Encryption::ID);
578
+		return $this->keyStorage->getSystemUserKey($this->publicShareKeyId.'.publicKey', Encryption::ID);
579 579
 	}
580 580
 
581 581
 	/**
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
 	 * @return string returns openssl key
646 646
 	 */
647 647
 	public function getSystemPrivateKey($keyId) {
648
-		return $this->keyStorage->getSystemUserKey($keyId . '.' . $this->privateKeyId, Encryption::ID);
648
+		return $this->keyStorage->getSystemUserKey($keyId.'.'.$this->privateKeyId, Encryption::ID);
649 649
 	}
650 650
 
651 651
 	/**
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
 	 */
656 656
 	public function setSystemPrivateKey($keyId, $key) {
657 657
 		return $this->keyStorage->setSystemUserKey(
658
-			$keyId . '.' . $this->privateKeyId,
658
+			$keyId.'.'.$this->privateKeyId,
659 659
 			$key,
660 660
 			Encryption::ID);
661 661
 	}
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 	 */
696 696
 	public function getMasterKeyPassword() {
697 697
 		$password = $this->config->getSystemValue('secret');
698
-		if (empty($password)){
698
+		if (empty($password)) {
699 699
 			throw new \Exception('Can not get secret from Nextcloud instance');
700 700
 		}
701 701
 
@@ -717,6 +717,6 @@  discard block
 block discarded – undo
717 717
 	 * @return string
718 718
 	 */
719 719
 	public function getPublicMasterKey() {
720
-		return $this->keyStorage->getSystemUserKey($this->masterKeyId . '.publicKey', Encryption::ID);
720
+		return $this->keyStorage->getSystemUserKey($this->masterKeyId.'.publicKey', Encryption::ID);
721 721
 	}
722 722
 }
Please login to merge, or discard this patch.