Passed
Branch master (52717f)
by John
02:35
created
LEClient/LEClient.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -60,17 +60,17 @@  discard block
 block discarded – undo
60 60
 	const LOG_STATUS = 1;	// Logs only messages and faults.
61 61
 	const LOG_DEBUG = 2;	// Logs messages, faults and raw responses from HTTP requests.
62 62
 
63
-    /**
64
-     * Initiates the LetsEncrypt main client.
65
-     *
66
-     * @param array		$email	 		The array of strings containing e-mail addresses. Only used in this function when creating a new account.
67
-     * @param boolean	$acmeURL		ACME URL, can be string or one of predefined values: LE_STAGING or LE_PRODUCTION. Defaults to LE_STAGING.
68
-     * @param int 		$log			The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted. Defaults to LOG_OFF. (optional)
69
-     * @param string 	$certificateKeys 		The main directory in which all keys (and certificates), including account keys, are stored. Defaults to 'keys/'. (optional)
70
-		 * @param array 	$certificateKeys 		Optional array containing location of all certificate files. Required paths are public_key, private_key, order and certificate/fullchain_certificate (you can use both or only one of them)
71
-     * @param string 	$accountKeys The directory in which the account keys are stored. Is a subdir inside $certificateKeys. Defaults to '__account/'.(optional)
72
-		 * @param array 	$accountKeys Optional array containing location of account private and public keys. Required paths are private_key, public_key.
73
-     */
63
+	/**
64
+	 * Initiates the LetsEncrypt main client.
65
+	 *
66
+	 * @param array		$email	 		The array of strings containing e-mail addresses. Only used in this function when creating a new account.
67
+	 * @param boolean	$acmeURL		ACME URL, can be string or one of predefined values: LE_STAGING or LE_PRODUCTION. Defaults to LE_STAGING.
68
+	 * @param int 		$log			The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted. Defaults to LOG_OFF. (optional)
69
+	 * @param string 	$certificateKeys 		The main directory in which all keys (and certificates), including account keys, are stored. Defaults to 'keys/'. (optional)
70
+	 * @param array 	$certificateKeys 		Optional array containing location of all certificate files. Required paths are public_key, private_key, order and certificate/fullchain_certificate (you can use both or only one of them)
71
+	 * @param string 	$accountKeys The directory in which the account keys are stored. Is a subdir inside $certificateKeys. Defaults to '__account/'.(optional)
72
+	 * @param array 	$accountKeys Optional array containing location of account private and public keys. Required paths are private_key, public_key.
73
+	 */
74 74
 	public function __construct($email, $acmeURL = LEClient::LE_STAGING, $log = LEClient::LOG_OFF, $certificateKeys = 'keys/', $accountKeys = '__account/')
75 75
 	{
76 76
 
@@ -171,27 +171,27 @@  discard block
 block discarded – undo
171 171
 	}
172 172
 
173 173
 
174
-    /**
175
-     * Returns the LetsEncrypt account used in the current client.
174
+	/**
175
+	 * Returns the LetsEncrypt account used in the current client.
176 176
 	 *
177 177
 	 * @return LEAccount	The LetsEncrypt Account instance used by the client.
178
-     */
178
+	 */
179 179
 	public function getAccount()
180 180
 	{
181 181
 		return $this->account;
182 182
 	}
183 183
 
184
-    /**
185
-     * Returns a LetsEncrypt order. If an order exists, this one is returned. If not, a new order is created and returned.
186
-     *
187
-     * @param string	$basename	The base name for the order. Preferable the top domain (example.org). Will be the directory in which the keys are stored. Used for the CommonName in the certificate as well.
188
-     * @param array 	$domains 	The array of strings containing the domain names on the certificate.
189
-     * @param string 		$keyType 	Type of the key we want to use for certificate. Can be provided in ALGO-SIZE format (ex. rsa-4096 or ec-256) or simple "rsa" and "ec" (using default sizes)
190
-     * @param string 	$notBefore	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) at which the certificate becomes valid. Defaults to the moment the order is finalized. (optional)
191
-     * @param string 	$notAfter  	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) until which the certificate is valid. Defaults to 90 days past the moment the order is finalized. (optional)
192
-     *
193
-     * @return LEOrder	The LetsEncrypt Order instance which is either retrieved or created.
194
-     */
184
+	/**
185
+	 * Returns a LetsEncrypt order. If an order exists, this one is returned. If not, a new order is created and returned.
186
+	 *
187
+	 * @param string	$basename	The base name for the order. Preferable the top domain (example.org). Will be the directory in which the keys are stored. Used for the CommonName in the certificate as well.
188
+	 * @param array 	$domains 	The array of strings containing the domain names on the certificate.
189
+	 * @param string 		$keyType 	Type of the key we want to use for certificate. Can be provided in ALGO-SIZE format (ex. rsa-4096 or ec-256) or simple "rsa" and "ec" (using default sizes)
190
+	 * @param string 	$notBefore	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) at which the certificate becomes valid. Defaults to the moment the order is finalized. (optional)
191
+	 * @param string 	$notAfter  	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) until which the certificate is valid. Defaults to 90 days past the moment the order is finalized. (optional)
192
+	 *
193
+	 * @return LEOrder	The LetsEncrypt Order instance which is either retrieved or created.
194
+	 */
195 195
 	public function getOrCreateOrder($basename, $domains, $keyType = 'rsa-4096', $notBefore = '', $notAfter = '')
196 196
 	{
197 197
 		return new LEOrder($this->connector, $this->log, $this->certificateKeys, $basename, $domains, $keyType, $notBefore, $notAfter);
Please login to merge, or discard this patch.
LEClient/src/LEOrder.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -58,18 +58,18 @@  discard block
 block discarded – undo
58 58
 	const CHALLENGE_TYPE_HTTP = 'http-01';
59 59
 	const CHALLENGE_TYPE_DNS = 'dns-01';
60 60
 
61
-    /**
62
-     * Initiates the LetsEncrypt Order class. If the base name is found in the $keysDir directory, the order data is requested. If no order was found locally, if the request is invalid or when there is a change in domain names, a new order is created.
63
-     *
64
-     * @param LEConnector	$connector	The LetsEncrypt Connector instance to use for HTTP requests.
65
-     * @param int 			$log 		The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
66
-     * @param array 		$certificateKeys 	Array containing location of certificate keys files.
67
-     * @param string 		$basename 	The base name for the order. Preferable the top domain (example.org). Will be the directory in which the keys are stored. Used for the CommonName in the certificate as well.
68
-     * @param array 		$domains 	The array of strings containing the domain names on the certificate.
69
-     * @param string 		$keyType 	Type of the key we want to use for certificate. Can be provided in ALGO-SIZE format (ex. rsa-4096 or ec-256) or simple "rsa" and "ec" (using default sizes)
70
-     * @param string 		$notBefore 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) at which the certificate becomes valid.
71
-     * @param string 		$notAfter 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) until which the certificate is valid.
72
-     */
61
+	/**
62
+	 * Initiates the LetsEncrypt Order class. If the base name is found in the $keysDir directory, the order data is requested. If no order was found locally, if the request is invalid or when there is a change in domain names, a new order is created.
63
+	 *
64
+	 * @param LEConnector	$connector	The LetsEncrypt Connector instance to use for HTTP requests.
65
+	 * @param int 			$log 		The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
66
+	 * @param array 		$certificateKeys 	Array containing location of certificate keys files.
67
+	 * @param string 		$basename 	The base name for the order. Preferable the top domain (example.org). Will be the directory in which the keys are stored. Used for the CommonName in the certificate as well.
68
+	 * @param array 		$domains 	The array of strings containing the domain names on the certificate.
69
+	 * @param string 		$keyType 	Type of the key we want to use for certificate. Can be provided in ALGO-SIZE format (ex. rsa-4096 or ec-256) or simple "rsa" and "ec" (using default sizes)
70
+	 * @param string 		$notBefore 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) at which the certificate becomes valid.
71
+	 * @param string 		$notAfter 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) until which the certificate is valid.
72
+	 */
73 73
 	public function __construct($connector, $log, $certificateKeys, $basename, $domains, $keyType = 'rsa-4096', $notBefore, $notAfter)
74 74
 	{
75 75
 		$this->connector = $connector;
@@ -159,13 +159,13 @@  discard block
 block discarded – undo
159 159
 		}
160 160
 	}
161 161
 
162
-    /**
163
-     * Creates a new LetsEncrypt order and fills this instance with its data. Subsequently creates a new RSA keypair for the certificate.
164
-     *
165
-     * @param array		$domains 	The array of strings containing the domain names on the certificate.
166
-     * @param string 	$notBefore 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) at which the certificate becomes valid.
167
-     * @param string 	$notAfter 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) until which the certificate is valid.
168
-     */
162
+	/**
163
+	 * Creates a new LetsEncrypt order and fills this instance with its data. Subsequently creates a new RSA keypair for the certificate.
164
+	 *
165
+	 * @param array		$domains 	The array of strings containing the domain names on the certificate.
166
+	 * @param string 	$notBefore 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) at which the certificate becomes valid.
167
+	 * @param string 	$notAfter 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) until which the certificate is valid.
168
+	 */
169 169
 	private function createOrder($domains, $notBefore, $notAfter)
170 170
 	{
171 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))
@@ -226,9 +226,9 @@  discard block
 block discarded – undo
226 226
 		}
227 227
 	}
228 228
 
229
-    /**
230
-     * Fetches the latest data concerning this LetsEncrypt Order instance and fills this instance with the new data.
231
-     */
229
+	/**
230
+	 * Fetches the latest data concerning this LetsEncrypt Order instance and fills this instance with the new data.
231
+	 */
232 232
 	private function updateOrderData()
233 233
 	{
234 234
 		$get = $this->connector->get($this->orderURL);
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
 	}
250 250
 
251 251
 	/**
252
-     * Fetches the latest data concerning all authorizations connected to this LetsEncrypt Order instance and creates and stores a new LetsEncrypt Authorization instance for each one.
253
-     */
252
+	 * Fetches the latest data concerning all authorizations connected to this LetsEncrypt Order instance and creates and stores a new LetsEncrypt Authorization instance for each one.
253
+	 */
254 254
 	private function updateAuthorizations()
255 255
 	{
256 256
 		$this->authorizations = array();
@@ -264,11 +264,11 @@  discard block
 block discarded – undo
264 264
 		}
265 265
 	}
266 266
 
267
-    /**
268
-     * Walks all LetsEncrypt Authorization instances and returns whether they are all valid (verified).
269
-     *
270
-     * @return boolean	Returns true if all authorizations are valid (verified), returns false if not.
271
-     */
267
+	/**
268
+	 * Walks all LetsEncrypt Authorization instances and returns whether they are all valid (verified).
269
+	 *
270
+	 * @return boolean	Returns true if all authorizations are valid (verified), returns false if not.
271
+	 */
272 272
 	public function allAuthorizationsValid()
273 273
 	{
274 274
 		if(count($this->authorizations) > 0)
@@ -282,16 +282,16 @@  discard block
 block discarded – undo
282 282
 		return false;
283 283
 	}
284 284
 
285
-    /**
286
-     * Get all pending LetsEncrypt Authorization instances and return the necessary data for verification. The data in the return object depends on the $type.
287
-     *
288
-     * @param int	$type	The type of verification to get. Supporting http-01 and dns-01. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS. Throws
285
+	/**
286
+	 * Get all pending LetsEncrypt Authorization instances and return the necessary data for verification. The data in the return object depends on the $type.
287
+	 *
288
+	 * @param int	$type	The type of verification to get. Supporting http-01 and dns-01. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS. Throws
289 289
 	 *						a Runtime Exception when requesting an unknown $type. Keep in mind a wildcard domain authorization only accepts LEOrder::CHALLENGE_TYPE_DNS.
290
-     *
291
-     * @return object	Returns an array with verification data if successful, false if not pending LetsEncrypt Authorization instances were found. The return array always
290
+	 *
291
+	 * @return object	Returns an array with verification data if successful, false if not pending LetsEncrypt Authorization instances were found. The return array always
292 292
 	 *					contains 'type' and 'identifier'. For LEOrder::CHALLENGE_TYPE_HTTP, the array contains 'filename' and 'content' for necessary the authorization file.
293 293
 	 *					For LEOrder::CHALLENGE_TYPE_DNS, the array contains 'DNSDigest', which is the content for the necessary DNS TXT entry.
294
-     */
294
+	 */
295 295
 
296 296
 	public function getPendingAuthorizations($type)
297 297
 	{
@@ -333,15 +333,15 @@  discard block
 block discarded – undo
333 333
 		return count($authorizations) > 0 ? $authorizations : false;
334 334
 	}
335 335
 
336
-    /**
337
-     * Sends a verification request for a given $identifier and $type. The function itself checks whether the verification is valid before making the request.
336
+	/**
337
+	 * Sends a verification request for a given $identifier and $type. The function itself checks whether the verification is valid before making the request.
338 338
 	 * Updates the LetsEncrypt Authorization instances after a successful verification.
339
-     *
340
-     * @param string	$identifier	The domain name to verify.
341
-     * @param int 		$type 		The type of verification. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS.
342
-     *
343
-     * @return boolean	Returns true when the verification request was successful, false if not.
344
-     */
339
+	 *
340
+	 * @param string	$identifier	The domain name to verify.
341
+	 * @param int 		$type 		The type of verification. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS.
342
+	 *
343
+	 * @return boolean	Returns true when the verification request was successful, false if not.
344
+	 */
345 345
 	public function verifyPendingOrderAuthorization($identifier, $type)
346 346
 	{
347 347
 		$privateKey = openssl_pkey_get_private(file_get_contents($this->connector->accountKeys['private_key']));
@@ -418,13 +418,13 @@  discard block
 block discarded – undo
418 418
 		return false;
419 419
 	}
420 420
 
421
-    /**
422
-     * Deactivate an LetsEncrypt Authorization instance.
423
-     *
424
-     * @param string	$identifier The domain name for which the verification should be deactivated.
425
-     *
426
-     * @return boolean	Returns true is the deactivation request was successful, false if not.
427
-     */
421
+	/**
422
+	 * Deactivate an LetsEncrypt Authorization instance.
423
+	 *
424
+	 * @param string	$identifier The domain name for which the verification should be deactivated.
425
+	 *
426
+	 * @return boolean	Returns true is the deactivation request was successful, false if not.
427
+	 */
428 428
 	public function deactivateOrderAuthorization($identifier)
429 429
 	{
430 430
 		foreach($this->authorizations as $auth)
@@ -445,12 +445,12 @@  discard block
 block discarded – undo
445 445
 		return false;
446 446
 	}
447 447
 
448
-    /**
449
-     * Generates a Certificate Signing Request for the identifiers in the current LetsEncrypt Order instance. If possible, the base name will be the certificate
448
+	/**
449
+	 * Generates a Certificate Signing Request for the identifiers in the current LetsEncrypt Order instance. If possible, the base name will be the certificate
450 450
 	 * common name and all domain names in this LetsEncrypt Order instance will be added to the Subject Alternative Names entry.
451
-     *
452
-     * @return string	Returns the generated CSR as string, unprepared for LetsEncrypt. Preparation for the request happens in finalizeOrder()
453
-     */
451
+	 *
452
+	 * @return string	Returns the generated CSR as string, unprepared for LetsEncrypt. Preparation for the request happens in finalizeOrder()
453
+	 */
454 454
 	public function generateCSR()
455 455
 	{
456 456
 		$domains = array_map(function ($dns) { return $dns['value']; }, $this->identifiers);
@@ -472,14 +472,14 @@  discard block
 block discarded – undo
472 472
 		);
473 473
 
474 474
 		$san = implode(",", array_map(function ($dns) {
475
-            return "DNS:" . $dns;
476
-        }, $domains));
477
-        $tmpConf = tmpfile();
478
-        $tmpConfMeta = stream_get_meta_data($tmpConf);
479
-        $tmpConfPath = $tmpConfMeta["uri"];
480
-
481
-        fwrite($tmpConf,
482
-            'HOME = .
475
+			return "DNS:" . $dns;
476
+		}, $domains));
477
+		$tmpConf = tmpfile();
478
+		$tmpConfMeta = stream_get_meta_data($tmpConf);
479
+		$tmpConfPath = $tmpConfMeta["uri"];
480
+
481
+		fwrite($tmpConf,
482
+			'HOME = .
483 483
 			RANDFILE = $ENV::HOME/.rnd
484 484
 			[ req ]
485 485
 			default_bits = 4096
@@ -499,13 +499,13 @@  discard block
 block discarded – undo
499 499
 		return $csr;
500 500
 	}
501 501
 
502
-    /**
503
-     * Checks, for redundancy, whether all authorizations are valid, and finalizes the order. Updates this LetsEncrypt Order instance with the new data.
504
-     *
505
-     * @param string	$csr	The Certificate Signing Request as a string. Can be a custom CSR. If empty, a CSR will be generated with the generateCSR() function.
506
-     *
507
-     * @return boolean	Returns true if the finalize request was successful, false if not.
508
-     */
502
+	/**
503
+	 * Checks, for redundancy, whether all authorizations are valid, and finalizes the order. Updates this LetsEncrypt Order instance with the new data.
504
+	 *
505
+	 * @param string	$csr	The Certificate Signing Request as a string. Can be a custom CSR. If empty, a CSR will be generated with the generateCSR() function.
506
+	 *
507
+	 * @return boolean	Returns true if the finalize request was successful, false if not.
508
+	 */
509 509
 	public function finalizeOrder($csr = '')
510 510
 	{
511 511
 		if($this->status == 'pending')
@@ -542,22 +542,22 @@  discard block
 block discarded – undo
542 542
 		return false;
543 543
 	}
544 544
 
545
-    /**
546
-     * Gets whether the LetsEncrypt Order is finalized by checking whether the status is processing or valid. Keep in mind, a certificate is not yet available when the status still is processing.
547
-     *
548
-     * @return boolean	Returns true if finalized, false if not.
549
-     */
545
+	/**
546
+	 * Gets whether the LetsEncrypt Order is finalized by checking whether the status is processing or valid. Keep in mind, a certificate is not yet available when the status still is processing.
547
+	 *
548
+	 * @return boolean	Returns true if finalized, false if not.
549
+	 */
550 550
 	public function isFinalized()
551 551
 	{
552 552
 		return ($this->status == 'processing' || $this->status == 'valid');
553 553
 	}
554 554
 
555
-    /**
556
-     * Requests the certificate for this LetsEncrypt Order instance, after finalization. When the order status is still 'processing', the order will be polled max
555
+	/**
556
+	 * Requests the certificate for this LetsEncrypt Order instance, after finalization. When the order status is still 'processing', the order will be polled max
557 557
 	 * four times with five seconds in between. If the status becomes 'valid' in the meantime, the certificate will be requested. Else, the function returns false.
558
-     *
559
-     * @return boolean	Returns true if the certificate is stored successfully, false if the certificate could not be retrieved or the status remained 'processing'.
560
-     */
558
+	 *
559
+	 * @return boolean	Returns true if the certificate is stored successfully, false if the certificate could not be retrieved or the status remained 'processing'.
560
+	 */
561 561
 	public function getCertificate()
562 562
 	{
563 563
 		$polling = 0;
@@ -607,14 +607,14 @@  discard block
 block discarded – undo
607 607
 		return false;
608 608
 	}
609 609
 
610
-    /**
611
-     * Revokes the certificate in the current LetsEncrypt Order instance, if existent. Unlike stated in the ACME draft, the certificate revoke request cannot be signed
610
+	/**
611
+	 * Revokes the certificate in the current LetsEncrypt Order instance, if existent. Unlike stated in the ACME draft, the certificate revoke request cannot be signed
612 612
 	 * with the account private key, and will be signed with the certificate private key.
613
-     *
614
-     * @param int	$reason   The reason to revoke the LetsEncrypt Order instance certificate. Possible reasons can be found in section 5.3.1 of RFC5280.
615
-     *
616
-     * @return boolean	Returns true if the certificate was successfully revoked, false if not.
617
-     */
613
+	 *
614
+	 * @param int	$reason   The reason to revoke the LetsEncrypt Order instance certificate. Possible reasons can be found in section 5.3.1 of RFC5280.
615
+	 *
616
+	 * @return boolean	Returns true if the certificate was successfully revoked, false if not.
617
+	 */
618 618
 	public function revokeCertificate($reason = 0)
619 619
 	{
620 620
 		if($this->status == 'valid')
Please login to merge, or discard this patch.
LEClient/src/LEAccount.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -49,14 +49,14 @@  discard block
 block discarded – undo
49 49
 
50 50
 	private $log;
51 51
 
52
-    /**
53
-     * Initiates the LetsEncrypt Account class.
54
-     *
55
-     * @param LEConnector	$connector 		The LetsEncrypt Connector instance to use for HTTP requests.
56
-     * @param int 			$log 			The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
57
-     * @param array 		$email	 		The array of strings containing e-mail addresses. Only used when creating a new account.
58
-     * @param array 		$accountKeys Array containing location of account keys files.
59
-     */
52
+	/**
53
+	 * Initiates the LetsEncrypt Account class.
54
+	 *
55
+	 * @param LEConnector	$connector 		The LetsEncrypt Connector instance to use for HTTP requests.
56
+	 * @param int 			$log 			The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
57
+	 * @param array 		$email	 		The array of strings containing e-mail addresses. Only used when creating a new account.
58
+	 * @param array 		$accountKeys Array containing location of account keys files.
59
+	 */
60 60
 	public function __construct($connector, $log, $email, $accountKeys)
61 61
 	{
62 62
 		$this->connector = $connector;
@@ -77,13 +77,13 @@  discard block
 block discarded – undo
77 77
 		$this->getLEAccountData();
78 78
 	}
79 79
 
80
-    /**
81
-     * Creates a new LetsEncrypt account.
82
-     *
83
-     * @param array 	$email 	The array of strings containing e-mail addresses.
84
-     *
85
-     * @return object	Returns the new account URL when the account was successfully created, false if not.
86
-     */
80
+	/**
81
+	 * Creates a new LetsEncrypt account.
82
+	 *
83
+	 * @param array 	$email 	The array of strings containing e-mail addresses.
84
+	 *
85
+	 * @return object	Returns the new account URL when the account was successfully created, false if not.
86
+	 */
87 87
 	private function createLEAccount($email)
88 88
 	{
89 89
 		$contact = array_map(function($addr) { return empty($addr) ? '' : (strpos($addr, 'mailto') === false ? 'mailto:' . $addr : $addr); }, $email);
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 		return false;
98 98
 	}
99 99
 
100
-    /**
101
-     * Gets the LetsEncrypt account URL associated with the stored account keys.
102
-     *
103
-     * @return object	Returns the account URL if it is found, or false when none is found.
104
-     */
100
+	/**
101
+	 * Gets the LetsEncrypt account URL associated with the stored account keys.
102
+	 *
103
+	 * @return object	Returns the account URL if it is found, or false when none is found.
104
+	 */
105 105
 	private function getLEAccount()
106 106
 	{
107 107
 		$sign = $this->connector->signRequestJWK(array('onlyReturnExisting' => true), $this->connector->newAccount);
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 		return false;
115 115
 	}
116 116
 
117
-    /**
118
-     * Gets the LetsEncrypt account data from the account URL.
119
-     */
117
+	/**
118
+	 * Gets the LetsEncrypt account data from the account URL.
119
+	 */
120 120
 	private function getLEAccountData()
121 121
 	{
122 122
 		$sign = $this->connector->signRequestKid(array('' => ''), $this->connector->accountURL, $this->connector->accountURL);
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
 		}
138 138
 	}
139 139
 
140
-    /**
141
-     * Updates account data. Now just supporting new contact information.
142
-     *
143
-     * @param array 	$email	The array of strings containing e-mail adresses.
144
-     *
145
-     * @return boolean	Returns true if the update is successful, false if not.
146
-     */
140
+	/**
141
+	 * Updates account data. Now just supporting new contact information.
142
+	 *
143
+	 * @param array 	$email	The array of strings containing e-mail adresses.
144
+	 *
145
+	 * @return boolean	Returns true if the update is successful, false if not.
146
+	 */
147 147
 	public function updateAccount($email)
148 148
 	{
149 149
 		$contact = array_map(function($addr) { return empty($addr) ? '' : (strpos($addr, 'mailto') === false ? 'mailto:' . $addr : $addr); }, $email);
@@ -168,17 +168,17 @@  discard block
 block discarded – undo
168 168
 		}
169 169
 	}
170 170
 
171
-    /**
172
-     * Creates new RSA account keys and updates the keys with LetsEncrypt.
173
-     *
174
-     * @return boolean	Returns true if the update is successful, false if not.
175
-     */
171
+	/**
172
+	 * Creates new RSA account keys and updates the keys with LetsEncrypt.
173
+	 *
174
+	 * @return boolean	Returns true if the update is successful, false if not.
175
+	 */
176 176
 	public function changeAccountKeys()
177 177
 	{
178 178
 		LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'].'.new', $this->accountKeys['public_key'].'.new');
179 179
 		$privateKey = openssl_pkey_get_private(file_get_contents($this->accountKeys['private_key'].'.new'));
180 180
 		$details = openssl_pkey_get_details($privateKey);
181
-    $innerPayload = array('account' => $this->connector->accountURL, 'newKey' => array(
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"])
@@ -204,11 +204,11 @@  discard block
 block discarded – undo
204 204
 		}
205 205
 	}
206 206
 
207
-    /**
208
-     * Deactivates the LetsEncrypt account.
209
-     *
210
-     * @return boolean	Returns true if the deactivation is successful, false if not.
211
-     */
207
+	/**
208
+	 * Deactivates the LetsEncrypt account.
209
+	 *
210
+	 * @return boolean	Returns true if the deactivation is successful, false if not.
211
+	 */
212 212
 	public function deactivateAccount()
213 213
 	{
214 214
 		$sign = $this->connector->signRequestKid(array('status' => 'deactivated'), $this->connector->accountURL, $this->connector->accountURL);
Please login to merge, or discard this patch.
LEClient/src/LEFunctions.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
  */
37 37
 class LEFunctions
38 38
 {
39
-    /**
40
-     * Generates a new RSA keypair and saves both keys to a new file.
41
-     *
42
-     * @param string	$directory		The directory in which to store the new keys. If set to null or empty string - privateKeyFile and publicKeyFile will be treated as absolute paths.
43
-     * @param string	$privateKeyFile	The filename for the private key file.
44
-     * @param string	$publicKeyFile  The filename for the public key file.
45
-     * @param string	$keySize 	RSA key size, must be between 2048 and 4096 (default is 4096)
46
-     */
39
+	/**
40
+	 * Generates a new RSA keypair and saves both keys to a new file.
41
+	 *
42
+	 * @param string	$directory		The directory in which to store the new keys. If set to null or empty string - privateKeyFile and publicKeyFile will be treated as absolute paths.
43
+	 * @param string	$privateKeyFile	The filename for the private key file.
44
+	 * @param string	$publicKeyFile  The filename for the public key file.
45
+	 * @param string	$keySize 	RSA key size, must be between 2048 and 4096 (default is 4096)
46
+	 */
47 47
 	public static function RSAGenerateKeys($directory, $privateKeyFile = 'private.pem', $publicKeyFile = 'public.pem', $keySize = 4096)
48 48
 	{
49 49
 
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
 
73 73
 
74 74
 
75
-    /**
76
-     * Generates a new EC prime256v1 keypair and saves both keys to a new file.
77
-     *
78
-     * @param string	$directory		The directory in which to store the new keys. If set to null or empty string - privateKeyFile and publicKeyFile will be treated as absolute paths.
79
-     * @param string	$privateKeyFile	The filename for the private key file.
80
-     * @param string	$publicKeyFile  The filename for the public key file.
81
-     * @param string	$keysize  EC key size, possible values are 256 (prime256v1) or 384 (secp384r1), default is 256
82
-     */
75
+	/**
76
+	 * Generates a new EC prime256v1 keypair and saves both keys to a new file.
77
+	 *
78
+	 * @param string	$directory		The directory in which to store the new keys. If set to null or empty string - privateKeyFile and publicKeyFile will be treated as absolute paths.
79
+	 * @param string	$privateKeyFile	The filename for the private key file.
80
+	 * @param string	$publicKeyFile  The filename for the public key file.
81
+	 * @param string	$keysize  EC key size, possible values are 256 (prime256v1) or 384 (secp384r1), default is 256
82
+	 */
83 83
 	public static function ECGenerateKeys($directory, $privateKeyFile = 'private.pem', $publicKeyFile = 'public.pem', $keySize = 256)
84 84
 	{
85 85
 		if (version_compare(PHP_VERSION, '7.1.0') == -1) throw new \RuntimeException("PHP 7.1+ required for EC keys");
@@ -120,43 +120,43 @@  discard block
 block discarded – undo
120 120
 
121 121
 
122 122
 
123
-    /**
124
-     * Encodes a string input to a base64 encoded string which is URL safe.
125
-     *
126
-     * @param string	$input 	The input string to encode.
127
-     *
128
-     * @return string	Returns a URL safe base64 encoded string.
129
-     */
123
+	/**
124
+	 * Encodes a string input to a base64 encoded string which is URL safe.
125
+	 *
126
+	 * @param string	$input 	The input string to encode.
127
+	 *
128
+	 * @return string	Returns a URL safe base64 encoded string.
129
+	 */
130 130
 	public static function Base64UrlSafeEncode($input)
131
-    {
132
-        return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
133
-    }
134
-
135
-    /**
136
-     * Decodes a string that is URL safe base64 encoded.
137
-     *
138
-     * @param string	$input	The encoded input string to decode.
139
-     *
140
-     * @return string	Returns the decoded input string.
141
-     */
142
-    public static function Base64UrlSafeDecode($input)
143
-    {
144
-        $remainder = strlen($input) % 4;
145
-        if ($remainder) {
146
-            $padlen = 4 - $remainder;
147
-            $input .= str_repeat('=', $padlen);
148
-        }
149
-        return base64_decode(strtr($input, '-_', '+/'));
150
-    }
151
-
152
-
153
-
154
-    /**
155
-     * Outputs a log message.
156
-     *
157
-     * @param object	$data		The data to print.
158
-     * @param string	$function	The function name to print above. Defaults to the calling function's name from the stacktrace. (optional)
159
-     */
131
+	{
132
+		return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
133
+	}
134
+
135
+	/**
136
+	 * Decodes a string that is URL safe base64 encoded.
137
+	 *
138
+	 * @param string	$input	The encoded input string to decode.
139
+	 *
140
+	 * @return string	Returns the decoded input string.
141
+	 */
142
+	public static function Base64UrlSafeDecode($input)
143
+	{
144
+		$remainder = strlen($input) % 4;
145
+		if ($remainder) {
146
+			$padlen = 4 - $remainder;
147
+			$input .= str_repeat('=', $padlen);
148
+		}
149
+		return base64_decode(strtr($input, '-_', '+/'));
150
+	}
151
+
152
+
153
+
154
+	/**
155
+	 * Outputs a log message.
156
+	 *
157
+	 * @param object	$data		The data to print.
158
+	 * @param string	$function	The function name to print above. Defaults to the calling function's name from the stacktrace. (optional)
159
+	 */
160 160
 	public static function log($data, $function = '')
161 161
 	{
162 162
 		$e = new Exception();
@@ -178,34 +178,34 @@  discard block
 block discarded – undo
178 178
 
179 179
 
180 180
 
181
-    /**
182
-     * Makes a request to the HTTP challenge URL and checks whether the authorization is valid for the given $domain.
183
-     *
184
-     * @param string	$domain 			The domain to check the authorization for.
185
-     * @param string 	$token 				The token (filename) to request.
186
-     * @param string 	$keyAuthorization 	the keyAuthorization (file content) to compare.
187
-     *
188
-     * @return boolean	Returns true if the challenge is valid, false if not.
189
-     */
181
+	/**
182
+	 * Makes a request to the HTTP challenge URL and checks whether the authorization is valid for the given $domain.
183
+	 *
184
+	 * @param string	$domain 			The domain to check the authorization for.
185
+	 * @param string 	$token 				The token (filename) to request.
186
+	 * @param string 	$keyAuthorization 	the keyAuthorization (file content) to compare.
187
+	 *
188
+	 * @return boolean	Returns true if the challenge is valid, false if not.
189
+	 */
190 190
 	public static function checkHTTPChallenge($domain, $token, $keyAuthorization)
191 191
 	{
192 192
 		$requestURL = $domain . '/.well-known/acme-challenge/' . $token;
193 193
 		$handle = curl_init();
194
-        curl_setopt($handle, CURLOPT_URL, $requestURL);
195
-        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
196
-        curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
197
-        $response = curl_exec($handle);
194
+		curl_setopt($handle, CURLOPT_URL, $requestURL);
195
+		curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
196
+		curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
197
+		$response = curl_exec($handle);
198 198
 		return (!empty($response) && $response == $keyAuthorization);
199 199
 	}
200 200
 
201
-    /**
202
-     * Checks whether the applicable DNS TXT record is a valid authorization for the given $domain.
203
-     *
204
-     * @param string	$domain 	The domain to check the authorization for.
205
-     * @param string	$DNSDigest	The digest to compare the DNS record to.
206
-     *
207
-     * @return boolean	Returns true if the challenge is valid, false if not.
208
-     */
201
+	/**
202
+	 * Checks whether the applicable DNS TXT record is a valid authorization for the given $domain.
203
+	 *
204
+	 * @param string	$domain 	The domain to check the authorization for.
205
+	 * @param string	$DNSDigest	The digest to compare the DNS record to.
206
+	 *
207
+	 * @return boolean	Returns true if the challenge is valid, false if not.
208
+	 */
209 209
 	public static function checkDNSChallenge($domain, $DNSDigest)
210 210
 	{
211 211
 		$DNS = '_acme-challenge.' . str_replace('*.', '', $domain);
@@ -219,11 +219,11 @@  discard block
 block discarded – undo
219 219
 
220 220
 
221 221
 
222
-    /**
223
-     * Creates a simple .htaccess file in $directory which denies from all.
224
-     *
225
-     * @param string	$directory	The directory in which to put the .htaccess file.
226
-     */
222
+	/**
223
+	 * Creates a simple .htaccess file in $directory which denies from all.
224
+	 *
225
+	 * @param string	$directory	The directory in which to put the .htaccess file.
226
+	 */
227 227
 	public static function createhtaccess($directory)
228 228
 	{
229 229
 		file_put_contents($directory . '.htaccess', "order deny,allow\ndeny from all");
Please login to merge, or discard this patch.
LEClient/src/LEConnector.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 
44 44
 	public $keyChange;
45 45
 	public $newAccount;
46
-    public $newNonce;
46
+	public $newNonce;
47 47
 	public $newOrder;
48 48
 	public $revokeCert;
49 49
 
@@ -52,13 +52,13 @@  discard block
 block discarded – undo
52 52
 
53 53
 	private $log;
54 54
 
55
-    /**
56
-     * Initiates the LetsEncrypt Connector class.
57
-     *
58
-     * @param int 		$log			The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
59
-     * @param string	$baseURL 		The LetsEncrypt server URL to make requests to.
60
-     * @param array	$accountKeys Array containing location of account keys files.
61
-     */
55
+	/**
56
+	 * Initiates the LetsEncrypt Connector class.
57
+	 *
58
+	 * @param int 		$log			The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
59
+	 * @param string	$baseURL 		The LetsEncrypt server URL to make requests to.
60
+	 * @param array	$accountKeys Array containing location of account keys files.
61
+	 */
62 62
 	public function __construct($log, $baseURL, $accountKeys)
63 63
 	{
64 64
 		$this->baseURL = $baseURL;
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
 		$this->getNewNonce();
69 69
 	}
70 70
 
71
-    /**
72
-     * Requests the LetsEncrypt Directory and stores the necessary URLs in this LetsEncrypt Connector instance.
73
-     */
71
+	/**
72
+	 * Requests the LetsEncrypt Directory and stores the necessary URLs in this LetsEncrypt Connector instance.
73
+	 */
74 74
 	private function getLEDirectory()
75 75
 	{
76 76
 		$req = $this->get('/directory');
@@ -81,42 +81,42 @@  discard block
 block discarded – undo
81 81
 		$this->revokeCert = $req['body']['revokeCert'];
82 82
 	}
83 83
 
84
-    /**
85
-     * Requests a new nonce from the LetsEncrypt server and stores it in this LetsEncrypt Connector instance.
86
-     */
84
+	/**
85
+	 * Requests a new nonce from the LetsEncrypt server and stores it in this LetsEncrypt Connector instance.
86
+	 */
87 87
 	private function getNewNonce()
88 88
 	{
89 89
 		if(strpos($this->head($this->newNonce)['header'], "204 No Content") == false) throw new \RuntimeException('No new nonce.');
90 90
 	}
91 91
 
92
-    /**
93
-     * Makes a Curl request.
94
-     *
95
-     * @param string	$method	The HTTP method to use. Accepting GET, POST and HEAD requests.
96
-     * @param string 	$URL 	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
97
-     * @param object 	$data  	The body to attach to a POST request. Expected as a JSON encoded string.
98
-     *
99
-     * @return array 	Returns an array with the keys 'request', 'header' and 'body'.
100
-     */
92
+	/**
93
+	 * Makes a Curl request.
94
+	 *
95
+	 * @param string	$method	The HTTP method to use. Accepting GET, POST and HEAD requests.
96
+	 * @param string 	$URL 	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
97
+	 * @param object 	$data  	The body to attach to a POST request. Expected as a JSON encoded string.
98
+	 *
99
+	 * @return array 	Returns an array with the keys 'request', 'header' and 'body'.
100
+	 */
101 101
 	private function request($method, $URL, $data = null)
102 102
 	{
103 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;
107
-        $handle = curl_init();
108
-        curl_setopt($handle, CURLOPT_URL, $requestURL);
109
-        curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
110
-        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
111
-        curl_setopt($handle, CURLOPT_HEADER, true);
112
-
113
-        switch ($method) {
114
-            case 'GET':
115
-                break;
116
-            case 'POST':
117
-                curl_setopt($handle, CURLOPT_POST, true);
118
-                curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
119
-                break;
107
+		$handle = curl_init();
108
+		curl_setopt($handle, CURLOPT_URL, $requestURL);
109
+		curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
110
+		curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
111
+		curl_setopt($handle, CURLOPT_HEADER, true);
112
+
113
+		switch ($method) {
114
+			case 'GET':
115
+				break;
116
+			case 'POST':
117
+				curl_setopt($handle, CURLOPT_POST, true);
118
+				curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
119
+				break;
120 120
 			case 'HEAD':
121 121
 				curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'HEAD');
122 122
 				curl_setopt($handle, CURLOPT_NOBODY, true);
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
 			default:
125 125
 				throw new \RuntimeException('HTTP request ' . $method . ' not supported.');
126 126
 				break;
127
-        }
128
-        $response = curl_exec($handle);
127
+		}
128
+		$response = curl_exec($handle);
129 129
 
130
-        if(curl_errno($handle)) {
131
-            throw new \RuntimeException('Curl: ' . curl_error($handle));
132
-        }
130
+		if(curl_errno($handle)) {
131
+			throw new \RuntimeException('Curl: ' . curl_error($handle));
132
+		}
133 133
 
134
-        $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
134
+		$header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
135 135
 
136
-        $header = substr($response, 0, $header_size);
137
-        $body = substr($response, $header_size);
136
+		$header = substr($response, 0, $header_size);
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 140
 		if($this->log >= LECLient::LOG_DEBUG) LEFunctions::log($jsonresponse);
@@ -154,124 +154,124 @@  discard block
 block discarded – undo
154 154
 			if($method == 'POST') $this->getNewNonce(); // Not expecting a new nonce with GET and HEAD requests.
155 155
 		}
156 156
 
157
-        return $jsonresponse;
157
+		return $jsonresponse;
158 158
 	}
159 159
 
160
-    /**
161
-     * Makes a GET request.
162
-     *
163
-     * @param string	$url 	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
164
-     *
165
-     * @return array 	Returns an array with the keys 'request', 'header' and 'body'.
166
-     */
160
+	/**
161
+	 * Makes a GET request.
162
+	 *
163
+	 * @param string	$url 	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
164
+	 *
165
+	 * @return array 	Returns an array with the keys 'request', 'header' and 'body'.
166
+	 */
167 167
 	public function get($url)
168 168
 	{
169 169
 		return $this->request('GET', $url);
170 170
 	}
171 171
 
172 172
 	/**
173
-     * Makes a POST request.
174
-     *
175
-     * @param string 	$url	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
173
+	 * Makes a POST request.
174
+	 *
175
+	 * @param string 	$url	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
176 176
 	 * @param object 	$data	The body to attach to a POST request. Expected as a json string.
177
-     *
178
-     * @return array 	Returns an array with the keys 'request', 'header' and 'body'.
179
-     */
177
+	 *
178
+	 * @return array 	Returns an array with the keys 'request', 'header' and 'body'.
179
+	 */
180 180
 	public function post($url, $data = null)
181 181
 	{
182 182
 		return $this->request('POST', $url, $data);
183 183
 	}
184 184
 
185 185
 	/**
186
-     * Makes a HEAD request.
187
-     *
188
-     * @param string 	$url	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
189
-     *
190
-     * @return array	Returns an array with the keys 'request', 'header' and 'body'.
191
-     */
186
+	 * Makes a HEAD request.
187
+	 *
188
+	 * @param string 	$url	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
189
+	 *
190
+	 * @return array	Returns an array with the keys 'request', 'header' and 'body'.
191
+	 */
192 192
 	public function head($url)
193 193
 	{
194 194
 		return $this->request('HEAD', $url);
195 195
 	}
196 196
 
197
-    /**
198
-     * Generates a JSON Web Key signature to attach to the request.
199
-     *
200
-     * @param array 	$payload		The payload to add to the signature.
201
-     * @param string	$url 			The URL to use in the signature.
202
-     * @param string 	$privateKeyFile The private key to sign the request with. Defaults to 'private.pem'. Defaults to accountKeys[private_key].
203
-     *
204
-     * @return string	Returns a JSON encoded string containing the signature.
205
-     */
197
+	/**
198
+	 * Generates a JSON Web Key signature to attach to the request.
199
+	 *
200
+	 * @param array 	$payload		The payload to add to the signature.
201
+	 * @param string	$url 			The URL to use in the signature.
202
+	 * @param string 	$privateKeyFile The private key to sign the request with. Defaults to 'private.pem'. Defaults to accountKeys[private_key].
203
+	 *
204
+	 * @return string	Returns a JSON encoded string containing the signature.
205
+	 */
206 206
 	public function signRequestJWK($payload, $url, $privateKeyFile = '')
207
-    {
207
+	{
208 208
 		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
209 209
 		$privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
210
-        $details = openssl_pkey_get_details($privateKey);
211
-
212
-        $protected = array(
213
-            "alg" => "RS256",
214
-            "jwk" => array(
215
-                "kty" => "RSA",
216
-                "n" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["n"]),
217
-                "e" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["e"]),
218
-            ),
210
+		$details = openssl_pkey_get_details($privateKey);
211
+
212
+		$protected = array(
213
+			"alg" => "RS256",
214
+			"jwk" => array(
215
+				"kty" => "RSA",
216
+				"n" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["n"]),
217
+				"e" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["e"]),
218
+			),
219 219
 			"nonce" => $this->nonce,
220 220
 			"url" => $url
221
-        );
221
+		);
222 222
 
223
-        $payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
224
-        $protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
223
+		$payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
224
+		$protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
225 225
 
226
-        openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
227
-        $signed64 = LEFunctions::Base64UrlSafeEncode($signed);
226
+		openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
227
+		$signed64 = LEFunctions::Base64UrlSafeEncode($signed);
228 228
 
229
-        $data = array(
230
-            'protected' => $protected64,
231
-            'payload' => $payload64,
232
-            'signature' => $signed64
233
-        );
229
+		$data = array(
230
+			'protected' => $protected64,
231
+			'payload' => $payload64,
232
+			'signature' => $signed64
233
+		);
234 234
 
235
-        return json_encode($data);
236
-    }
235
+		return json_encode($data);
236
+	}
237 237
 
238 238
 	/**
239
-     * Generates a Key ID signature to attach to the request.
240
-     *
241
-     * @param array 	$payload		The payload to add to the signature.
239
+	 * Generates a Key ID signature to attach to the request.
240
+	 *
241
+	 * @param array 	$payload		The payload to add to the signature.
242 242
 	 * @param string	$kid			The Key ID to use in the signature.
243
-     * @param string	$url 			The URL to use in the signature.
244
-     * @param string 	$privateKeyFile The private key to sign the request with. Defaults to 'private.pem'. Defaults to accountKeys[private_key].
245
-     *
246
-     * @return string	Returns a JSON encoded string containing the signature.
247
-     */
243
+	 * @param string	$url 			The URL to use in the signature.
244
+	 * @param string 	$privateKeyFile The private key to sign the request with. Defaults to 'private.pem'. Defaults to accountKeys[private_key].
245
+	 *
246
+	 * @return string	Returns a JSON encoded string containing the signature.
247
+	 */
248 248
 	public function signRequestKid($payload, $kid, $url, $privateKeyFile = '')
249
-    {
249
+	{
250 250
 		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
251
-        $privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
252
-        $details = openssl_pkey_get_details($privateKey);
251
+		$privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
252
+		$details = openssl_pkey_get_details($privateKey);
253 253
 
254
-        $protected = array(
255
-            "alg" => "RS256",
256
-            "kid" => $kid,
254
+		$protected = array(
255
+			"alg" => "RS256",
256
+			"kid" => $kid,
257 257
 			"nonce" => $this->nonce,
258 258
 			"url" => $url
259
-        );
259
+		);
260 260
 
261
-        $payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
262
-        $protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
261
+		$payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
262
+		$protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
263 263
 
264
-        openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
265
-        $signed64 = LEFunctions::Base64UrlSafeEncode($signed);
264
+		openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
265
+		$signed64 = LEFunctions::Base64UrlSafeEncode($signed);
266 266
 
267
-        $data = array(
268
-            'protected' => $protected64,
269
-            'payload' => $payload64,
270
-            'signature' => $signed64
271
-        );
267
+		$data = array(
268
+			'protected' => $protected64,
269
+			'payload' => $payload64,
270
+			'signature' => $signed64
271
+		);
272 272
 
273
-        return json_encode($data);
274
-    }
273
+		return json_encode($data);
274
+	}
275 275
 }
276 276
 
277 277
 ?>
Please login to merge, or discard this patch.
LEClient/src/LEAuthorization.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
 	
47 47
 	private $log;
48 48
 	
49
-    /**
50
-     * Initiates the LetsEncrypt Authorization class. Child of a LetsEncrypt Order instance.
51
-     * 
52
-     * @param LEConnector	$connector			The LetsEncrypt Connector instance to use for HTTP requests.
53
-     * @param int 			$log 				The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
54
-     * @param string 		$authorizationURL 	The URL of the authorization, given by a LetsEncrypt order request.
55
-     */
49
+	/**
50
+	 * Initiates the LetsEncrypt Authorization class. Child of a LetsEncrypt Order instance.
51
+	 * 
52
+	 * @param LEConnector	$connector			The LetsEncrypt Connector instance to use for HTTP requests.
53
+	 * @param int 			$log 				The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
54
+	 * @param string 		$authorizationURL 	The URL of the authorization, given by a LetsEncrypt order request.
55
+	 */
56 56
 	public function __construct($connector, $log, $authorizationURL)
57 57
 	{
58 58
 		$this->connector = $connector;
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
 		}
74 74
 	}
75 75
 	
76
-    /**
77
-     * Updates the data associated with the current LetsEncrypt Authorization instance.
78
-     */
76
+	/**
77
+	 * Updates the data associated with the current LetsEncrypt Authorization instance.
78
+	 */
79 79
 	
80 80
 	public function updateData()
81 81
 	{
@@ -93,14 +93,14 @@  discard block
 block discarded – undo
93 93
 		}
94 94
 	}
95 95
 	
96
-    /**
97
-     * Gets the challenge of the given $type for this LetsEncrypt Authorization instance. Throws a Runtime Exception if the given $type is not found in this
96
+	/**
97
+	 * Gets the challenge of the given $type for this LetsEncrypt Authorization instance. Throws a Runtime Exception if the given $type is not found in this
98 98
 	 * LetsEncrypt Authorization instance.
99
-     * 
100
-     * @param int	$type 	The type of verification. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS.
101
-     * 
102
-     * @return array	Returns an array with the challenge of the requested $type.
103
-     */
99
+	 * 
100
+	 * @param int	$type 	The type of verification. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS.
101
+	 * 
102
+	 * @return array	Returns an array with the challenge of the requested $type.
103
+	 */
104 104
 	public function getChallenge($type)
105 105
 	{
106 106
 		foreach($this->challenges as $challenge)
Please login to merge, or discard this patch.