Completed
Pull Request — master (#3643)
by Christoph
12:28
created
lib/private/Security/CSRF/CsrfTokenManager.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 	 * @return CsrfToken
54 54
 	 */
55 55
 	public function getToken() {
56
-		if(!is_null($this->csrfToken)) {
56
+		if (!is_null($this->csrfToken)) {
57 57
 			return $this->csrfToken;
58 58
 		}
59 59
 
60
-		if($this->sessionStorage->hasToken()) {
60
+		if ($this->sessionStorage->hasToken()) {
61 61
 			$value = $this->sessionStorage->getToken();
62 62
 		} else {
63 63
 			$value = $this->tokenGenerator->generateToken();
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 * @return bool
96 96
 	 */
97 97
 	public function isTokenValid(CsrfToken $token) {
98
-		if(!$this->sessionStorage->hasToken()) {
98
+		if (!$this->sessionStorage->hasToken()) {
99 99
 			return false;
100 100
 		}
101 101
 
Please login to merge, or discard this patch.
lib/private/Security/Crypto.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
68 68
 	 * @return string Calculated HMAC
69 69
 	 */
70 70
 	public function calculateHMAC($message, $password = '') {
71
-		if($password === '') {
71
+		if ($password === '') {
72 72
 			$password = $this->config->getSystemValue('secret');
73 73
 		}
74 74
 
75 75
 		// Append an "a" behind the password and hash it to prevent reusing the same password as for encryption
76
-		$password = hash('sha512', $password . 'a');
76
+		$password = hash('sha512', $password.'a');
77 77
 
78 78
 		$hash = new Hash('sha512');
79 79
 		$hash->setKey($password);
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @return string Authenticated ciphertext
88 88
 	 */
89 89
 	public function encrypt($plaintext, $password = '') {
90
-		if($password === '') {
90
+		if ($password === '') {
91 91
 			$password = $this->config->getSystemValue('secret');
92 92
 		}
93 93
 		$this->cipher->setPassword($password);
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
 	 * @throws \Exception If the HMAC does not match
110 110
 	 */
111 111
 	public function decrypt($authenticatedCiphertext, $password = '') {
112
-		if($password === '') {
112
+		if ($password === '') {
113 113
 			$password = $this->config->getSystemValue('secret');
114 114
 		}
115 115
 		$this->cipher->setPassword($password);
116 116
 
117 117
 		$parts = explode('|', $authenticatedCiphertext);
118
-		if(sizeof($parts) !== 3) {
118
+		if (sizeof($parts) !== 3) {
119 119
 			throw new \Exception('Authenticated ciphertext could not be decoded.');
120 120
 		}
121 121
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
 		$this->cipher->setIV($iv);
127 127
 
128
-		if(!hash_equals($this->calculateHMAC($parts[0].$parts[1], $password), $hmac)) {
128
+		if (!hash_equals($this->calculateHMAC($parts[0].$parts[1], $password), $hmac)) {
129 129
 			throw new \Exception('HMAC does not match.');
130 130
 		}
131 131
 
Please login to merge, or discard this patch.
lib/private/Security/SecureRandom.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@
 block discarded – undo
77 77
 		$maxCharIndex = strlen($characters) - 1;
78 78
 		$randomString = '';
79 79
 
80
-		while($length > 0) {
80
+		while ($length > 0) {
81 81
 			$randomNumber = \random_int(0, $maxCharIndex);
82 82
 			$randomString .= $characters[$randomNumber];
83 83
 			$length--;
Please login to merge, or discard this patch.
lib/private/Security/Certificate.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -54,19 +54,19 @@
 block discarded – undo
54 54
 
55 55
 		// If string starts with "file://" ignore the certificate
56 56
 		$query = 'file://';
57
-		if(strtolower(substr($data, 0, strlen($query))) === $query) {
57
+		if (strtolower(substr($data, 0, strlen($query))) === $query) {
58 58
 			throw new \Exception('Certificate could not get parsed.');
59 59
 		}
60 60
 
61 61
 		$info = openssl_x509_parse($data);
62
-		if(!is_array($info)) {
62
+		if (!is_array($info)) {
63 63
 			throw new \Exception('Certificate could not get parsed.');
64 64
 		}
65 65
 
66 66
 		$this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null;
67 67
 		$this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null;
68
-		$this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt);
69
-		$this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt);
68
+		$this->issueDate = new \DateTime('@'.$info['validFrom_time_t'], $gmt);
69
+		$this->expireDate = new \DateTime('@'.$info['validTo_time_t'], $gmt);
70 70
 		$this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null;
71 71
 		$this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null;
72 72
 	}
Please login to merge, or discard this patch.
lib/private/Security/IdentityProof/Signer.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	 * @return bool
78 78
 	 */
79 79
 	public function verify(array $data) {
80
-		if(isset($data['message'])
80
+		if (isset($data['message'])
81 81
 			&& isset($data['signature'])
82 82
 			&& isset($data['message']['signer'])
83 83
 		) {
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 			$userId = substr($data['message']['signer'], 0, $location);
86 86
 
87 87
 			$user = $this->userManager->get($userId);
88
-			if($user !== null) {
88
+			if ($user !== null) {
89 89
 				$key = $this->keyManager->getKey($user);
90
-				return (bool)openssl_verify(
90
+				return (bool) openssl_verify(
91 91
 					json_encode($data['message']),
92 92
 					base64_decode($data['signature']),
93 93
 					$key->getPublic(),
Please login to merge, or discard this patch.
lib/private/Security/Bruteforce/Throttler.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	private function getCutoff($expire) {
79 79
 		$d1 = new \DateTime();
80 80
 		$d2 = clone $d1;
81
-		$d2->sub(new \DateInterval('PT' . $expire . 'S'));
81
+		$d2->sub(new \DateInterval('PT'.$expire.'S'));
82 82
 		return $d2->diff($d1);
83 83
 	}
84 84
 
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 									$ip,
155 155
 									array $metadata = []) {
156 156
 		// No need to log if the bruteforce protection is disabled
157
-		if($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
157
+		if ($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
158 158
 			return;
159 159
 		}
160 160
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 
180 180
 		$qb = $this->db->getQueryBuilder();
181 181
 		$qb->insert('bruteforce_attempts');
182
-		foreach($values as $column => $value) {
182
+		foreach ($values as $column => $value) {
183 183
 			$qb->setValue($column, $qb->createNamedParameter($value));
184 184
 		}
185 185
 		$qb->execute();
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 
216 216
 		$maxDelay = 30;
217 217
 		$firstDelay = 0.1;
218
-		if ($attempts > (8 * PHP_INT_SIZE - 1))  {
218
+		if ($attempts > (8 * PHP_INT_SIZE - 1)) {
219 219
 			// Don't ever overflow. Just assume the maxDelay time:s
220 220
 			$firstDelay = $maxDelay;
221 221
 		} else {
Please login to merge, or discard this patch.
lib/private/Security/CertificateManager.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 			return array();
81 81
 		}
82 82
 
83
-		$path = $this->getPathToCertificates() . 'uploads/';
83
+		$path = $this->getPathToCertificates().'uploads/';
84 84
 		if (!$this->view->is_dir($path)) {
85 85
 			return array();
86 86
 		}
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 		while (false !== ($file = readdir($handle))) {
93 93
 			if ($file != '.' && $file != '..') {
94 94
 				try {
95
-					$result[] = new Certificate($this->view->file_get_contents($path . $file), $file);
95
+					$result[] = new Certificate($this->view->file_get_contents($path.$file), $file);
96 96
 				} catch (\Exception $e) {
97 97
 				}
98 98
 			}
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
 			$this->view->mkdir($path);
113 113
 		}
114 114
 
115
-		$defaultCertificates = file_get_contents(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
115
+		$defaultCertificates = file_get_contents(\OC::$SERVERROOT.'/resources/config/ca-bundle.crt');
116 116
 		if (strlen($defaultCertificates) < 1024) { // sanity check to verify that we have some content for our bundle
117 117
 			// log as exception so we have a stacktrace
118 118
 			$this->logger->logException(new \Exception('Shipped ca-bundle is empty, refusing to create certificate bundle'));
119 119
 			return;
120 120
 		}
121 121
 
122
-		$fhCerts = $this->view->fopen($path . '/rootcerts.crt', 'w');
122
+		$fhCerts = $this->view->fopen($path.'/rootcerts.crt', 'w');
123 123
 
124 124
 		// Write user certificates
125 125
 		foreach ($certs as $cert) {
126
-			$file = $path . '/uploads/' . $cert->getName();
126
+			$file = $path.'/uploads/'.$cert->getName();
127 127
 			$data = $this->view->file_get_contents($file);
128 128
 			if (strpos($data, 'BEGIN CERTIFICATE')) {
129 129
 				fwrite($fhCerts, $data);
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
 			throw new \Exception('Filename is not valid');
158 158
 		}
159 159
 
160
-		$dir = $this->getPathToCertificates() . 'uploads/';
160
+		$dir = $this->getPathToCertificates().'uploads/';
161 161
 		if (!$this->view->file_exists($dir)) {
162 162
 			$this->view->mkdir($dir);
163 163
 		}
164 164
 
165 165
 		try {
166
-			$file = $dir . $name;
166
+			$file = $dir.$name;
167 167
 			$certificateObject = new Certificate($certificate, $name);
168 168
 			$this->view->file_put_contents($file, $certificate);
169 169
 			$this->createCertificateBundle();
@@ -184,9 +184,9 @@  discard block
 block discarded – undo
184 184
 		if (!Filesystem::isValidPath($name)) {
185 185
 			return false;
186 186
 		}
187
-		$path = $this->getPathToCertificates() . 'uploads/';
188
-		if ($this->view->file_exists($path . $name)) {
189
-			$this->view->unlink($path . $name);
187
+		$path = $this->getPathToCertificates().'uploads/';
188
+		if ($this->view->file_exists($path.$name)) {
189
+			$this->view->unlink($path.$name);
190 190
 			$this->createCertificateBundle();
191 191
 		}
192 192
 		return true;
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 		if ($uid === '') {
203 203
 			$uid = $this->uid;
204 204
 		}
205
-		return $this->getPathToCertificates($uid) . 'rootcerts.crt';
205
+		return $this->getPathToCertificates($uid).'rootcerts.crt';
206 206
 	}
207 207
 
208 208
 	/**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 		if ($uid === '') {
235 235
 			$uid = $this->uid;
236 236
 		}
237
-		$path = is_null($uid) ? '/files_external/' : '/' . $uid . '/files_external/';
237
+		$path = is_null($uid) ? '/files_external/' : '/'.$uid.'/files_external/';
238 238
 
239 239
 		return $path;
240 240
 	}
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 			$sourceMTimes[] = $this->view->filemtime($this->getCertificateBundle(null));
260 260
 		}
261 261
 
262
-		$sourceMTime = array_reduce($sourceMTimes, function ($max, $mtime) {
262
+		$sourceMTime = array_reduce($sourceMTimes, function($max, $mtime) {
263 263
 			return max($max, $mtime);
264 264
 		}, 0);
265 265
 		return $sourceMTime > $this->view->filemtime($targetBundle);
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 	 * @return int
272 272
 	 */
273 273
 	protected function getFilemtimeOfCaBundle() {
274
-		return filemtime(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
274
+		return filemtime(\OC::$SERVERROOT.'/resources/config/ca-bundle.crt');
275 275
 	}
276 276
 
277 277
 }
Please login to merge, or discard this patch.
lib/private/TempManager.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -65,13 +65,13 @@  discard block
 block discarded – undo
65 65
 	 * @return string
66 66
 	 */
67 67
 	private function buildFileNameWithSuffix($absolutePath, $postFix = '') {
68
-		if($postFix !== '') {
69
-			$postFix = '.' . ltrim($postFix, '.');
68
+		if ($postFix !== '') {
69
+			$postFix = '.'.ltrim($postFix, '.');
70 70
 			$postFix = str_replace(['\\', '/'], '', $postFix);
71 71
 			$absolutePath .= '-';
72 72
 		}
73 73
 
74
-		return $absolutePath . $postFix;
74
+		return $absolutePath.$postFix;
75 75
 	}
76 76
 
77 77
 	/**
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 
92 92
 			// If a postfix got specified sanitize it and create a postfixed
93 93
 			// temporary file
94
-			if($postFix !== '') {
94
+			if ($postFix !== '') {
95 95
 				$fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix);
96 96
 				touch($fileNameWithPostfix);
97 97
 				chmod($fileNameWithPostfix, 0600);
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
 			$this->current[] = $uniqueFileName;
128 128
 
129 129
 			// Build a name without postfix
130
-			$path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix);
130
+			$path = $this->buildFileNameWithSuffix($uniqueFileName.'-folder', $postFix);
131 131
 			mkdir($path, 0700);
132 132
 			$this->current[] = $path;
133 133
 
134
-			return $path . '/';
134
+			return $path.'/';
135 135
 		} else {
136 136
 			$this->log->warning(
137 137
 				'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 		if ($dh) {
191 191
 			while (($file = readdir($dh)) !== false) {
192 192
 				if (substr($file, 0, 7) === self::TMP_PREFIX) {
193
-					$path = $this->tmpBaseDir . '/' . $file;
193
+					$path = $this->tmpBaseDir.'/'.$file;
194 194
 					$mtime = filemtime($path);
195 195
 					if ($mtime < $cutOfTime) {
196 196
 						$files[] = $path;
Please login to merge, or discard this patch.
lib/private/Federation/CloudIdManager.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@
 block discarded – undo
75 75
 	 */
76 76
 	public function getCloudId($user, $remote) {
77 77
 		// TODO check what the correct url is for remote (asking the remote)
78
-		return new CloudId($user. '@' . $remote, $user, $remote);
78
+		return new CloudId($user.'@'.$remote, $user, $remote);
79 79
 	}
80 80
 
81 81
 	/**
Please login to merge, or discard this patch.