Passed
Branch master (52717f)
by John
02:35
created
exampleHTTP.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -16,19 +16,19 @@  discard block
 block discarded – undo
16 16
 // Initiating the order instance. The keys and certificate will be stored in /example.org/ (argument 1) and the domains in the array (argument 2) will be on the certificate.
17 17
 $order = $client->getOrCreateOrder($basename, $domains);
18 18
 // Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations.
19
-if(!$order->allAuthorizationsValid())
19
+if (!$order->allAuthorizationsValid())
20 20
 {
21 21
 	// Get the HTTP challenges from the pending authorizations.
22 22
 	$pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_HTTP);
23 23
 	// Walk the list of pending authorization HTTP challenges.
24
-	if(!empty($pending))
24
+	if (!empty($pending))
25 25
 	{
26
-		foreach($pending as $challenge)
26
+		foreach ($pending as $challenge)
27 27
 		{
28 28
 			// Define the folder in which to store the challenge. For the purpose of this example, a fictitious path is set.
29 29
 			$folder = '/path/to/' . $challenge['identifier'] . '/.well-known/acme-challenge/';
30 30
 			// Check if that directory yet exists. If not, create it.
31
-			if(!file_exists($folder)) mkdir($folder, 0777, true);
31
+			if (!file_exists($folder)) mkdir($folder, 0777, true);
32 32
 			// Store the challenge file for this domain.
33 33
 			file_put_contents($folder . $challenge['filename'], $challenge['content']);
34 34
 			// Let LetsEncrypt verify this challenge.
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
 	}
38 38
 }
39 39
 // Check once more whether all authorizations are valid before we can finalize the order.
40
-if($order->allAuthorizationsValid())
40
+if ($order->allAuthorizationsValid())
41 41
 {
42 42
 	// Finalize the order first, if that is not yet done.
43
-	if(!$order->isFinalized()) $order->finalizeOrder();
43
+	if (!$order->isFinalized()) $order->finalizeOrder();
44 44
 	// Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate.
45
-	if($order->isFinalized()) $order->getCertificate();
45
+	if ($order->isFinalized()) $order->getCertificate();
46 46
 }
47 47
 ?>
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
LEClient/LEClient.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 
57 57
 	private $log;
58 58
 
59
-	const LOG_OFF = 0;		// Logs no messages or faults, except Runtime Exceptions.
60
-	const LOG_STATUS = 1;	// Logs only messages and faults.
61
-	const LOG_DEBUG = 2;	// Logs messages, faults and raw responses from HTTP requests.
59
+	const LOG_OFF = 0; // Logs no messages or faults, except Runtime Exceptions.
60
+	const LOG_STATUS = 1; // Logs only messages and faults.
61
+	const LOG_DEBUG = 2; // Logs messages, faults and raw responses from HTTP requests.
62 62
 
63 63
     /**
64 64
      * Initiates the LetsEncrypt main client.
@@ -95,18 +95,18 @@  discard block
 block discarded – undo
95 95
 
96 96
 			$certificateKeysDir = $certificateKeys;
97 97
 
98
-			if(!file_exists($certificateKeys))
98
+			if (!file_exists($certificateKeys))
99 99
 			{
100 100
 				mkdir($certificateKeys, 0777, true);
101 101
 				LEFunctions::createhtaccess($certificateKeys);
102 102
 			}
103 103
 
104 104
 			$this->certificateKeys = array(
105
-				"public_key" => $certificateKeys.'/public.pem',
106
-				"private_key" => $certificateKeys.'/private.pem',
107
-				"certificate" => $certificateKeys.'/certificate.crt',
108
-				"fullchain_certificate" => $certificateKeys.'/fullchain.crt',
109
-				"order" => $certificateKeys.'/order'
105
+				"public_key" => $certificateKeys . '/public.pem',
106
+				"private_key" => $certificateKeys . '/private.pem',
107
+				"certificate" => $certificateKeys . '/certificate.crt',
108
+				"fullchain_certificate" => $certificateKeys . '/fullchain.crt',
109
+				"order" => $certificateKeys . '/order'
110 110
 			);
111 111
 
112 112
 		}
@@ -115,12 +115,12 @@  discard block
 block discarded – undo
115 115
 
116 116
 			if (!isset($certificateKeys['certificate']) && !isset($certificateKeys['fullchain_certificate'])) throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] file path must be set');
117 117
 			if (!isset($certificateKeys['private_key'])) throw new \RuntimeException('certificateKeys[private_key] file path must be set');
118
-			if (!isset($certificateKeys['order'])) $certificateKeys['order'] = dirname($certificateKeys['private_key']).'/order';
119
-			if (!isset($certificateKeys['public_key'])) $certificateKeys['public_key'] = dirname($certificateKeys['private_key']).'/public.pem';
118
+			if (!isset($certificateKeys['order'])) $certificateKeys['order'] = dirname($certificateKeys['private_key']) . '/order';
119
+			if (!isset($certificateKeys['public_key'])) $certificateKeys['public_key'] = dirname($certificateKeys['private_key']) . '/public.pem';
120 120
 
121 121
 			foreach ($certificateKeys as $param => $file) {
122 122
 				$parentDir = dirname($file);
123
-				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir.' directory not found');
123
+				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir . ' directory not found');
124 124
 			}
125 125
 
126 126
 			$this->certificateKeys = $certificateKeys;
@@ -134,17 +134,17 @@  discard block
 block discarded – undo
134 134
 		if (is_string($accountKeys))
135 135
 		{
136 136
 
137
-			$accountKeys = $certificateKeysDir.'/'.$accountKeys;
137
+			$accountKeys = $certificateKeysDir . '/' . $accountKeys;
138 138
 
139
-			if(!file_exists($accountKeys))
139
+			if (!file_exists($accountKeys))
140 140
 			{
141 141
 				mkdir($accountKeys, 0777, true);
142 142
 				LEFunctions::createhtaccess($accountKeys);
143 143
 			}
144 144
 
145 145
 			$this->accountKeys = array(
146
-				"private_key" => $accountKeys.'/private.pem',
147
-				"public_key" => $accountKeys.'/public.pem'
146
+				"private_key" => $accountKeys . '/private.pem',
147
+				"public_key" => $accountKeys . '/public.pem'
148 148
 			);
149 149
 		}
150 150
 		elseif (is_array($accountKeys))
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 
155 155
 			foreach ($accountKeys as $param => $file) {
156 156
 				$parentDir = dirname($file);
157
-				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir.' directory not found');
157
+				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir . ' directory not found');
158 158
 			}
159 159
 
160 160
 			$this->accountKeys = $accountKeys;
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 
168 168
 		$this->connector = new LEConnector($this->log, $this->baseURL, $this->accountKeys);
169 169
 		$this->account = new LEAccount($this->connector, $this->log, $email, $this->accountKeys);
170
-		if($this->log) LEFunctions::log('LEClient finished constructing', 'function LEClient __construct');
170
+		if ($this->log) LEFunctions::log('LEClient finished constructing', 'function LEClient __construct');
171 171
 	}
172 172
 
173 173
 
Please login to merge, or discard this patch.
LEClient/src/LEOrder.php 1 patch
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -100,23 +100,23 @@  discard block
 block discarded – undo
100 100
 
101 101
 		$this->certificateKeys = $certificateKeys;
102 102
 
103
-		if(file_exists($this->certificateKeys['private_key']) AND file_exists($this->certificateKeys['order']) AND file_exists($this->certificateKeys['public_key']))
103
+		if (file_exists($this->certificateKeys['private_key']) AND file_exists($this->certificateKeys['order']) AND file_exists($this->certificateKeys['public_key']))
104 104
 		{
105 105
 			$this->orderURL = file_get_contents($this->certificateKeys['order']);
106 106
 			if (filter_var($this->orderURL, FILTER_VALIDATE_URL))
107 107
 			{
108 108
 				$get = $this->connector->get($this->orderURL);
109
-				if(strpos($get['header'], "200 OK") !== false)
109
+				if (strpos($get['header'], "200 OK") !== false)
110 110
 				{
111 111
 					$orderdomains = array_map(function($ident) { return $ident['value']; }, $get['body']['identifiers']);
112 112
 					$diff = array_merge(array_diff($orderdomains, $domains), array_diff($domains, $orderdomains));
113
-					if(!empty($diff))
113
+					if (!empty($diff))
114 114
 					{
115 115
 						foreach ($this->certificateKeys as $file)
116 116
 						{
117
-							if (is_file($file)) rename($file, $file.'.old');
117
+							if (is_file($file)) rename($file, $file . '.old');
118 118
 						}
119
-						if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct');
119
+						if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct');
120 120
 						$this->createOrder($domains, $notBefore, $notAfter, $keyType);
121 121
 					}
122 122
 					else
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 						$this->identifiers = $get['body']['identifiers'];
127 127
 						$this->authorizationURLs = $get['body']['authorizations'];
128 128
 						$this->finalizeURL = $get['body']['finalize'];
129
-						if(array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
129
+						if (array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
130 130
 						$this->updateAuthorizations();
131 131
 					}
132 132
 				}
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 					{
137 137
 						if (is_file($file)) unlink($file);
138 138
 					}
139
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
139
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
140 140
 					$this->createOrder($domains, $notBefore, $notAfter);
141 141
 				}
142 142
 			}
@@ -147,14 +147,14 @@  discard block
 block discarded – undo
147 147
 				{
148 148
 					if (is_file($file)) unlink($file);
149 149
 				}
150
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
150
+				if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
151 151
 
152 152
 				$this->createOrder($domains, $notBefore, $notAfter);
153 153
 			}
154 154
 		}
155 155
 		else
156 156
 		{
157
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct');
157
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct');
158 158
 			$this->createOrder($domains, $notBefore, $notAfter);
159 159
 		}
160 160
 	}
@@ -168,22 +168,22 @@  discard block
 block discarded – undo
168 168
      */
169 169
 	private function createOrder($domains, $notBefore, $notAfter)
170 170
 	{
171
-		if(preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notBefore) AND preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notAfter))
171
+		if (preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notBefore) AND preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notAfter))
172 172
 		{
173 173
 
174 174
 			$dns = array();
175
-			foreach($domains as $domain)
175
+			foreach ($domains as $domain)
176 176
 			{
177
-				if(preg_match_all('~(\*\.)~', $domain) > 1) throw new \RuntimeException('Cannot create orders with multiple wildcards in one domain.');
177
+				if (preg_match_all('~(\*\.)~', $domain) > 1) throw new \RuntimeException('Cannot create orders with multiple wildcards in one domain.');
178 178
 				$dns[] = array('type' => 'dns', 'value' => $domain);
179 179
 			}
180 180
 			$payload = array("identifiers" => $dns, 'notBefore' => $notBefore, 'notAfter' => $notAfter);
181 181
 			$sign = $this->connector->signRequestKid($payload, $this->connector->accountURL, $this->connector->newOrder);
182 182
 			$post = $this->connector->post($this->connector->newOrder, $sign);
183 183
 
184
-			if(strpos($post['header'], "201 Created") !== false)
184
+			if (strpos($post['header'], "201 Created") !== false)
185 185
 			{
186
-				if(preg_match('~Location: (\S+)~i', $post['header'], $matches))
186
+				if (preg_match('~Location: (\S+)~i', $post['header'], $matches))
187 187
 				{
188 188
 					$this->orderURL = trim($matches[1]);
189 189
 					file_put_contents($this->certificateKeys['order'], $this->orderURL);
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
 					$this->identifiers = $post['body']['identifiers'];
206 206
 					$this->authorizationURLs = $post['body']['authorizations'];
207 207
 					$this->finalizeURL = $post['body']['finalize'];
208
-					if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
208
+					if (array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
209 209
 					$this->updateAuthorizations();
210 210
 
211
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)');
211
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)');
212 212
 				}
213 213
 				else
214 214
 				{
@@ -232,19 +232,19 @@  discard block
 block discarded – undo
232 232
 	private function updateOrderData()
233 233
 	{
234 234
 		$get = $this->connector->get($this->orderURL);
235
-		if(strpos($get['header'], "200 OK") !== false)
235
+		if (strpos($get['header'], "200 OK") !== false)
236 236
 		{
237 237
 			$this->status = $get['body']['status'];
238 238
 			$this->expires = $get['body']['expires'];
239 239
 			$this->identifiers = $get['body']['identifiers'];
240 240
 			$this->authorizationURLs = $get['body']['authorizations'];
241 241
 			$this->finalizeURL = $get['body']['finalize'];
242
-			if(array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
242
+			if (array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
243 243
 			$this->updateAuthorizations();
244 244
 		}
245 245
 		else
246 246
 		{
247
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData');
247
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData');
248 248
 		}
249 249
 	}
250 250
 
@@ -254,12 +254,12 @@  discard block
 block discarded – undo
254 254
 	private function updateAuthorizations()
255 255
 	{
256 256
 		$this->authorizations = array();
257
-		foreach($this->authorizationURLs as $authURL)
257
+		foreach ($this->authorizationURLs as $authURL)
258 258
 		{
259 259
 			if (filter_var($authURL, FILTER_VALIDATE_URL))
260 260
 			{
261 261
 				$auth = new LEAuthorization($this->connector, $this->log, $authURL);
262
-				if($auth != false) $this->authorizations[] = $auth;
262
+				if ($auth != false) $this->authorizations[] = $auth;
263 263
 			}
264 264
 		}
265 265
 	}
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
271 271
      */
272 272
 	public function allAuthorizationsValid()
273 273
 	{
274
-		if(count($this->authorizations) > 0)
274
+		if (count($this->authorizations) > 0)
275 275
 		{
276
-			foreach($this->authorizations as $auth)
276
+			foreach ($this->authorizations as $auth)
277 277
 			{
278
-				if($auth->status != 'valid') return false;
278
+				if ($auth->status != 'valid') return false;
279 279
 			}
280 280
 			return true;
281 281
 		}
@@ -308,15 +308,15 @@  discard block
 block discarded – undo
308 308
 		);
309 309
 		$digest = LEFunctions::Base64UrlSafeEncode(hash('sha256', json_encode($header), true));
310 310
 
311
-		foreach($this->authorizations as $auth)
311
+		foreach ($this->authorizations as $auth)
312 312
 		{
313
-			if($auth->status == 'pending')
313
+			if ($auth->status == 'pending')
314 314
 			{
315 315
 				$challenge = $auth->getChallenge($type);
316
-				if($challenge['status'] == 'pending')
316
+				if ($challenge['status'] == 'pending')
317 317
 				{
318 318
 					$keyAuthorization = $challenge['token'] . '.' . $digest;
319
-					switch(strtolower($type))
319
+					switch (strtolower($type))
320 320
 					{
321 321
 						case LEOrder::CHALLENGE_TYPE_HTTP:
322 322
 							$authorizations[] = array('type' => LEOrder::CHALLENGE_TYPE_HTTP, 'identifier' => $auth->identifier['value'], 'filename' => $challenge['token'], 'content' => $keyAuthorization);
@@ -355,27 +355,27 @@  discard block
 block discarded – undo
355 355
 		);
356 356
 		$digest = LEFunctions::Base64UrlSafeEncode(hash('sha256', json_encode($header), true));
357 357
 
358
-		foreach($this->authorizations as $auth)
358
+		foreach ($this->authorizations as $auth)
359 359
 		{
360
-			if($auth->identifier['value'] == $identifier)
360
+			if ($auth->identifier['value'] == $identifier)
361 361
 			{
362
-				if($auth->status == 'pending')
362
+				if ($auth->status == 'pending')
363 363
 				{
364 364
 					$challenge = $auth->getChallenge($type);
365
-					if($challenge['status'] == 'pending')
365
+					if ($challenge['status'] == 'pending')
366 366
 					{
367 367
 						$keyAuthorization = $challenge['token'] . '.' . $digest;
368
-						switch($type)
368
+						switch ($type)
369 369
 						{
370 370
 							case LEOrder::CHALLENGE_TYPE_HTTP:
371
-								if(LEFunctions::checkHTTPChallenge($identifier, $challenge['token'], $keyAuthorization))
371
+								if (LEFunctions::checkHTTPChallenge($identifier, $challenge['token'], $keyAuthorization))
372 372
 								{
373 373
 									$sign = $this->connector->signRequestKid(array('keyAuthorization' => $keyAuthorization), $this->connector->accountURL, $challenge['url']);
374 374
 									$post = $this->connector->post($challenge['url'], $sign);
375
-									if(strpos($post['header'], "200 OK") !== false)
375
+									if (strpos($post['header'], "200 OK") !== false)
376 376
 									{
377
-										if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
378
-										while($auth->status == 'pending')
377
+										if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
378
+										while ($auth->status == 'pending')
379 379
 										{
380 380
 											sleep(1);
381 381
 											$auth->updateData();
@@ -385,19 +385,19 @@  discard block
 block discarded – undo
385 385
 								}
386 386
 								else
387 387
 								{
388
-									if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
388
+									if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
389 389
 								}
390 390
 								break;
391 391
 							case LEOrder::CHALLENGE_TYPE_DNS:
392 392
 								$DNSDigest = LEFunctions::Base64UrlSafeEncode(hash('sha256', $keyAuthorization, true));
393
-								if(LEFunctions::checkDNSChallenge($identifier, $DNSDigest))
393
+								if (LEFunctions::checkDNSChallenge($identifier, $DNSDigest))
394 394
 								{
395 395
 									$sign = $this->connector->signRequestKid(array('keyAuthorization' => $keyAuthorization), $this->connector->accountURL, $challenge['url']);
396 396
 									$post = $this->connector->post($challenge['url'], $sign);
397
-									if(strpos($post['header'], "200 OK") !== false)
397
+									if (strpos($post['header'], "200 OK") !== false)
398 398
 									{
399
-										if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
400
-										while($auth->status == 'pending')
399
+										if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
400
+										while ($auth->status == 'pending')
401 401
 										{
402 402
 											sleep(1);
403 403
 											$auth->updateData();
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 								}
408 408
 								else
409 409
 								{
410
-									if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
410
+									if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
411 411
 								}
412 412
 								break;
413 413
 						}
@@ -427,21 +427,21 @@  discard block
 block discarded – undo
427 427
      */
428 428
 	public function deactivateOrderAuthorization($identifier)
429 429
 	{
430
-		foreach($this->authorizations as $auth)
430
+		foreach ($this->authorizations as $auth)
431 431
 		{
432
-			if($auth->identifier['value'] == $identifier)
432
+			if ($auth->identifier['value'] == $identifier)
433 433
 			{
434 434
 				$sign = $this->connector->signRequestKid(array('status' => 'deactivated'), $this->connector->accountURL, $auth->authorizationURL);
435 435
 				$post = $this->connector->post($auth->authorizationURL, $sign);
436
-				if(strpos($post['header'], "200 OK") !== false)
436
+				if (strpos($post['header'], "200 OK") !== false)
437 437
 				{
438
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization');
438
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization');
439 439
 					$this->updateAuthorizations();
440 440
 					return true;
441 441
 				}
442 442
 			}
443 443
 		}
444
-		if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization');
444
+		if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization');
445 445
 		return false;
446 446
 	}
447 447
 
@@ -453,12 +453,12 @@  discard block
 block discarded – undo
453 453
      */
454 454
 	public function generateCSR()
455 455
 	{
456
-		$domains = array_map(function ($dns) { return $dns['value']; }, $this->identifiers);
457
-		if(in_array($this->basename, $domains))
456
+		$domains = array_map(function($dns) { return $dns['value']; }, $this->identifiers);
457
+		if (in_array($this->basename, $domains))
458 458
 		{
459 459
 			$CN = $this->basename;
460 460
 		}
461
-		elseif(in_array('*.' . $this->basename, $domains))
461
+		elseif (in_array('*.' . $this->basename, $domains))
462 462
 		{
463 463
 			$CN = '*.' . $this->basename;
464 464
 		}
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 			"commonName" => $CN
472 472
 		);
473 473
 
474
-		$san = implode(",", array_map(function ($dns) {
474
+		$san = implode(",", array_map(function($dns) {
475 475
             return "DNS:" . $dns;
476 476
         }, $domains));
477 477
         $tmpConf = tmpfile();
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 
496 496
 		$privateKey = openssl_pkey_get_private(file_get_contents($this->certificateKeys['private_key']));
497 497
 		$csr = openssl_csr_new($dn, $privateKey, array('config' => $tmpConfPath, 'digest_alg' => 'sha256'));
498
-		openssl_csr_export ($csr, $csr);
498
+		openssl_csr_export($csr, $csr);
499 499
 		return $csr;
500 500
 	}
501 501
 
@@ -508,36 +508,36 @@  discard block
 block discarded – undo
508 508
      */
509 509
 	public function finalizeOrder($csr = '')
510 510
 	{
511
-		if($this->status == 'pending')
511
+		if ($this->status == 'pending')
512 512
 		{
513
-			if($this->allAuthorizationsValid())
513
+			if ($this->allAuthorizationsValid())
514 514
 			{
515
-				if(empty($csr)) $csr = $this->generateCSR();
516
-				if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) $csr = $matches[1];
515
+				if (empty($csr)) $csr = $this->generateCSR();
516
+				if (preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) $csr = $matches[1];
517 517
 				$csr = trim(LEFunctions::Base64UrlSafeEncode(base64_decode($csr)));
518 518
 				$sign = $this->connector->signRequestKid(array('csr' => $csr), $this->connector->accountURL, $this->finalizeURL);
519 519
 				$post = $this->connector->post($this->finalizeURL, $sign);
520
-				if(strpos($post['header'], "200 OK") !== false)
520
+				if (strpos($post['header'], "200 OK") !== false)
521 521
 				{
522 522
 					$this->status = $post['body']['status'];
523 523
 					$this->expires = $post['body']['expires'];
524 524
 					$this->identifiers = $post['body']['identifiers'];
525 525
 					$this->authorizationURLs = $post['body']['authorizations'];
526 526
 					$this->finalizeURL = $post['body']['finalize'];
527
-					if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
527
+					if (array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
528 528
 					$this->updateAuthorizations();
529
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder');
529
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder');
530 530
 					return true;
531 531
 				}
532 532
 			}
533 533
 			else
534 534
 			{
535
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder');
535
+				if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder');
536 536
 			}
537 537
 		}
538 538
 		else
539 539
 		{
540
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder');
540
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder');
541 541
 		}
542 542
 		return false;
543 543
 	}
@@ -561,48 +561,48 @@  discard block
 block discarded – undo
561 561
 	public function getCertificate()
562 562
 	{
563 563
 		$polling = 0;
564
-		while($this->status == 'processing' && $polling < 4)
564
+		while ($this->status == 'processing' && $polling < 4)
565 565
 		{
566
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate');
566
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate');
567 567
 			sleep(5);
568 568
 			$this->updateOrderData();
569 569
 			$polling++;
570 570
 		}
571
-		if($this->status == 'valid' && !empty($this->certificateURL))
571
+		if ($this->status == 'valid' && !empty($this->certificateURL))
572 572
 		{
573 573
 			$get = $this->connector->get($this->certificateURL);
574
-			if(strpos($get['header'], "200 OK") !== false)
574
+			if (strpos($get['header'], "200 OK") !== false)
575 575
 			{
576
-				if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $get['body'], $matches))
576
+				if (preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $get['body'], $matches))
577 577
 				{
578
-					if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'],  $matches[0][0]);
578
+					if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'], $matches[0][0]);
579 579
 
580
-					if(count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate']))
580
+					if (count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate']))
581 581
 					{
582
-						$fullchain = $matches[0][0]."\n";
583
-						for($i=1;$i<count($matches[0]);$i++)
582
+						$fullchain = $matches[0][0] . "\n";
583
+						for ($i = 1; $i < count($matches[0]); $i++)
584 584
 						{
585
-							$fullchain .= $matches[0][$i]."\n";
585
+							$fullchain .= $matches[0][$i] . "\n";
586 586
 
587 587
 						}
588 588
 						file_put_contents(trim($this->certificateKeys['fullchain_certificate']), $fullchain);
589 589
 					}
590
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
590
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
591 591
 					return true;
592 592
 				}
593 593
 				else
594 594
 				{
595
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
595
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
596 596
 				}
597 597
 			}
598 598
 			else
599 599
 			{
600
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
600
+				if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
601 601
 			}
602 602
 		}
603 603
 		else
604 604
 		{
605
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate');
605
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate');
606 606
 		}
607 607
 		return false;
608 608
 	}
@@ -617,13 +617,13 @@  discard block
 block discarded – undo
617 617
      */
618 618
 	public function revokeCertificate($reason = 0)
619 619
 	{
620
-		if($this->status == 'valid')
620
+		if ($this->status == 'valid')
621 621
 		{
622 622
 			if (isset($this->certificateKeys['certificate'])) $certFile = $this->certificateKeys['certificate'];
623 623
 			elseif (isset($this->certificateKeys['fullchain_certificate']))  $certFile = $this->certificateKeys['fullchain_certificate'];
624 624
 			else throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] required');
625 625
 
626
-			if(file_exists($certFile) && file_exists($this->certificateKeys['private_key']))
626
+			if (file_exists($certFile) && file_exists($this->certificateKeys['private_key']))
627 627
 			{
628 628
 				$certificate = file_get_contents($this->certificateKeys['certificate']);
629 629
 				preg_match('~-----BEGIN\sCERTIFICATE-----(.*)-----END\sCERTIFICATE-----~s', $certificate, $matches);
@@ -631,24 +631,24 @@  discard block
 block discarded – undo
631 631
 
632 632
 				$sign = $this->connector->signRequestJWK(array('certificate' => $certificate, 'reason' => $reason), $this->connector->revokeCert);
633 633
 				$post = $this->connector->post($this->connector->revokeCert, $sign);
634
-				if(strpos($post['header'], "200 OK") !== false)
634
+				if (strpos($post['header'], "200 OK") !== false)
635 635
 				{
636
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate');
636
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate');
637 637
 					return true;
638 638
 				}
639 639
 				else
640 640
 				{
641
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate');
641
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate');
642 642
 				}
643 643
 			}
644 644
 			else
645 645
 			{
646
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate');
646
+				if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate');
647 647
 			}
648 648
 		}
649 649
 		else
650 650
 		{
651
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate');
651
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate');
652 652
 		}
653 653
 		return false;
654 654
 	}
Please login to merge, or discard this patch.
LEClient/src/LEAccount.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 		$this->accountKeys = $accountKeys;
64 64
 		$this->log = $log;
65 65
 
66
-		if(!file_exists($this->accountKeys['private_key']) OR !file_exists($this->accountKeys['public_key']))
66
+		if (!file_exists($this->accountKeys['private_key']) OR !file_exists($this->accountKeys['public_key']))
67 67
 		{
68
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No account found, attempting to create account.', 'function LEAccount __construct');
68
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No account found, attempting to create account.', 'function LEAccount __construct');
69 69
 			LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'], $this->accountKeys['public_key']);
70 70
 			$this->connector->accountURL = $this->createLEAccount($email);
71 71
 		}
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		{
74 74
 			$this->connector->accountURL = $this->getLEAccount();
75 75
 		}
76
-		if($this->connector->accountURL == false) throw new \RuntimeException('Account not found or deactivated.');
76
+		if ($this->connector->accountURL == false) throw new \RuntimeException('Account not found or deactivated.');
77 77
 		$this->getLEAccountData();
78 78
 	}
79 79
 
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
 
91 91
 		$sign = $this->connector->signRequestJWK(array('contact' => $contact, 'termsOfServiceAgreed' => true), $this->connector->newAccount);
92 92
 		$post = $this->connector->post($this->connector->newAccount, $sign);
93
-		if(strpos($post['header'], "201 Created") !== false)
93
+		if (strpos($post['header'], "201 Created") !== false)
94 94
 		{
95
-			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
95
+			if (preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
96 96
 		}
97 97
 		return false;
98 98
 	}
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
 		$sign = $this->connector->signRequestJWK(array('onlyReturnExisting' => true), $this->connector->newAccount);
108 108
 		$post = $this->connector->post($this->connector->newAccount, $sign);
109 109
 
110
-		if(strpos($post['header'], "200 OK") !== false)
110
+		if (strpos($post['header'], "200 OK") !== false)
111 111
 		{
112
-			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
112
+			if (preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
113 113
 		}
114 114
 		return false;
115 115
 	}
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	{
122 122
 		$sign = $this->connector->signRequestKid(array('' => ''), $this->connector->accountURL, $this->connector->accountURL);
123 123
 		$post = $this->connector->post($this->connector->accountURL, $sign);
124
-		if(strpos($post['header'], "200 OK") !== false)
124
+		if (strpos($post['header'], "200 OK") !== false)
125 125
 		{
126 126
 			$this->id = $post['body']['id'];
127 127
 			$this->key = $post['body']['key'];
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 
151 151
 		$sign = $this->connector->signRequestKid(array('contact' => $contact), $this->connector->accountURL, $this->connector->accountURL);
152 152
 		$post = $this->connector->post($this->connector->accountURL, $sign);
153
-		if(strpos($post['header'], "200 OK") !== false)
153
+		if (strpos($post['header'], "200 OK") !== false)
154 154
 		{
155 155
 			$this->id = $post['body']['id'];
156 156
 			$this->key = $post['body']['key'];
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 			$this->initialIp = $post['body']['initialIp'];
160 160
 			$this->createdAt = $post['body']['createdAt'];
161 161
 			$this->status = $post['body']['status'];
162
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account data updated.', 'function updateAccount');
162
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account data updated.', 'function updateAccount');
163 163
 			return true;
164 164
 		}
165 165
 		else
@@ -175,27 +175,27 @@  discard block
 block discarded – undo
175 175
      */
176 176
 	public function changeAccountKeys()
177 177
 	{
178
-		LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'].'.new', $this->accountKeys['public_key'].'.new');
179
-		$privateKey = openssl_pkey_get_private(file_get_contents($this->accountKeys['private_key'].'.new'));
178
+		LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'] . '.new', $this->accountKeys['public_key'] . '.new');
179
+		$privateKey = openssl_pkey_get_private(file_get_contents($this->accountKeys['private_key'] . '.new'));
180 180
 		$details = openssl_pkey_get_details($privateKey);
181 181
     $innerPayload = array('account' => $this->connector->accountURL, 'newKey' => array(
182 182
 			"kty" => "RSA",
183 183
 			"n" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["n"]),
184 184
 			"e" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["e"])
185 185
 		));
186
-		$outerPayload = $this->connector->signRequestJWK($innerPayload, $this->connector->keyChange, $this->accountKeys['private_key'].'.new');
186
+		$outerPayload = $this->connector->signRequestJWK($innerPayload, $this->connector->keyChange, $this->accountKeys['private_key'] . '.new');
187 187
 		$sign = $this->connector->signRequestKid($outerPayload, $this->connector->accountURL, $this->connector->keyChange);
188 188
 		$post = $this->connector->post($this->connector->keyChange, $sign);
189
-		if(strpos($post['header'], "200 OK") !== false)
189
+		if (strpos($post['header'], "200 OK") !== false)
190 190
 		{
191 191
 			$this->getLEAccountData();
192 192
 
193 193
 			unlink($this->accountKeys['private_key']);
194 194
 			unlink($this->accountKeys['public_key']);
195
-			rename($this->accountKeys['private_key'].'.new', $this->accountKeys['private_key']);
196
-			rename($this->accountKeys['public_key'].'.new', $this->accountKeys['public_key']);
195
+			rename($this->accountKeys['private_key'] . '.new', $this->accountKeys['private_key']);
196
+			rename($this->accountKeys['public_key'] . '.new', $this->accountKeys['public_key']);
197 197
 
198
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account keys changed.', 'function changeAccountKey');
198
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account keys changed.', 'function changeAccountKey');
199 199
 			return true;
200 200
 		}
201 201
 		else
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
 	{
214 214
 		$sign = $this->connector->signRequestKid(array('status' => 'deactivated'), $this->connector->accountURL, $this->connector->accountURL);
215 215
 		$post = $this->connector->post($this->connector->accountURL, $sign);
216
-		if(strpos($post['header'], "200 OK") !== false)
216
+		if (strpos($post['header'], "200 OK") !== false)
217 217
 		{
218 218
 			$this->connector->accountDeactivated = true;
219
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account deactivated.', 'function deactivateAccount');
219
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account deactivated.', 'function deactivateAccount');
220 220
 		}
221 221
 		else
222 222
 		{
Please login to merge, or discard this patch.
LEClient/src/LEFunctions.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
 			"private_key_bits" => intval($keySize),
55 55
 		));
56 56
 
57
-		if(!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("RSA keypair export failed!");
57
+		if (!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("RSA keypair export failed!");
58 58
 
59 59
 		$details = openssl_pkey_get_details($res);
60 60
 
61 61
 		if ($directory !== null && $directory !== '')
62 62
 		{
63
-			$privateKeyFile = $directory.$privateKeyFile;
64
-			$publicKeyFile = $directory.$publicKeyFile;
63
+			$privateKeyFile = $directory . $privateKeyFile;
64
+			$publicKeyFile = $directory . $publicKeyFile;
65 65
 		}
66 66
 
67 67
 		file_put_contents($privateKeyFile, $privateKey);
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
 		else throw new \RuntimeException("EC key size must be 256 or 384");
103 103
 
104 104
 
105
-		if(!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("EC keypair export failed!");
105
+		if (!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("EC keypair export failed!");
106 106
 
107 107
 		$details = openssl_pkey_get_details($res);
108 108
 
109 109
 		if ($directory !== null && $directory !== '')
110 110
 		{
111
-			$privateKeyFile = $directory.$privateKeyFile;
112
-			$publicKeyFile = $directory.$publicKeyFile;
111
+			$privateKeyFile = $directory . $privateKeyFile;
112
+			$publicKeyFile = $directory . $publicKeyFile;
113 113
 		}
114 114
 
115 115
 		file_put_contents($privateKeyFile, $privateKey);
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	{
162 162
 		$e = new Exception();
163 163
 		$trace = $e->getTrace();
164
-		$function = $function == '' ? 'function ' .  $trace[3]['function'] . ' (function ' . $trace[2]['function'] . ')' : $function;
164
+		$function = $function == '' ? 'function ' . $trace[3]['function'] . ' (function ' . $trace[2]['function'] . ')' : $function;
165 165
 		if (PHP_SAPI == "cli")
166 166
 		{
167 167
 			echo '[' . date('d-m-Y H:i:s') . '] ' . $function . ":\n";
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
 	{
211 211
 		$DNS = '_acme-challenge.' . str_replace('*.', '', $domain);
212 212
 		$records = dns_get_record($DNS, DNS_TXT);
213
-		foreach($records as $record)
213
+		foreach ($records as $record)
214 214
 		{
215
-			if($record['host'] == $DNS && $record['type'] == 'TXT' && $record['txt'] == $DNSDigest) return true;
215
+			if ($record['host'] == $DNS && $record['type'] == 'TXT' && $record['txt'] == $DNSDigest) return true;
216 216
 		}
217 217
 		return false;
218 218
 	}
Please login to merge, or discard this patch.
LEClient/src/LEConnector.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      */
87 87
 	private function getNewNonce()
88 88
 	{
89
-		if(strpos($this->head($this->newNonce)['header'], "204 No Content") == false) throw new \RuntimeException('No new nonce.');
89
+		if (strpos($this->head($this->newNonce)['header'], "204 No Content") == false) throw new \RuntimeException('No new nonce.');
90 90
 	}
91 91
 
92 92
     /**
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      */
101 101
 	private function request($method, $URL, $data = null)
102 102
 	{
103
-		if($this->accountDeactivated) throw new \RuntimeException('The account was deactivated. No further requests can be made.');
103
+		if ($this->accountDeactivated) throw new \RuntimeException('The account was deactivated. No further requests can be made.');
104 104
 
105 105
 		$headers = array('Accept: application/json', 'Content-Type: application/json');
106 106
 		$requestURL = preg_match('~^http~', $URL) ? $URL : $this->baseURL . $URL;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         }
128 128
         $response = curl_exec($handle);
129 129
 
130
-        if(curl_errno($handle)) {
130
+        if (curl_errno($handle)) {
131 131
             throw new \RuntimeException('Curl: ' . curl_error($handle));
132 132
         }
133 133
 
@@ -137,21 +137,21 @@  discard block
 block discarded – undo
137 137
         $body = substr($response, $header_size);
138 138
 		$jsonbody = json_decode($body, true);
139 139
 		$jsonresponse = array('request' => $method . ' ' . $requestURL, 'header' => $header, 'body' => $jsonbody === null ? $body : $jsonbody);
140
-		if($this->log >= LECLient::LOG_DEBUG) LEFunctions::log($jsonresponse);
140
+		if ($this->log >= LECLient::LOG_DEBUG) LEFunctions::log($jsonresponse);
141 141
 
142
-		if(	(($method == 'POST' OR $method == 'GET') AND strpos($header, "200 OK") === false AND strpos($header, "201 Created") === false) OR
142
+		if ((($method == 'POST' OR $method == 'GET') AND strpos($header, "200 OK") === false AND strpos($header, "201 Created") === false) OR
143 143
 			($method == 'HEAD' AND strpos($header, "204 No Content") === false))
144 144
 		{
145 145
 			throw new \RuntimeException('Invalid response, header: ' . $header);
146 146
 		}
147 147
 
148
-		if(preg_match('~Replay\-Nonce: (\S+)~i', $header, $matches))
148
+		if (preg_match('~Replay\-Nonce: (\S+)~i', $header, $matches))
149 149
 		{
150 150
 			$this->nonce = trim($matches[1]);
151 151
 		}
152 152
 		else
153 153
 		{
154
-			if($method == 'POST') $this->getNewNonce(); // Not expecting a new nonce with GET and HEAD requests.
154
+			if ($method == 'POST') $this->getNewNonce(); // Not expecting a new nonce with GET and HEAD requests.
155 155
 		}
156 156
 
157 157
         return $jsonresponse;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      */
206 206
 	public function signRequestJWK($payload, $url, $privateKeyFile = '')
207 207
     {
208
-		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
208
+		if ($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
209 209
 		$privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
210 210
         $details = openssl_pkey_get_details($privateKey);
211 211
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
         $payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
224 224
         $protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
225 225
 
226
-        openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
226
+        openssl_sign($protected64 . '.' . $payload64, $signed, $privateKey, "SHA256");
227 227
         $signed64 = LEFunctions::Base64UrlSafeEncode($signed);
228 228
 
229 229
         $data = array(
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      */
248 248
 	public function signRequestKid($payload, $kid, $url, $privateKeyFile = '')
249 249
     {
250
-		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
250
+		if ($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
251 251
         $privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
252 252
         $details = openssl_pkey_get_details($privateKey);
253 253
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
         $payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
262 262
         $protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
263 263
 
264
-        openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
264
+        openssl_sign($protected64 . '.' . $payload64, $signed, $privateKey, "SHA256");
265 265
         $signed64 = LEFunctions::Base64UrlSafeEncode($signed);
266 266
 
267 267
         $data = array(
Please login to merge, or discard this patch.
LEClient/src/LEAuthorization.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 		$this->authorizationURL = $authorizationURL;
61 61
 		
62 62
 		$get = $this->connector->get($this->authorizationURL);
63
-		if(strpos($get['header'], "200 OK") !== false)
63
+		if (strpos($get['header'], "200 OK") !== false)
64 64
 		{
65 65
 			$this->identifier = $get['body']['identifier'];
66 66
 			$this->status = $get['body']['status'];
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 		}
70 70
 		else
71 71
 		{
72
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function LEAuthorization __construct');
72
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function LEAuthorization __construct');
73 73
 		}
74 74
 	}
75 75
 	
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	public function updateData()
81 81
 	{
82 82
 		$get = $this->connector->get($this->authorizationURL);
83
-		if(strpos($get['header'], "200 OK") !== false)
83
+		if (strpos($get['header'], "200 OK") !== false)
84 84
 		{
85 85
 			$this->identifier = $get['body']['identifier'];
86 86
 			$this->status = $get['body']['status'];
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		}
90 90
 		else
91 91
 		{
92
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function updateData');
92
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function updateData');
93 93
 		}
94 94
 	}
95 95
 	
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
      */
104 104
 	public function getChallenge($type)
105 105
 	{
106
-		foreach($this->challenges as $challenge)
106
+		foreach ($this->challenges as $challenge)
107 107
 		{
108
-			if($challenge['type'] == $type) return $challenge;
108
+			if ($challenge['type'] == $type) return $challenge;
109 109
 		}
110 110
 		throw new \RuntimeException('No challenge found for type \'' . $type . '\' and identifier \'' . $this->identifier['value'] . '\'.');
111 111
 	}
Please login to merge, or discard this patch.
exampleDNSInit.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@
 block discarded – undo
16 16
 // Initiating the order instance. The keys and certificate will be stored in /example.org/ (argument 1) and the domains in the array (argument 2) will be on the certificate.
17 17
 $order = $client->getOrCreateOrder($basename, $domains);
18 18
 // Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations.
19
-if(!$order->allAuthorizationsValid())
19
+if (!$order->allAuthorizationsValid())
20 20
 {
21 21
 	// Get the DNS challenges from the pending authorizations.
22 22
 	$pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_DNS);
23 23
 	// Walk the list of pending authorization DNS challenges.
24
-	if(!empty($pending))
24
+	if (!empty($pending))
25 25
 	{
26
-		foreach($pending as $challenge)
26
+		foreach ($pending as $challenge)
27 27
 		{
28 28
 			// For the purpose of this example, a fictitious functions creates or updates the ACME challenge DNS record for this domain. 
29 29
 			setDNSRecord($challenge['identifier'], $challenge['DNSDigest'])
Please login to merge, or discard this patch.
exampleDNSFinish.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@  discard block
 block discarded – undo
16 16
 // Initiating the order instance. The keys and certificate will be stored in /example.org/ (argument 1) and the domains in the array (argument 2) will be on the certificate.
17 17
 $order = $client->getOrCreateOrder($basename, $domains);
18 18
 // Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations.
19
-if(!$order->allAuthorizationsValid())
19
+if (!$order->allAuthorizationsValid())
20 20
 {
21 21
 	// Get the DNS challenges from the pending authorizations.
22 22
 	$pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_DNS);
23 23
 	// Walk the list of pending authorization DNS challenges.
24
-	if(!empty($pending))
24
+	if (!empty($pending))
25 25
 	{
26
-		foreach($pending as $challenge)
26
+		foreach ($pending as $challenge)
27 27
 		{
28 28
 			// Let LetsEncrypt verify this challenge, which should have been fulfilled in exampleDNSStart.php.
29 29
 			$order->verifyPendingOrderAuthorization($challenge['identifier'], LEOrder::CHALLENGE_TYPE_DNS);
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
 	}
32 32
 }
33 33
 // Check once more whether all authorizations are valid before we can finalize the order.
34
-if($order->allAuthorizationsValid())
34
+if ($order->allAuthorizationsValid())
35 35
 {
36 36
 	// Finalize the order first, if that is not yet done.
37
-	if(!$order->isFinalized()) $order->finalizeOrder();
37
+	if (!$order->isFinalized()) $order->finalizeOrder();
38 38
 	// Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate.
39
-	if($order->isFinalized()) $order->getCertificate();
39
+	if ($order->isFinalized()) $order->getCertificate();
40 40
 }
41 41
 ?>
42 42
\ No newline at end of file
Please login to merge, or discard this patch.