@@ -61,18 +61,18 @@ discard block |
||
61 | 61 | const CHALLENGE_TYPE_HTTP = 'http-01'; |
62 | 62 | const CHALLENGE_TYPE_DNS = 'dns-01'; |
63 | 63 | |
64 | - /** |
|
65 | - * 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. |
|
66 | - * |
|
67 | - * @param LEConnector $connector The LetsEncrypt Connector instance to use for HTTP requests. |
|
68 | - * @param int $log The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted. |
|
69 | - * @param array $certificateKeys Array containing location of certificate keys files. |
|
70 | - * @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. |
|
71 | - * @param array $domains The array of strings containing the domain names on the certificate. |
|
72 | - * @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) |
|
73 | - * @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. |
|
74 | - * @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. |
|
75 | - */ |
|
64 | + /** |
|
65 | + * 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. |
|
66 | + * |
|
67 | + * @param LEConnector $connector The LetsEncrypt Connector instance to use for HTTP requests. |
|
68 | + * @param int $log The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted. |
|
69 | + * @param array $certificateKeys Array containing location of certificate keys files. |
|
70 | + * @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. |
|
71 | + * @param array $domains The array of strings containing the domain names on the certificate. |
|
72 | + * @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) |
|
73 | + * @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. |
|
74 | + * @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. |
|
75 | + */ |
|
76 | 76 | public function __construct($connector, $log, $certificateKeys, $basename, $domains, $keyType = 'rsa-4096', $notBefore, $notAfter) |
77 | 77 | { |
78 | 78 | $this->connector = $connector; |
@@ -189,13 +189,13 @@ discard block |
||
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
192 | - /** |
|
193 | - * Creates a new LetsEncrypt order and fills this instance with its data. Subsequently creates a new RSA keypair for the certificate. |
|
194 | - * |
|
195 | - * @param array $domains The array of strings containing the domain names on the certificate. |
|
196 | - * @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. |
|
197 | - * @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. |
|
198 | - */ |
|
192 | + /** |
|
193 | + * Creates a new LetsEncrypt order and fills this instance with its data. Subsequently creates a new RSA keypair for the certificate. |
|
194 | + * |
|
195 | + * @param array $domains The array of strings containing the domain names on the certificate. |
|
196 | + * @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. |
|
197 | + * @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. |
|
198 | + */ |
|
199 | 199 | private function createOrder($domains, $notBefore, $notAfter) |
200 | 200 | { |
201 | 201 | $dns = array(); |
@@ -252,9 +252,9 @@ discard block |
||
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
255 | - /** |
|
256 | - * Fetches the latest data concerning this LetsEncrypt Order instance and fills this instance with the new data. |
|
257 | - */ |
|
255 | + /** |
|
256 | + * Fetches the latest data concerning this LetsEncrypt Order instance and fills this instance with the new data. |
|
257 | + */ |
|
258 | 258 | private function updateOrderData() |
259 | 259 | { |
260 | 260 | $sign = $this->connector->signRequestKid('', $this->connector->accountURL, $this->orderURL); |
@@ -280,8 +280,8 @@ discard block |
||
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
283 | - * 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. |
|
284 | - */ |
|
283 | + * 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. |
|
284 | + */ |
|
285 | 285 | private function updateAuthorizations() |
286 | 286 | { |
287 | 287 | $this->authorizations = array(); |
@@ -295,11 +295,11 @@ discard block |
||
295 | 295 | } |
296 | 296 | } |
297 | 297 | |
298 | - /** |
|
299 | - * Walks all LetsEncrypt Authorization instances and returns whether they are all valid (verified). |
|
300 | - * |
|
301 | - * @return boolean Returns true if all authorizations are valid (verified), returns false if not. |
|
302 | - */ |
|
298 | + /** |
|
299 | + * Walks all LetsEncrypt Authorization instances and returns whether they are all valid (verified). |
|
300 | + * |
|
301 | + * @return boolean Returns true if all authorizations are valid (verified), returns false if not. |
|
302 | + */ |
|
303 | 303 | public function allAuthorizationsValid() |
304 | 304 | { |
305 | 305 | if(count($this->authorizations) > 0) |
@@ -313,16 +313,16 @@ discard block |
||
313 | 313 | return false; |
314 | 314 | } |
315 | 315 | |
316 | - /** |
|
317 | - * Get all pending LetsEncrypt Authorization instances and return the necessary data for verification. The data in the return object depends on the $type. |
|
318 | - * |
|
319 | - * @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 |
|
316 | + /** |
|
317 | + * Get all pending LetsEncrypt Authorization instances and return the necessary data for verification. The data in the return object depends on the $type. |
|
318 | + * |
|
319 | + * @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 |
|
320 | 320 | * a Runtime Exception when requesting an unknown $type. Keep in mind a wildcard domain authorization only accepts LEOrder::CHALLENGE_TYPE_DNS. |
321 | - * |
|
322 | - * @return object Returns an array with verification data if successful, false if not pending LetsEncrypt Authorization instances were found. The return array always |
|
321 | + * |
|
322 | + * @return object Returns an array with verification data if successful, false if not pending LetsEncrypt Authorization instances were found. The return array always |
|
323 | 323 | * contains 'type' and 'identifier'. For LEOrder::CHALLENGE_TYPE_HTTP, the array contains 'filename' and 'content' for necessary the authorization file. |
324 | 324 | * For LEOrder::CHALLENGE_TYPE_DNS, the array contains 'DNSDigest', which is the content for the necessary DNS TXT entry. |
325 | - */ |
|
325 | + */ |
|
326 | 326 | |
327 | 327 | public function getPendingAuthorizations($type) |
328 | 328 | { |
@@ -364,16 +364,16 @@ discard block |
||
364 | 364 | return count($authorizations) > 0 ? $authorizations : false; |
365 | 365 | } |
366 | 366 | |
367 | - /** |
|
368 | - * Sends a verification request for a given $identifier and $type. The function itself checks whether the verification is valid before making the request. |
|
367 | + /** |
|
368 | + * Sends a verification request for a given $identifier and $type. The function itself checks whether the verification is valid before making the request. |
|
369 | 369 | * Updates the LetsEncrypt Authorization instances after a successful verification. |
370 | - * |
|
371 | - * @param string $identifier The domain name to verify. |
|
372 | - * @param int $type The type of verification. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS. |
|
370 | + * |
|
371 | + * @param string $identifier The domain name to verify. |
|
372 | + * @param int $type The type of verification. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS. |
|
373 | 373 | * @param boolean $localcheck Whether to verify the authorization locally before making the authorization request to LE. Optional, default to true. |
374 | - * |
|
375 | - * @return boolean Returns true when the verification request was successful, false if not. |
|
376 | - */ |
|
374 | + * |
|
375 | + * @return boolean Returns true when the verification request was successful, false if not. |
|
376 | + */ |
|
377 | 377 | public function verifyPendingOrderAuthorization($identifier, $type, $localcheck = true) |
378 | 378 | { |
379 | 379 | $privateKey = openssl_pkey_get_private(file_get_contents($this->connector->accountKeys['private_key'])); |
@@ -472,13 +472,13 @@ discard block |
||
472 | 472 | return false; |
473 | 473 | } |
474 | 474 | |
475 | - /** |
|
476 | - * Deactivate an LetsEncrypt Authorization instance. |
|
477 | - * |
|
478 | - * @param string $identifier The domain name for which the verification should be deactivated. |
|
479 | - * |
|
480 | - * @return boolean Returns true is the deactivation request was successful, false if not. |
|
481 | - */ |
|
475 | + /** |
|
476 | + * Deactivate an LetsEncrypt Authorization instance. |
|
477 | + * |
|
478 | + * @param string $identifier The domain name for which the verification should be deactivated. |
|
479 | + * |
|
480 | + * @return boolean Returns true is the deactivation request was successful, false if not. |
|
481 | + */ |
|
482 | 482 | public function deactivateOrderAuthorization($identifier) |
483 | 483 | { |
484 | 484 | foreach($this->authorizations as $auth) |
@@ -507,12 +507,12 @@ discard block |
||
507 | 507 | return false; |
508 | 508 | } |
509 | 509 | |
510 | - /** |
|
511 | - * Generates a Certificate Signing Request for the identifiers in the current LetsEncrypt Order instance. If possible, the base name will be the certificate |
|
510 | + /** |
|
511 | + * Generates a Certificate Signing Request for the identifiers in the current LetsEncrypt Order instance. If possible, the base name will be the certificate |
|
512 | 512 | * common name and all domain names in this LetsEncrypt Order instance will be added to the Subject Alternative Names entry. |
513 | - * |
|
514 | - * @return string Returns the generated CSR as string, unprepared for LetsEncrypt. Preparation for the request happens in finalizeOrder() |
|
515 | - */ |
|
513 | + * |
|
514 | + * @return string Returns the generated CSR as string, unprepared for LetsEncrypt. Preparation for the request happens in finalizeOrder() |
|
515 | + */ |
|
516 | 516 | public function generateCSR() |
517 | 517 | { |
518 | 518 | $domains = array_map(function ($dns) { return $dns['value']; }, $this->identifiers); |
@@ -534,14 +534,14 @@ discard block |
||
534 | 534 | ); |
535 | 535 | |
536 | 536 | $san = implode(",", array_map(function ($dns) { |
537 | - return "DNS:" . $dns; |
|
538 | - }, $domains)); |
|
539 | - $tmpConf = tmpfile(); |
|
540 | - $tmpConfMeta = stream_get_meta_data($tmpConf); |
|
541 | - $tmpConfPath = $tmpConfMeta["uri"]; |
|
542 | - |
|
543 | - fwrite($tmpConf, |
|
544 | - 'HOME = . |
|
537 | + return "DNS:" . $dns; |
|
538 | + }, $domains)); |
|
539 | + $tmpConf = tmpfile(); |
|
540 | + $tmpConfMeta = stream_get_meta_data($tmpConf); |
|
541 | + $tmpConfPath = $tmpConfMeta["uri"]; |
|
542 | + |
|
543 | + fwrite($tmpConf, |
|
544 | + 'HOME = . |
|
545 | 545 | RANDFILE = $ENV::HOME/.rnd |
546 | 546 | [ req ] |
547 | 547 | default_bits = ' . $this->keySize . ' |
@@ -561,13 +561,13 @@ discard block |
||
561 | 561 | return $csr; |
562 | 562 | } |
563 | 563 | |
564 | - /** |
|
565 | - * Checks, for redundancy, whether all authorizations are valid, and finalizes the order. Updates this LetsEncrypt Order instance with the new data. |
|
566 | - * |
|
567 | - * @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. |
|
568 | - * |
|
569 | - * @return boolean Returns true if the finalize request was successful, false if not. |
|
570 | - */ |
|
564 | + /** |
|
565 | + * Checks, for redundancy, whether all authorizations are valid, and finalizes the order. Updates this LetsEncrypt Order instance with the new data. |
|
566 | + * |
|
567 | + * @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. |
|
568 | + * |
|
569 | + * @return boolean Returns true if the finalize request was successful, false if not. |
|
570 | + */ |
|
571 | 571 | public function finalizeOrder($csr = '') |
572 | 572 | { |
573 | 573 | $this->updateOrderData(); |
@@ -617,22 +617,22 @@ discard block |
||
617 | 617 | return false; |
618 | 618 | } |
619 | 619 | |
620 | - /** |
|
621 | - * 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. |
|
622 | - * |
|
623 | - * @return boolean Returns true if finalized, false if not. |
|
624 | - */ |
|
620 | + /** |
|
621 | + * 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. |
|
622 | + * |
|
623 | + * @return boolean Returns true if finalized, false if not. |
|
624 | + */ |
|
625 | 625 | public function isFinalized() |
626 | 626 | { |
627 | 627 | return ($this->status == 'processing' || $this->status == 'valid'); |
628 | 628 | } |
629 | 629 | |
630 | - /** |
|
631 | - * Requests the certificate for this LetsEncrypt Order instance, after finalization. When the order status is still 'processing', the order will be polled max |
|
630 | + /** |
|
631 | + * Requests the certificate for this LetsEncrypt Order instance, after finalization. When the order status is still 'processing', the order will be polled max |
|
632 | 632 | * 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. |
633 | - * |
|
634 | - * @return boolean Returns true if the certificate is stored successfully, false if the certificate could not be retrieved or the status remained 'processing'. |
|
635 | - */ |
|
633 | + * |
|
634 | + * @return boolean Returns true if the certificate is stored successfully, false if the certificate could not be retrieved or the status remained 'processing'. |
|
635 | + */ |
|
636 | 636 | public function getCertificate() |
637 | 637 | { |
638 | 638 | $polling = 0; |
@@ -713,14 +713,14 @@ discard block |
||
713 | 713 | return false; |
714 | 714 | } |
715 | 715 | |
716 | - /** |
|
717 | - * Revokes the certificate in the current LetsEncrypt Order instance, if existent. Unlike stated in the ACME draft, the certificate revoke request cannot be signed |
|
716 | + /** |
|
717 | + * Revokes the certificate in the current LetsEncrypt Order instance, if existent. Unlike stated in the ACME draft, the certificate revoke request cannot be signed |
|
718 | 718 | * with the account private key, and will be signed with the certificate private key. |
719 | - * |
|
720 | - * @param int $reason The reason to revoke the LetsEncrypt Order instance certificate. Possible reasons can be found in section 5.3.1 of RFC5280. |
|
721 | - * |
|
722 | - * @return boolean Returns true if the certificate was successfully revoked, false if not. |
|
723 | - */ |
|
719 | + * |
|
720 | + * @param int $reason The reason to revoke the LetsEncrypt Order instance certificate. Possible reasons can be found in section 5.3.1 of RFC5280. |
|
721 | + * |
|
722 | + * @return boolean Returns true if the certificate was successfully revoked, false if not. |
|
723 | + */ |
|
724 | 724 | public function revokeCertificate($reason = 0) |
725 | 725 | { |
726 | 726 | if($this->status == 'valid' || $this->status == 'ready') |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | else throw LEOrderException::InvalidKeyTypeException($keyType); |
102 | 102 | } |
103 | 103 | |
104 | - if(preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notBefore) == false OR preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notAfter) == false) |
|
104 | + if (preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notBefore) == false OR preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notAfter) == false) |
|
105 | 105 | { |
106 | 106 | throw LEOrderException::InvalidArgumentException('notBefore and notAfter fields must be empty or be a string similar to 0000-00-00T00:00:00Z'); |
107 | 107 | } |
108 | 108 | |
109 | 109 | $this->certificateKeys = $certificateKeys; |
110 | 110 | |
111 | - if(file_exists($this->certificateKeys['private_key']) AND file_exists($this->certificateKeys['order']) AND file_exists($this->certificateKeys['public_key'])) |
|
111 | + if (file_exists($this->certificateKeys['private_key']) AND file_exists($this->certificateKeys['order']) AND file_exists($this->certificateKeys['public_key'])) |
|
112 | 112 | { |
113 | 113 | $this->orderURL = file_get_contents($this->certificateKeys['order']); |
114 | 114 | if (filter_var($this->orderURL, FILTER_VALIDATE_URL) !== false) |
@@ -117,24 +117,24 @@ discard block |
||
117 | 117 | { |
118 | 118 | $sign = $this->connector->signRequestKid('', $this->connector->accountURL, $this->orderURL); |
119 | 119 | $post = $this->connector->post($this->orderURL, $sign); |
120 | - if($post['body']['status'] == "invalid") |
|
120 | + if ($post['body']['status'] == "invalid") |
|
121 | 121 | { |
122 | 122 | throw LEOrderException::InvalidOrderStatusException(); |
123 | 123 | } |
124 | 124 | |
125 | 125 | $orderdomains = array_map(function($ident) { return $ident['value']; }, $post['body']['identifiers']); |
126 | 126 | $diff = array_merge(array_diff($orderdomains, $domains), array_diff($domains, $orderdomains)); |
127 | - if(!empty($diff)) |
|
127 | + if (!empty($diff)) |
|
128 | 128 | { |
129 | 129 | foreach ($this->certificateKeys as $file) |
130 | 130 | { |
131 | - if (is_file($file)) rename($file, $file.'.old'); |
|
131 | + if (is_file($file)) rename($file, $file . '.old'); |
|
132 | 132 | } |
133 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
133 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
134 | 134 | { |
135 | 135 | $this->log->info('Domains do not match order data. Renaming current files and creating new order.'); |
136 | 136 | } |
137 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct'); |
|
137 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct'); |
|
138 | 138 | $this->createOrder($domains, $notBefore, $notAfter, $keyType); |
139 | 139 | } |
140 | 140 | else |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $this->identifiers = $post['body']['identifiers']; |
145 | 145 | $this->authorizationURLs = $post['body']['authorizations']; |
146 | 146 | $this->finalizeURL = $post['body']['finalize']; |
147 | - if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
147 | + if (array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
148 | 148 | $this->updateAuthorizations(); |
149 | 149 | } |
150 | 150 | } |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | { |
155 | 155 | if (is_file($file)) unlink($file); |
156 | 156 | } |
157 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
157 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
158 | 158 | { |
159 | 159 | $this->log->info('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.'); |
160 | 160 | } |
161 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct'); |
|
161 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct'); |
|
162 | 162 | $this->createOrder($domains, $notBefore, $notAfter); |
163 | 163 | } |
164 | 164 | } |
@@ -169,22 +169,22 @@ discard block |
||
169 | 169 | { |
170 | 170 | if (is_file($file)) unlink($file); |
171 | 171 | } |
172 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
172 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
173 | 173 | { |
174 | 174 | $this->log->info('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.'); |
175 | 175 | } |
176 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct'); |
|
176 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct'); |
|
177 | 177 | |
178 | 178 | $this->createOrder($domains, $notBefore, $notAfter); |
179 | 179 | } |
180 | 180 | } |
181 | 181 | else |
182 | 182 | { |
183 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
183 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
184 | 184 | { |
185 | 185 | $this->log->info('No order found for \'' . $this->basename . '\'. Creating new order.'); |
186 | 186 | } |
187 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct'); |
|
187 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct'); |
|
188 | 188 | $this->createOrder($domains, $notBefore, $notAfter); |
189 | 189 | } |
190 | 190 | } |
@@ -199,18 +199,18 @@ discard block |
||
199 | 199 | private function createOrder($domains, $notBefore, $notAfter) |
200 | 200 | { |
201 | 201 | $dns = array(); |
202 | - foreach($domains as $domain) |
|
202 | + foreach ($domains as $domain) |
|
203 | 203 | { |
204 | - if(preg_match_all('~(\*\.)~', $domain) > 1) throw LEOrderException::InvalidArgumentException('Cannot create orders with multiple wildcards in one domain.'); |
|
204 | + if (preg_match_all('~(\*\.)~', $domain) > 1) throw LEOrderException::InvalidArgumentException('Cannot create orders with multiple wildcards in one domain.'); |
|
205 | 205 | $dns[] = array('type' => 'dns', 'value' => $domain); |
206 | 206 | } |
207 | 207 | $payload = array("identifiers" => $dns, 'notBefore' => $notBefore, 'notAfter' => $notAfter); |
208 | 208 | $sign = $this->connector->signRequestKid($payload, $this->connector->accountURL, $this->connector->newOrder); |
209 | 209 | $post = $this->connector->post($this->connector->newOrder, $sign); |
210 | 210 | |
211 | - if($post['status'] === 201) |
|
211 | + if ($post['status'] === 201) |
|
212 | 212 | { |
213 | - if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) |
|
213 | + if (preg_match('~Location: (\S+)~i', $post['header'], $matches)) |
|
214 | 214 | { |
215 | 215 | $this->orderURL = trim($matches[1]); |
216 | 216 | file_put_contents($this->certificateKeys['order'], $this->orderURL); |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | $this->identifiers = $post['body']['identifiers']; |
233 | 233 | $this->authorizationURLs = $post['body']['authorizations']; |
234 | 234 | $this->finalizeURL = $post['body']['finalize']; |
235 | - if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
235 | + if (array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
236 | 236 | $this->updateAuthorizations(); |
237 | 237 | |
238 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
238 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
239 | 239 | { |
240 | 240 | $this->log->info('Created order for \'' . $this->basename . '\'.'); |
241 | 241 | } |
242 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)'); |
|
242 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)'); |
|
243 | 243 | } |
244 | 244 | else |
245 | 245 | { |
@@ -259,23 +259,23 @@ discard block |
||
259 | 259 | { |
260 | 260 | $sign = $this->connector->signRequestKid('', $this->connector->accountURL, $this->orderURL); |
261 | 261 | $post = $this->connector->post($this->orderURL, $sign); |
262 | - if($post['status'] === 200) |
|
262 | + if ($post['status'] === 200) |
|
263 | 263 | { |
264 | 264 | $this->status = $post['body']['status']; |
265 | 265 | $this->expires = $post['body']['expires']; |
266 | 266 | $this->identifiers = $post['body']['identifiers']; |
267 | 267 | $this->authorizationURLs = $post['body']['authorizations']; |
268 | 268 | $this->finalizeURL = $post['body']['finalize']; |
269 | - if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
269 | + if (array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
270 | 270 | $this->updateAuthorizations(); |
271 | 271 | } |
272 | 272 | else |
273 | 273 | { |
274 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
274 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
275 | 275 | { |
276 | 276 | $this->log->info('Cannot update data for order \'' . $this->basename . '\'.'); |
277 | 277 | } |
278 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData'); |
|
278 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData'); |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
@@ -285,12 +285,12 @@ discard block |
||
285 | 285 | private function updateAuthorizations() |
286 | 286 | { |
287 | 287 | $this->authorizations = array(); |
288 | - foreach($this->authorizationURLs as $authURL) |
|
288 | + foreach ($this->authorizationURLs as $authURL) |
|
289 | 289 | { |
290 | 290 | if (filter_var($authURL, FILTER_VALIDATE_URL)) |
291 | 291 | { |
292 | 292 | $auth = new LEAuthorization($this->connector, $this->log, $authURL); |
293 | - if($auth != false) $this->authorizations[] = $auth; |
|
293 | + if ($auth != false) $this->authorizations[] = $auth; |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | } |
@@ -302,11 +302,11 @@ discard block |
||
302 | 302 | */ |
303 | 303 | public function allAuthorizationsValid() |
304 | 304 | { |
305 | - if(count($this->authorizations) > 0) |
|
305 | + if (count($this->authorizations) > 0) |
|
306 | 306 | { |
307 | - foreach($this->authorizations as $auth) |
|
307 | + foreach ($this->authorizations as $auth) |
|
308 | 308 | { |
309 | - if($auth->status != 'valid') return false; |
|
309 | + if ($auth->status != 'valid') return false; |
|
310 | 310 | } |
311 | 311 | return true; |
312 | 312 | } |
@@ -339,15 +339,15 @@ discard block |
||
339 | 339 | ); |
340 | 340 | $digest = LEFunctions::Base64UrlSafeEncode(hash('sha256', json_encode($header), true)); |
341 | 341 | |
342 | - foreach($this->authorizations as $auth) |
|
342 | + foreach ($this->authorizations as $auth) |
|
343 | 343 | { |
344 | - if($auth->status == 'pending') |
|
344 | + if ($auth->status == 'pending') |
|
345 | 345 | { |
346 | 346 | $challenge = $auth->getChallenge($type); |
347 | - if($challenge['status'] == 'pending') |
|
347 | + if ($challenge['status'] == 'pending') |
|
348 | 348 | { |
349 | 349 | $keyAuthorization = $challenge['token'] . '.' . $digest; |
350 | - switch(strtolower($type)) |
|
350 | + switch (strtolower($type)) |
|
351 | 351 | { |
352 | 352 | case LEOrder::CHALLENGE_TYPE_HTTP: |
353 | 353 | $authorizations[] = array('type' => LEOrder::CHALLENGE_TYPE_HTTP, 'identifier' => $auth->identifier['value'], 'filename' => $challenge['token'], 'content' => $keyAuthorization); |
@@ -387,34 +387,34 @@ discard block |
||
387 | 387 | ); |
388 | 388 | $digest = LEFunctions::Base64UrlSafeEncode(hash('sha256', json_encode($header), true)); |
389 | 389 | |
390 | - foreach($this->authorizations as $auth) |
|
390 | + foreach ($this->authorizations as $auth) |
|
391 | 391 | { |
392 | - if($auth->identifier['value'] == $identifier) |
|
392 | + if ($auth->identifier['value'] == $identifier) |
|
393 | 393 | { |
394 | - if($auth->status == 'pending') |
|
394 | + if ($auth->status == 'pending') |
|
395 | 395 | { |
396 | 396 | $challenge = $auth->getChallenge($type); |
397 | - if($challenge['status'] == 'pending') |
|
397 | + if ($challenge['status'] == 'pending') |
|
398 | 398 | { |
399 | 399 | $keyAuthorization = $challenge['token'] . '.' . $digest; |
400 | - switch($type) |
|
400 | + switch ($type) |
|
401 | 401 | { |
402 | 402 | case LEOrder::CHALLENGE_TYPE_HTTP: |
403 | - if($localcheck == false OR LEFunctions::checkHTTPChallenge($identifier, $challenge['token'], $keyAuthorization)) |
|
403 | + if ($localcheck == false OR LEFunctions::checkHTTPChallenge($identifier, $challenge['token'], $keyAuthorization)) |
|
404 | 404 | { |
405 | 405 | $sign = $this->connector->signRequestKid(array('keyAuthorization' => $keyAuthorization), $this->connector->accountURL, $challenge['url']); |
406 | 406 | $post = $this->connector->post($challenge['url'], $sign); |
407 | - if($post['status'] === 200) |
|
407 | + if ($post['status'] === 200) |
|
408 | 408 | { |
409 | - if($localcheck) |
|
409 | + if ($localcheck) |
|
410 | 410 | { |
411 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
411 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
412 | 412 | { |
413 | 413 | $this->log->info('HTTP challenge for \'' . $identifier . '\' valid.'); |
414 | 414 | } |
415 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization'); |
|
415 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization'); |
|
416 | 416 | } |
417 | - while($auth->status == 'pending') |
|
417 | + while ($auth->status == 'pending') |
|
418 | 418 | { |
419 | 419 | sleep(1); |
420 | 420 | $auth->updateData(); |
@@ -424,30 +424,30 @@ discard block |
||
424 | 424 | } |
425 | 425 | else |
426 | 426 | { |
427 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
427 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
428 | 428 | { |
429 | 429 | $this->log->info('HTTP challenge for \'' . $identifier . '\' tested locally, found invalid.'); |
430 | 430 | } |
431 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested locally, found invalid.', 'function verifyPendingOrderAuthorization'); |
|
431 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested locally, found invalid.', 'function verifyPendingOrderAuthorization'); |
|
432 | 432 | } |
433 | 433 | break; |
434 | 434 | case LEOrder::CHALLENGE_TYPE_DNS: |
435 | 435 | $DNSDigest = LEFunctions::Base64UrlSafeEncode(hash('sha256', $keyAuthorization, true)); |
436 | - if($localcheck == false OR LEFunctions::checkDNSChallenge($identifier, $DNSDigest)) |
|
436 | + if ($localcheck == false OR LEFunctions::checkDNSChallenge($identifier, $DNSDigest)) |
|
437 | 437 | { |
438 | 438 | $sign = $this->connector->signRequestKid(array('keyAuthorization' => $keyAuthorization), $this->connector->accountURL, $challenge['url']); |
439 | 439 | $post = $this->connector->post($challenge['url'], $sign); |
440 | - if($post['status'] === 200) |
|
440 | + if ($post['status'] === 200) |
|
441 | 441 | { |
442 | - if($localcheck) |
|
442 | + if ($localcheck) |
|
443 | 443 | { |
444 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
444 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
445 | 445 | { |
446 | 446 | $this->log->info('DNS challenge for \'' . $identifier . '\' valid.'); |
447 | 447 | } |
448 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization'); |
|
448 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization'); |
|
449 | 449 | } |
450 | - while($auth->status == 'pending') |
|
450 | + while ($auth->status == 'pending') |
|
451 | 451 | { |
452 | 452 | sleep(1); |
453 | 453 | $auth->updateData(); |
@@ -457,11 +457,11 @@ discard block |
||
457 | 457 | } |
458 | 458 | else |
459 | 459 | { |
460 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
460 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
461 | 461 | { |
462 | 462 | $this->log->info('DNS challenge for \'' . $identifier . '\' tested locally, found invalid.'); |
463 | 463 | } |
464 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested locally, found invalid.', 'function verifyPendingOrderAuthorization'); |
|
464 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested locally, found invalid.', 'function verifyPendingOrderAuthorization'); |
|
465 | 465 | } |
466 | 466 | break; |
467 | 467 | } |
@@ -481,29 +481,29 @@ discard block |
||
481 | 481 | */ |
482 | 482 | public function deactivateOrderAuthorization($identifier) |
483 | 483 | { |
484 | - foreach($this->authorizations as $auth) |
|
484 | + foreach ($this->authorizations as $auth) |
|
485 | 485 | { |
486 | - if($auth->identifier['value'] == $identifier) |
|
486 | + if ($auth->identifier['value'] == $identifier) |
|
487 | 487 | { |
488 | 488 | $sign = $this->connector->signRequestKid(array('status' => 'deactivated'), $this->connector->accountURL, $auth->authorizationURL); |
489 | 489 | $post = $this->connector->post($auth->authorizationURL, $sign); |
490 | - if($post['status'] === 200) |
|
490 | + if ($post['status'] === 200) |
|
491 | 491 | { |
492 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
492 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
493 | 493 | { |
494 | 494 | $this->log->info('Authorization for \'' . $identifier . '\' deactivated.'); |
495 | 495 | } |
496 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization'); |
|
496 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization'); |
|
497 | 497 | $this->updateAuthorizations(); |
498 | 498 | return true; |
499 | 499 | } |
500 | 500 | } |
501 | 501 | } |
502 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
502 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
503 | 503 | { |
504 | 504 | $this->log->info('No authorization found for \'' . $identifier . '\', cannot deactivate.'); |
505 | 505 | } |
506 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization'); |
|
506 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization'); |
|
507 | 507 | return false; |
508 | 508 | } |
509 | 509 | |
@@ -515,12 +515,12 @@ discard block |
||
515 | 515 | */ |
516 | 516 | public function generateCSR() |
517 | 517 | { |
518 | - $domains = array_map(function ($dns) { return $dns['value']; }, $this->identifiers); |
|
519 | - if(in_array($this->basename, $domains)) |
|
518 | + $domains = array_map(function($dns) { return $dns['value']; }, $this->identifiers); |
|
519 | + if (in_array($this->basename, $domains)) |
|
520 | 520 | { |
521 | 521 | $CN = $this->basename; |
522 | 522 | } |
523 | - elseif(in_array('*.' . $this->basename, $domains)) |
|
523 | + elseif (in_array('*.' . $this->basename, $domains)) |
|
524 | 524 | { |
525 | 525 | $CN = '*.' . $this->basename; |
526 | 526 | } |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | "commonName" => $CN |
534 | 534 | ); |
535 | 535 | |
536 | - $san = implode(",", array_map(function ($dns) { |
|
536 | + $san = implode(",", array_map(function($dns) { |
|
537 | 537 | return "DNS:" . $dns; |
538 | 538 | }, $domains)); |
539 | 539 | $tmpConf = tmpfile(); |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | |
558 | 558 | $privateKey = openssl_pkey_get_private(file_get_contents($this->certificateKeys['private_key'])); |
559 | 559 | $csr = openssl_csr_new($dn, $privateKey, array('config' => $tmpConfPath, 'digest_alg' => 'sha256')); |
560 | - openssl_csr_export ($csr, $csr); |
|
560 | + openssl_csr_export($csr, $csr); |
|
561 | 561 | return $csr; |
562 | 562 | } |
563 | 563 | |
@@ -571,48 +571,48 @@ discard block |
||
571 | 571 | public function finalizeOrder($csr = '') |
572 | 572 | { |
573 | 573 | $this->updateOrderData(); |
574 | - if($this->status == 'ready') |
|
574 | + if ($this->status == 'ready') |
|
575 | 575 | { |
576 | - if($this->allAuthorizationsValid()) |
|
576 | + if ($this->allAuthorizationsValid()) |
|
577 | 577 | { |
578 | - if(empty($csr)) $csr = $this->generateCSR(); |
|
579 | - if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) $csr = $matches[1]; |
|
578 | + if (empty($csr)) $csr = $this->generateCSR(); |
|
579 | + if (preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) $csr = $matches[1]; |
|
580 | 580 | $csr = trim(LEFunctions::Base64UrlSafeEncode(base64_decode($csr))); |
581 | 581 | $sign = $this->connector->signRequestKid(array('csr' => $csr), $this->connector->accountURL, $this->finalizeURL); |
582 | 582 | $post = $this->connector->post($this->finalizeURL, $sign); |
583 | - if($post['status'] === 200) |
|
583 | + if ($post['status'] === 200) |
|
584 | 584 | { |
585 | 585 | $this->status = $post['body']['status']; |
586 | 586 | $this->expires = $post['body']['expires']; |
587 | 587 | $this->identifiers = $post['body']['identifiers']; |
588 | 588 | $this->authorizationURLs = $post['body']['authorizations']; |
589 | 589 | $this->finalizeURL = $post['body']['finalize']; |
590 | - if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
590 | + if (array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
591 | 591 | $this->updateAuthorizations(); |
592 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
592 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
593 | 593 | { |
594 | 594 | $this->log->info('Order for \'' . $this->basename . '\' finalized.'); |
595 | 595 | } |
596 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder'); |
|
596 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder'); |
|
597 | 597 | return true; |
598 | 598 | } |
599 | 599 | } |
600 | 600 | else |
601 | 601 | { |
602 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
602 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
603 | 603 | { |
604 | 604 | $this->log->info('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.'); |
605 | 605 | } |
606 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder'); |
|
606 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder'); |
|
607 | 607 | } |
608 | 608 | } |
609 | 609 | else |
610 | 610 | { |
611 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
611 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
612 | 612 | { |
613 | 613 | $this->log->info('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.'); |
614 | 614 | } |
615 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder'); |
|
615 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder'); |
|
616 | 616 | } |
617 | 617 | return false; |
618 | 618 | } |
@@ -636,79 +636,79 @@ discard block |
||
636 | 636 | public function getCertificate() |
637 | 637 | { |
638 | 638 | $polling = 0; |
639 | - while($this->status == 'processing' && $polling < 4) |
|
639 | + while ($this->status == 'processing' && $polling < 4) |
|
640 | 640 | { |
641 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
641 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
642 | 642 | { |
643 | 643 | $this->log->info('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...'); |
644 | 644 | } |
645 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate'); |
|
645 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate'); |
|
646 | 646 | sleep(5); |
647 | 647 | $this->updateOrderData(); |
648 | 648 | $polling++; |
649 | 649 | } |
650 | - if($this->status == 'valid') |
|
650 | + if ($this->status == 'valid') |
|
651 | 651 | { |
652 | - if(!empty($this->certificateURL)) |
|
652 | + if (!empty($this->certificateURL)) |
|
653 | 653 | { |
654 | 654 | $sign = $this->connector->signRequestKid('', $this->connector->accountURL, $this->certificateURL); |
655 | 655 | $post = $this->connector->post($this->certificateURL, $sign); |
656 | - if($post['status'] === 200) |
|
656 | + if ($post['status'] === 200) |
|
657 | 657 | { |
658 | - if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $post['body'], $matches)) |
|
658 | + if (preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $post['body'], $matches)) |
|
659 | 659 | { |
660 | - if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'], $matches[0][0]); |
|
660 | + if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'], $matches[0][0]); |
|
661 | 661 | |
662 | - if(count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate'])) |
|
662 | + if (count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate'])) |
|
663 | 663 | { |
664 | - $fullchain = $matches[0][0]."\n"; |
|
665 | - for($i=1;$i<count($matches[0]);$i++) |
|
664 | + $fullchain = $matches[0][0] . "\n"; |
|
665 | + for ($i = 1; $i < count($matches[0]); $i++) |
|
666 | 666 | { |
667 | - $fullchain .= $matches[0][$i]."\n"; |
|
667 | + $fullchain .= $matches[0][$i] . "\n"; |
|
668 | 668 | } |
669 | 669 | file_put_contents(trim($this->certificateKeys['fullchain_certificate']), $fullchain); |
670 | 670 | } |
671 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
671 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
672 | 672 | { |
673 | 673 | $this->log->info('Certificate for \'' . $this->basename . '\' saved'); |
674 | 674 | } |
675 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate'); |
|
675 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate'); |
|
676 | 676 | return true; |
677 | 677 | } |
678 | 678 | else |
679 | 679 | { |
680 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
680 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
681 | 681 | { |
682 | 682 | $this->log->info('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.'); |
683 | 683 | } |
684 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate'); |
|
684 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate'); |
|
685 | 685 | } |
686 | 686 | } |
687 | 687 | else |
688 | 688 | { |
689 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
689 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
690 | 690 | { |
691 | 691 | $this->log->info('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.'); |
692 | 692 | } |
693 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate'); |
|
693 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate'); |
|
694 | 694 | } |
695 | 695 | } |
696 | 696 | else |
697 | 697 | { |
698 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
698 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
699 | 699 | { |
700 | 700 | $this->log->info('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.'); |
701 | 701 | } |
702 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.', 'function getCertificate'); |
|
702 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.', 'function getCertificate'); |
|
703 | 703 | } |
704 | 704 | } |
705 | 705 | else |
706 | 706 | { |
707 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
707 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
708 | 708 | { |
709 | 709 | $this->log->info('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.'); |
710 | 710 | } |
711 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate'); |
|
711 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate'); |
|
712 | 712 | } |
713 | 713 | return false; |
714 | 714 | } |
@@ -723,13 +723,13 @@ discard block |
||
723 | 723 | */ |
724 | 724 | public function revokeCertificate($reason = 0) |
725 | 725 | { |
726 | - if($this->status == 'valid' || $this->status == 'ready') |
|
726 | + if ($this->status == 'valid' || $this->status == 'ready') |
|
727 | 727 | { |
728 | 728 | if (isset($this->certificateKeys['certificate'])) $certFile = $this->certificateKeys['certificate']; |
729 | 729 | elseif (isset($this->certificateKeys['fullchain_certificate'])) $certFile = $this->certificateKeys['fullchain_certificate']; |
730 | 730 | else throw LEOrderException::InvalidConfigurationException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] required'); |
731 | 731 | |
732 | - if(file_exists($certFile) && file_exists($this->certificateKeys['private_key'])) |
|
732 | + if (file_exists($certFile) && file_exists($this->certificateKeys['private_key'])) |
|
733 | 733 | { |
734 | 734 | $certificate = file_get_contents($this->certificateKeys['certificate']); |
735 | 735 | preg_match('~-----BEGIN\sCERTIFICATE-----(.*)-----END\sCERTIFICATE-----~s', $certificate, $matches); |
@@ -737,40 +737,40 @@ discard block |
||
737 | 737 | |
738 | 738 | $sign = $this->connector->signRequestJWK(array('certificate' => $certificate, 'reason' => $reason), $this->connector->revokeCert, $this->certificateKeys['private_key']); |
739 | 739 | $post = $this->connector->post($this->connector->revokeCert, $sign); |
740 | - if($post['status'] === 200) |
|
740 | + if ($post['status'] === 200) |
|
741 | 741 | { |
742 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
742 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
743 | 743 | { |
744 | 744 | $this->log->info('Certificate for order \'' . $this->basename . '\' revoked.'); |
745 | 745 | } |
746 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate'); |
|
746 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate'); |
|
747 | 747 | return true; |
748 | 748 | } |
749 | 749 | else |
750 | 750 | { |
751 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
751 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
752 | 752 | { |
753 | 753 | $this->log->info('Certificate for order \'' . $this->basename . '\' cannot be revoked.'); |
754 | 754 | } |
755 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate'); |
|
755 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate'); |
|
756 | 756 | } |
757 | 757 | } |
758 | 758 | else |
759 | 759 | { |
760 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
760 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
761 | 761 | { |
762 | 762 | $this->log->info('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.'); |
763 | 763 | } |
764 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate'); |
|
764 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate'); |
|
765 | 765 | } |
766 | 766 | } |
767 | 767 | else |
768 | 768 | { |
769 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
769 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
770 | 770 | { |
771 | 771 | $this->log->info('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.'); |
772 | 772 | } |
773 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate'); |
|
773 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate'); |
|
774 | 774 | } |
775 | 775 | return false; |
776 | 776 | } |
@@ -83,13 +83,11 @@ discard block |
||
83 | 83 | { |
84 | 84 | $this->keyType = 'rsa'; |
85 | 85 | $this->keySize = 4096; |
86 | - } |
|
87 | - elseif ($keyType == 'ec') |
|
86 | + } elseif ($keyType == 'ec') |
|
88 | 87 | { |
89 | 88 | $this->keyType = 'ec'; |
90 | 89 | $this->keySize = 256; |
91 | - } |
|
92 | - else |
|
90 | + } else |
|
93 | 91 | { |
94 | 92 | preg_match_all('/^(rsa|ec)\-([0-9]{3,4})$/', $keyType, $keyTypeParts, PREG_SET_ORDER, 0); |
95 | 93 | |
@@ -97,8 +95,9 @@ discard block |
||
97 | 95 | { |
98 | 96 | $this->keyType = $keyTypeParts[0][1]; |
99 | 97 | $this->keySize = intval($keyTypeParts[0][2]); |
98 | + } else { |
|
99 | + throw LEOrderException::InvalidKeyTypeException($keyType); |
|
100 | 100 | } |
101 | - else throw LEOrderException::InvalidKeyTypeException($keyType); |
|
102 | 101 | } |
103 | 102 | |
104 | 103 | if(preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notBefore) == false OR preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notAfter) == false) |
@@ -128,63 +127,71 @@ discard block |
||
128 | 127 | { |
129 | 128 | foreach ($this->certificateKeys as $file) |
130 | 129 | { |
131 | - if (is_file($file)) rename($file, $file.'.old'); |
|
130 | + if (is_file($file)) { |
|
131 | + rename($file, $file.'.old'); |
|
132 | + } |
|
132 | 133 | } |
133 | 134 | if($this->log instanceof \Psr\Log\LoggerInterface) |
134 | 135 | { |
135 | 136 | $this->log->info('Domains do not match order data. Renaming current files and creating new order.'); |
137 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
138 | + LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct'); |
|
136 | 139 | } |
137 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct'); |
|
138 | 140 | $this->createOrder($domains, $notBefore, $notAfter, $keyType); |
139 | - } |
|
140 | - else |
|
141 | + } else |
|
141 | 142 | { |
142 | 143 | $this->status = $post['body']['status']; |
143 | 144 | $this->expires = $post['body']['expires']; |
144 | 145 | $this->identifiers = $post['body']['identifiers']; |
145 | 146 | $this->authorizationURLs = $post['body']['authorizations']; |
146 | 147 | $this->finalizeURL = $post['body']['finalize']; |
147 | - if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
148 | + if(array_key_exists('certificate', $post['body'])) { |
|
149 | + $this->certificateURL = $post['body']['certificate']; |
|
150 | + } |
|
148 | 151 | $this->updateAuthorizations(); |
149 | 152 | } |
150 | - } |
|
151 | - catch (\Exception $e) |
|
153 | + } catch (\Exception $e) |
|
152 | 154 | { |
153 | 155 | foreach ($this->certificateKeys as $file) |
154 | 156 | { |
155 | - if (is_file($file)) unlink($file); |
|
157 | + if (is_file($file)) { |
|
158 | + unlink($file); |
|
159 | + } |
|
156 | 160 | } |
157 | 161 | if($this->log instanceof \Psr\Log\LoggerInterface) |
158 | 162 | { |
159 | 163 | $this->log->info('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.'); |
164 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
165 | + LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct'); |
|
160 | 166 | } |
161 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct'); |
|
162 | 167 | $this->createOrder($domains, $notBefore, $notAfter); |
163 | 168 | } |
164 | - } |
|
165 | - else |
|
169 | + } else |
|
166 | 170 | { |
167 | 171 | |
168 | 172 | foreach ($this->certificateKeys as $file) |
169 | 173 | { |
170 | - if (is_file($file)) unlink($file); |
|
174 | + if (is_file($file)) { |
|
175 | + unlink($file); |
|
176 | + } |
|
171 | 177 | } |
172 | 178 | if($this->log instanceof \Psr\Log\LoggerInterface) |
173 | 179 | { |
174 | 180 | $this->log->info('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.'); |
181 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
182 | + LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct'); |
|
175 | 183 | } |
176 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct'); |
|
177 | 184 | |
178 | 185 | $this->createOrder($domains, $notBefore, $notAfter); |
179 | 186 | } |
180 | - } |
|
181 | - else |
|
187 | + } else |
|
182 | 188 | { |
183 | 189 | if($this->log instanceof \Psr\Log\LoggerInterface) |
184 | 190 | { |
185 | 191 | $this->log->info('No order found for \'' . $this->basename . '\'. Creating new order.'); |
192 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
193 | + LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct'); |
|
186 | 194 | } |
187 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct'); |
|
188 | 195 | $this->createOrder($domains, $notBefore, $notAfter); |
189 | 196 | } |
190 | 197 | } |
@@ -201,7 +208,9 @@ discard block |
||
201 | 208 | $dns = array(); |
202 | 209 | foreach($domains as $domain) |
203 | 210 | { |
204 | - if(preg_match_all('~(\*\.)~', $domain) > 1) throw LEOrderException::InvalidArgumentException('Cannot create orders with multiple wildcards in one domain.'); |
|
211 | + if(preg_match_all('~(\*\.)~', $domain) > 1) { |
|
212 | + throw LEOrderException::InvalidArgumentException('Cannot create orders with multiple wildcards in one domain.'); |
|
213 | + } |
|
205 | 214 | $dns[] = array('type' => 'dns', 'value' => $domain); |
206 | 215 | } |
207 | 216 | $payload = array("identifiers" => $dns, 'notBefore' => $notBefore, 'notAfter' => $notAfter); |
@@ -217,12 +226,10 @@ discard block |
||
217 | 226 | if ($this->keyType == "rsa") |
218 | 227 | { |
219 | 228 | LEFunctions::RSAgenerateKeys(null, $this->certificateKeys['private_key'], $this->certificateKeys['public_key'], $this->keySize); |
220 | - } |
|
221 | - elseif ($this->keyType == "ec") |
|
229 | + } elseif ($this->keyType == "ec") |
|
222 | 230 | { |
223 | 231 | LEFunctions::ECgenerateKeys(null, $this->certificateKeys['private_key'], $this->certificateKeys['public_key'], $this->keySize); |
224 | - } |
|
225 | - else |
|
232 | + } else |
|
226 | 233 | { |
227 | 234 | throw LEOrderException::InvalidKeyTypeException($this->keyType); |
228 | 235 | } |
@@ -232,21 +239,22 @@ discard block |
||
232 | 239 | $this->identifiers = $post['body']['identifiers']; |
233 | 240 | $this->authorizationURLs = $post['body']['authorizations']; |
234 | 241 | $this->finalizeURL = $post['body']['finalize']; |
235 | - if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
242 | + if(array_key_exists('certificate', $post['body'])) { |
|
243 | + $this->certificateURL = $post['body']['certificate']; |
|
244 | + } |
|
236 | 245 | $this->updateAuthorizations(); |
237 | 246 | |
238 | 247 | if($this->log instanceof \Psr\Log\LoggerInterface) |
239 | 248 | { |
240 | 249 | $this->log->info('Created order for \'' . $this->basename . '\'.'); |
250 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
251 | + LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)'); |
|
241 | 252 | } |
242 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)'); |
|
243 | - } |
|
244 | - else |
|
253 | + } else |
|
245 | 254 | { |
246 | 255 | throw LEOrderException::CreateFailedException('New-order returned invalid response.'); |
247 | 256 | } |
248 | - } |
|
249 | - else |
|
257 | + } else |
|
250 | 258 | { |
251 | 259 | throw LEOrderException::CreateFailedException('Creating new order failed.'); |
252 | 260 | } |
@@ -266,16 +274,18 @@ discard block |
||
266 | 274 | $this->identifiers = $post['body']['identifiers']; |
267 | 275 | $this->authorizationURLs = $post['body']['authorizations']; |
268 | 276 | $this->finalizeURL = $post['body']['finalize']; |
269 | - if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
277 | + if(array_key_exists('certificate', $post['body'])) { |
|
278 | + $this->certificateURL = $post['body']['certificate']; |
|
279 | + } |
|
270 | 280 | $this->updateAuthorizations(); |
271 | - } |
|
272 | - else |
|
281 | + } else |
|
273 | 282 | { |
274 | 283 | if($this->log instanceof \Psr\Log\LoggerInterface) |
275 | 284 | { |
276 | 285 | $this->log->info('Cannot update data for order \'' . $this->basename . '\'.'); |
286 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
287 | + LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData'); |
|
277 | 288 | } |
278 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData'); |
|
279 | 289 | } |
280 | 290 | } |
281 | 291 | |
@@ -290,7 +300,9 @@ discard block |
||
290 | 300 | if (filter_var($authURL, FILTER_VALIDATE_URL)) |
291 | 301 | { |
292 | 302 | $auth = new LEAuthorization($this->connector, $this->log, $authURL); |
293 | - if($auth != false) $this->authorizations[] = $auth; |
|
303 | + if($auth != false) { |
|
304 | + $this->authorizations[] = $auth; |
|
305 | + } |
|
294 | 306 | } |
295 | 307 | } |
296 | 308 | } |
@@ -306,7 +318,9 @@ discard block |
||
306 | 318 | { |
307 | 319 | foreach($this->authorizations as $auth) |
308 | 320 | { |
309 | - if($auth->status != 'valid') return false; |
|
321 | + if($auth->status != 'valid') { |
|
322 | + return false; |
|
323 | + } |
|
310 | 324 | } |
311 | 325 | return true; |
312 | 326 | } |
@@ -411,8 +425,9 @@ discard block |
||
411 | 425 | if($this->log instanceof \Psr\Log\LoggerInterface) |
412 | 426 | { |
413 | 427 | $this->log->info('HTTP challenge for \'' . $identifier . '\' valid.'); |
428 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
429 | + LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization'); |
|
414 | 430 | } |
415 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization'); |
|
416 | 431 | } |
417 | 432 | while($auth->status == 'pending') |
418 | 433 | { |
@@ -421,14 +436,14 @@ discard block |
||
421 | 436 | } |
422 | 437 | return true; |
423 | 438 | } |
424 | - } |
|
425 | - else |
|
439 | + } else |
|
426 | 440 | { |
427 | 441 | if($this->log instanceof \Psr\Log\LoggerInterface) |
428 | 442 | { |
429 | 443 | $this->log->info('HTTP challenge for \'' . $identifier . '\' tested locally, found invalid.'); |
444 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
445 | + LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested locally, found invalid.', 'function verifyPendingOrderAuthorization'); |
|
430 | 446 | } |
431 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested locally, found invalid.', 'function verifyPendingOrderAuthorization'); |
|
432 | 447 | } |
433 | 448 | break; |
434 | 449 | case LEOrder::CHALLENGE_TYPE_DNS: |
@@ -444,8 +459,9 @@ discard block |
||
444 | 459 | if($this->log instanceof \Psr\Log\LoggerInterface) |
445 | 460 | { |
446 | 461 | $this->log->info('DNS challenge for \'' . $identifier . '\' valid.'); |
462 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
463 | + LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization'); |
|
447 | 464 | } |
448 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization'); |
|
449 | 465 | } |
450 | 466 | while($auth->status == 'pending') |
451 | 467 | { |
@@ -454,14 +470,14 @@ discard block |
||
454 | 470 | } |
455 | 471 | return true; |
456 | 472 | } |
457 | - } |
|
458 | - else |
|
473 | + } else |
|
459 | 474 | { |
460 | 475 | if($this->log instanceof \Psr\Log\LoggerInterface) |
461 | 476 | { |
462 | 477 | $this->log->info('DNS challenge for \'' . $identifier . '\' tested locally, found invalid.'); |
478 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
479 | + LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested locally, found invalid.', 'function verifyPendingOrderAuthorization'); |
|
463 | 480 | } |
464 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested locally, found invalid.', 'function verifyPendingOrderAuthorization'); |
|
465 | 481 | } |
466 | 482 | break; |
467 | 483 | } |
@@ -492,8 +508,9 @@ discard block |
||
492 | 508 | if($this->log instanceof \Psr\Log\LoggerInterface) |
493 | 509 | { |
494 | 510 | $this->log->info('Authorization for \'' . $identifier . '\' deactivated.'); |
511 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
512 | + LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization'); |
|
495 | 513 | } |
496 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization'); |
|
497 | 514 | $this->updateAuthorizations(); |
498 | 515 | return true; |
499 | 516 | } |
@@ -502,8 +519,9 @@ discard block |
||
502 | 519 | if($this->log instanceof \Psr\Log\LoggerInterface) |
503 | 520 | { |
504 | 521 | $this->log->info('No authorization found for \'' . $identifier . '\', cannot deactivate.'); |
522 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
523 | + LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization'); |
|
505 | 524 | } |
506 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization'); |
|
507 | 525 | return false; |
508 | 526 | } |
509 | 527 | |
@@ -519,12 +537,10 @@ discard block |
||
519 | 537 | if(in_array($this->basename, $domains)) |
520 | 538 | { |
521 | 539 | $CN = $this->basename; |
522 | - } |
|
523 | - elseif(in_array('*.' . $this->basename, $domains)) |
|
540 | + } elseif(in_array('*.' . $this->basename, $domains)) |
|
524 | 541 | { |
525 | 542 | $CN = '*.' . $this->basename; |
526 | - } |
|
527 | - else |
|
543 | + } else |
|
528 | 544 | { |
529 | 545 | $CN = $domains[0]; |
530 | 546 | } |
@@ -575,8 +591,12 @@ discard block |
||
575 | 591 | { |
576 | 592 | if($this->allAuthorizationsValid()) |
577 | 593 | { |
578 | - if(empty($csr)) $csr = $this->generateCSR(); |
|
579 | - if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) $csr = $matches[1]; |
|
594 | + if(empty($csr)) { |
|
595 | + $csr = $this->generateCSR(); |
|
596 | + } |
|
597 | + if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) { |
|
598 | + $csr = $matches[1]; |
|
599 | + } |
|
580 | 600 | $csr = trim(LEFunctions::Base64UrlSafeEncode(base64_decode($csr))); |
581 | 601 | $sign = $this->connector->signRequestKid(array('csr' => $csr), $this->connector->accountURL, $this->finalizeURL); |
582 | 602 | $post = $this->connector->post($this->finalizeURL, $sign); |
@@ -587,32 +607,35 @@ discard block |
||
587 | 607 | $this->identifiers = $post['body']['identifiers']; |
588 | 608 | $this->authorizationURLs = $post['body']['authorizations']; |
589 | 609 | $this->finalizeURL = $post['body']['finalize']; |
590 | - if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
610 | + if(array_key_exists('certificate', $post['body'])) { |
|
611 | + $this->certificateURL = $post['body']['certificate']; |
|
612 | + } |
|
591 | 613 | $this->updateAuthorizations(); |
592 | 614 | if($this->log instanceof \Psr\Log\LoggerInterface) |
593 | 615 | { |
594 | 616 | $this->log->info('Order for \'' . $this->basename . '\' finalized.'); |
617 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
618 | + LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder'); |
|
595 | 619 | } |
596 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder'); |
|
597 | 620 | return true; |
598 | 621 | } |
599 | - } |
|
600 | - else |
|
622 | + } else |
|
601 | 623 | { |
602 | 624 | if($this->log instanceof \Psr\Log\LoggerInterface) |
603 | 625 | { |
604 | 626 | $this->log->info('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.'); |
627 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
628 | + LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder'); |
|
605 | 629 | } |
606 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder'); |
|
607 | 630 | } |
608 | - } |
|
609 | - else |
|
631 | + } else |
|
610 | 632 | { |
611 | 633 | if($this->log instanceof \Psr\Log\LoggerInterface) |
612 | 634 | { |
613 | 635 | $this->log->info('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.'); |
636 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
637 | + LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder'); |
|
614 | 638 | } |
615 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder'); |
|
616 | 639 | } |
617 | 640 | return false; |
618 | 641 | } |
@@ -641,8 +664,9 @@ discard block |
||
641 | 664 | if($this->log instanceof \Psr\Log\LoggerInterface) |
642 | 665 | { |
643 | 666 | $this->log->info('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...'); |
667 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
668 | + LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate'); |
|
644 | 669 | } |
645 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate'); |
|
646 | 670 | sleep(5); |
647 | 671 | $this->updateOrderData(); |
648 | 672 | $polling++; |
@@ -657,7 +681,9 @@ discard block |
||
657 | 681 | { |
658 | 682 | if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $post['body'], $matches)) |
659 | 683 | { |
660 | - if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'], $matches[0][0]); |
|
684 | + if (isset($this->certificateKeys['certificate'])) { |
|
685 | + file_put_contents($this->certificateKeys['certificate'], $matches[0][0]); |
|
686 | + } |
|
661 | 687 | |
662 | 688 | if(count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate'])) |
663 | 689 | { |
@@ -671,44 +697,45 @@ discard block |
||
671 | 697 | if($this->log instanceof \Psr\Log\LoggerInterface) |
672 | 698 | { |
673 | 699 | $this->log->info('Certificate for \'' . $this->basename . '\' saved'); |
700 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
701 | + LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate'); |
|
674 | 702 | } |
675 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate'); |
|
676 | 703 | return true; |
677 | - } |
|
678 | - else |
|
704 | + } else |
|
679 | 705 | { |
680 | 706 | if($this->log instanceof \Psr\Log\LoggerInterface) |
681 | 707 | { |
682 | 708 | $this->log->info('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.'); |
709 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
710 | + LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate'); |
|
683 | 711 | } |
684 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate'); |
|
685 | 712 | } |
686 | - } |
|
687 | - else |
|
713 | + } else |
|
688 | 714 | { |
689 | 715 | if($this->log instanceof \Psr\Log\LoggerInterface) |
690 | 716 | { |
691 | 717 | $this->log->info('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.'); |
718 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
719 | + LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate'); |
|
692 | 720 | } |
693 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate'); |
|
694 | 721 | } |
695 | - } |
|
696 | - else |
|
722 | + } else |
|
697 | 723 | { |
698 | 724 | if($this->log instanceof \Psr\Log\LoggerInterface) |
699 | 725 | { |
700 | 726 | $this->log->info('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.'); |
727 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
728 | + LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.', 'function getCertificate'); |
|
701 | 729 | } |
702 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.', 'function getCertificate'); |
|
703 | 730 | } |
704 | - } |
|
705 | - else |
|
731 | + } else |
|
706 | 732 | { |
707 | 733 | if($this->log instanceof \Psr\Log\LoggerInterface) |
708 | 734 | { |
709 | 735 | $this->log->info('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.'); |
736 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
737 | + LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate'); |
|
710 | 738 | } |
711 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate'); |
|
712 | 739 | } |
713 | 740 | return false; |
714 | 741 | } |
@@ -725,9 +752,13 @@ discard block |
||
725 | 752 | { |
726 | 753 | if($this->status == 'valid' || $this->status == 'ready') |
727 | 754 | { |
728 | - if (isset($this->certificateKeys['certificate'])) $certFile = $this->certificateKeys['certificate']; |
|
729 | - elseif (isset($this->certificateKeys['fullchain_certificate'])) $certFile = $this->certificateKeys['fullchain_certificate']; |
|
730 | - else throw LEOrderException::InvalidConfigurationException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] required'); |
|
755 | + if (isset($this->certificateKeys['certificate'])) { |
|
756 | + $certFile = $this->certificateKeys['certificate']; |
|
757 | + } elseif (isset($this->certificateKeys['fullchain_certificate'])) { |
|
758 | + $certFile = $this->certificateKeys['fullchain_certificate']; |
|
759 | + } else { |
|
760 | + throw LEOrderException::InvalidConfigurationException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] required'); |
|
761 | + } |
|
731 | 762 | |
732 | 763 | if(file_exists($certFile) && file_exists($this->certificateKeys['private_key'])) |
733 | 764 | { |
@@ -742,35 +773,36 @@ discard block |
||
742 | 773 | if($this->log instanceof \Psr\Log\LoggerInterface) |
743 | 774 | { |
744 | 775 | $this->log->info('Certificate for order \'' . $this->basename . '\' revoked.'); |
776 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
777 | + LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate'); |
|
745 | 778 | } |
746 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate'); |
|
747 | 779 | return true; |
748 | - } |
|
749 | - else |
|
780 | + } else |
|
750 | 781 | { |
751 | 782 | if($this->log instanceof \Psr\Log\LoggerInterface) |
752 | 783 | { |
753 | 784 | $this->log->info('Certificate for order \'' . $this->basename . '\' cannot be revoked.'); |
785 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
786 | + LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate'); |
|
754 | 787 | } |
755 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate'); |
|
756 | 788 | } |
757 | - } |
|
758 | - else |
|
789 | + } else |
|
759 | 790 | { |
760 | 791 | if($this->log instanceof \Psr\Log\LoggerInterface) |
761 | 792 | { |
762 | 793 | $this->log->info('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.'); |
794 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
795 | + LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate'); |
|
763 | 796 | } |
764 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate'); |
|
765 | 797 | } |
766 | - } |
|
767 | - else |
|
798 | + } else |
|
768 | 799 | { |
769 | 800 | if($this->log instanceof \Psr\Log\LoggerInterface) |
770 | 801 | { |
771 | 802 | $this->log->info('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.'); |
803 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
804 | + LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate'); |
|
772 | 805 | } |
773 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate'); |
|
774 | 806 | } |
775 | 807 | return false; |
776 | 808 | } |
@@ -54,17 +54,17 @@ discard block |
||
54 | 54 | const LOG_STATUS = 1; // Logs only messages and faults. |
55 | 55 | const LOG_DEBUG = 2; // Logs messages, faults and raw responses from HTTP requests. |
56 | 56 | |
57 | - /** |
|
58 | - * Initiates the LetsEncrypt main client. |
|
59 | - * |
|
60 | - * @param array $email The array of strings containing e-mail addresses. Only used in this function when creating a new account. |
|
61 | - * @param boolean $acmeURL ACME URL, can be string or one of predefined values: LE_STAGING or LE_PRODUCTION. Defaults to LE_STAGING. |
|
62 | - * @param int $log The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted. Defaults to LOG_OFF. (optional) |
|
63 | - * @param string $certificateKeys The main directory in which all keys (and certificates), including account keys, are stored. Defaults to 'keys/'. (optional) |
|
64 | - * @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) |
|
65 | - * @param string $accountKeys The directory in which the account keys are stored. Is a subdir inside $certificateKeys. Defaults to '__account/'.(optional) |
|
66 | - * @param array $accountKeys Optional array containing location of account private and public keys. Required paths are private_key, public_key. |
|
67 | - */ |
|
57 | + /** |
|
58 | + * Initiates the LetsEncrypt main client. |
|
59 | + * |
|
60 | + * @param array $email The array of strings containing e-mail addresses. Only used in this function when creating a new account. |
|
61 | + * @param boolean $acmeURL ACME URL, can be string or one of predefined values: LE_STAGING or LE_PRODUCTION. Defaults to LE_STAGING. |
|
62 | + * @param int $log The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted. Defaults to LOG_OFF. (optional) |
|
63 | + * @param string $certificateKeys The main directory in which all keys (and certificates), including account keys, are stored. Defaults to 'keys/'. (optional) |
|
64 | + * @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) |
|
65 | + * @param string $accountKeys The directory in which the account keys are stored. Is a subdir inside $certificateKeys. Defaults to '__account/'.(optional) |
|
66 | + * @param array $accountKeys Optional array containing location of account private and public keys. Required paths are private_key, public_key. |
|
67 | + */ |
|
68 | 68 | public function __construct($email, $acmeURL = LEClient::LE_PRODUCTION, $log = LEClient::LOG_OFF, $certificateKeys = 'keys/', $accountKeys = '__account/') |
69 | 69 | { |
70 | 70 | $this->log = $log; |
@@ -163,27 +163,27 @@ discard block |
||
163 | 163 | } |
164 | 164 | |
165 | 165 | |
166 | - /** |
|
167 | - * Returns the LetsEncrypt account used in the current client. |
|
166 | + /** |
|
167 | + * Returns the LetsEncrypt account used in the current client. |
|
168 | 168 | * |
169 | 169 | * @return LEAccount The LetsEncrypt Account instance used by the client. |
170 | - */ |
|
170 | + */ |
|
171 | 171 | public function getAccount() |
172 | 172 | { |
173 | 173 | return $this->account; |
174 | 174 | } |
175 | 175 | |
176 | - /** |
|
177 | - * Returns a LetsEncrypt order. If an order exists, this one is returned. If not, a new order is created and returned. |
|
178 | - * |
|
179 | - * @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. |
|
180 | - * @param array $domains The array of strings containing the domain names on the certificate. |
|
181 | - * @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) |
|
182 | - * @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) |
|
183 | - * @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) |
|
184 | - * |
|
185 | - * @return LEOrder The LetsEncrypt Order instance which is either retrieved or created. |
|
186 | - */ |
|
176 | + /** |
|
177 | + * Returns a LetsEncrypt order. If an order exists, this one is returned. If not, a new order is created and returned. |
|
178 | + * |
|
179 | + * @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. |
|
180 | + * @param array $domains The array of strings containing the domain names on the certificate. |
|
181 | + * @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) |
|
182 | + * @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) |
|
183 | + * @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) |
|
184 | + * |
|
185 | + * @return LEOrder The LetsEncrypt Order instance which is either retrieved or created. |
|
186 | + */ |
|
187 | 187 | public function getOrCreateOrder($basename, $domains, $keyType = 'rsa-4096', $notBefore = '', $notAfter = '') |
188 | 188 | { |
189 | 189 | return new LEOrder($this->connector, $this->log, $this->certificateKeys, $basename, $domains, $keyType, $notBefore, $notAfter); |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | |
51 | 51 | private $log; |
52 | 52 | |
53 | - const LOG_OFF = 0; // Logs no messages or faults, except Runtime Exceptions. |
|
54 | - const LOG_STATUS = 1; // Logs only messages and faults. |
|
55 | - const LOG_DEBUG = 2; // Logs messages, faults and raw responses from HTTP requests. |
|
53 | + const LOG_OFF = 0; // Logs no messages or faults, except Runtime Exceptions. |
|
54 | + const LOG_STATUS = 1; // Logs only messages and faults. |
|
55 | + const LOG_DEBUG = 2; // Logs messages, faults and raw responses from HTTP requests. |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Initiates the LetsEncrypt main client. |
@@ -87,26 +87,26 @@ discard block |
||
87 | 87 | { |
88 | 88 | $certificateKeysDir = $certificateKeys; |
89 | 89 | |
90 | - if(!file_exists($certificateKeys)) |
|
90 | + if (!file_exists($certificateKeys)) |
|
91 | 91 | { |
92 | 92 | mkdir($certificateKeys, 0755, true); |
93 | 93 | LEFunctions::createhtaccess($certificateKeys); |
94 | 94 | } |
95 | 95 | |
96 | 96 | $this->certificateKeys = array( |
97 | - "public_key" => $certificateKeys.'/public.pem', |
|
98 | - "private_key" => $certificateKeys.'/private.pem', |
|
99 | - "certificate" => $certificateKeys.'/certificate.crt', |
|
100 | - "fullchain_certificate" => $certificateKeys.'/fullchain.crt', |
|
101 | - "order" => $certificateKeys.'/order' |
|
97 | + "public_key" => $certificateKeys . '/public.pem', |
|
98 | + "private_key" => $certificateKeys . '/private.pem', |
|
99 | + "certificate" => $certificateKeys . '/certificate.crt', |
|
100 | + "fullchain_certificate" => $certificateKeys . '/fullchain.crt', |
|
101 | + "order" => $certificateKeys . '/order' |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | elseif (is_array($certificateKeys)) |
105 | 105 | { |
106 | 106 | if (!isset($certificateKeys['certificate']) && !isset($certificateKeys['fullchain_certificate'])) throw LEClientException::InvalidArgumentException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] file path must be set.'); |
107 | 107 | if (!isset($certificateKeys['private_key'])) throw LEClientException::InvalidArgumentException('certificateKeys[private_key] file path must be set.'); |
108 | - if (!isset($certificateKeys['order'])) $certificateKeys['order'] = dirname($certificateKeys['private_key']).'/order'; |
|
109 | - if (!isset($certificateKeys['public_key'])) $certificateKeys['public_key'] = dirname($certificateKeys['private_key']).'/public.pem'; |
|
108 | + if (!isset($certificateKeys['order'])) $certificateKeys['order'] = dirname($certificateKeys['private_key']) . '/order'; |
|
109 | + if (!isset($certificateKeys['public_key'])) $certificateKeys['public_key'] = dirname($certificateKeys['private_key']) . '/public.pem'; |
|
110 | 110 | |
111 | 111 | foreach ($certificateKeys as $param => $file) { |
112 | 112 | $parentDir = dirname($file); |
@@ -122,17 +122,17 @@ discard block |
||
122 | 122 | |
123 | 123 | if (is_string($accountKeys)) |
124 | 124 | { |
125 | - $accountKeys = $certificateKeysDir.'/'.$accountKeys; |
|
125 | + $accountKeys = $certificateKeysDir . '/' . $accountKeys; |
|
126 | 126 | |
127 | - if(!file_exists($accountKeys)) |
|
127 | + if (!file_exists($accountKeys)) |
|
128 | 128 | { |
129 | 129 | mkdir($accountKeys, 0755, true); |
130 | 130 | LEFunctions::createhtaccess($accountKeys); |
131 | 131 | } |
132 | 132 | |
133 | 133 | $this->accountKeys = array( |
134 | - "private_key" => $accountKeys.'/private.pem', |
|
135 | - "public_key" => $accountKeys.'/public.pem' |
|
134 | + "private_key" => $accountKeys . '/private.pem', |
|
135 | + "public_key" => $accountKeys . '/public.pem' |
|
136 | 136 | ); |
137 | 137 | } |
138 | 138 | elseif (is_array($accountKeys)) |
@@ -155,11 +155,11 @@ discard block |
||
155 | 155 | $this->connector = new LEConnector($this->log, $this->baseURL, $this->accountKeys); |
156 | 156 | $this->account = new LEAccount($this->connector, $this->log, $email, $this->accountKeys); |
157 | 157 | |
158 | - if($this->log instanceof \Psr\Log\LoggerInterface) |
|
158 | + if ($this->log instanceof \Psr\Log\LoggerInterface) |
|
159 | 159 | { |
160 | 160 | $this->log->info('LEClient finished constructing'); |
161 | 161 | } |
162 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('LEClient finished constructing', 'function LEClient __construct'); |
|
162 | + elseif ($this->log >= LEClient::LOG_STATUS) LEFunctions::log('LEClient finished constructing', 'function LEClient __construct'); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 |
@@ -71,17 +71,23 @@ discard block |
||
71 | 71 | |
72 | 72 | if (is_bool($acmeURL)) |
73 | 73 | { |
74 | - if ($acmeURL === true) $this->baseURL = LEClient::LE_STAGING; |
|
75 | - elseif ($acmeURL === false) $this->baseURL = LEClient::LE_PRODUCTION; |
|
76 | - } |
|
77 | - elseif (is_string($acmeURL)) |
|
74 | + if ($acmeURL === true) { |
|
75 | + $this->baseURL = LEClient::LE_STAGING; |
|
76 | + } elseif ($acmeURL === false) { |
|
77 | + $this->baseURL = LEClient::LE_PRODUCTION; |
|
78 | + } |
|
79 | + } elseif (is_string($acmeURL)) |
|
78 | 80 | { |
79 | 81 | $this->baseURL = $acmeURL; |
82 | + } else { |
|
83 | + throw LEClientException::InvalidArgumentException('acmeURL must be set to string or bool (legacy).'); |
|
80 | 84 | } |
81 | - else throw LEClientException::InvalidArgumentException('acmeURL must be set to string or bool (legacy).'); |
|
82 | 85 | |
83 | - if (is_array($certificateKeys) && is_string($accountKeys)) throw LEClientException::InvalidArgumentException('When certificateKeys is array, accountKeys must be array too.'); |
|
84 | - elseif (is_array($accountKeys) && is_string($certificateKeys)) throw LEClientException::InvalidArgumentException('When accountKeys is array, certificateKeys must be array too.'); |
|
86 | + if (is_array($certificateKeys) && is_string($accountKeys)) { |
|
87 | + throw LEClientException::InvalidArgumentException('When certificateKeys is array, accountKeys must be array too.'); |
|
88 | + } elseif (is_array($accountKeys) && is_string($certificateKeys)) { |
|
89 | + throw LEClientException::InvalidArgumentException('When accountKeys is array, certificateKeys must be array too.'); |
|
90 | + } |
|
85 | 91 | |
86 | 92 | if (is_string($certificateKeys)) |
87 | 93 | { |
@@ -100,22 +106,30 @@ discard block |
||
100 | 106 | "fullchain_certificate" => $certificateKeys.'/fullchain.crt', |
101 | 107 | "order" => $certificateKeys.'/order' |
102 | 108 | ); |
103 | - } |
|
104 | - elseif (is_array($certificateKeys)) |
|
109 | + } elseif (is_array($certificateKeys)) |
|
105 | 110 | { |
106 | - if (!isset($certificateKeys['certificate']) && !isset($certificateKeys['fullchain_certificate'])) throw LEClientException::InvalidArgumentException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] file path must be set.'); |
|
107 | - if (!isset($certificateKeys['private_key'])) throw LEClientException::InvalidArgumentException('certificateKeys[private_key] file path must be set.'); |
|
108 | - if (!isset($certificateKeys['order'])) $certificateKeys['order'] = dirname($certificateKeys['private_key']).'/order'; |
|
109 | - if (!isset($certificateKeys['public_key'])) $certificateKeys['public_key'] = dirname($certificateKeys['private_key']).'/public.pem'; |
|
111 | + if (!isset($certificateKeys['certificate']) && !isset($certificateKeys['fullchain_certificate'])) { |
|
112 | + throw LEClientException::InvalidArgumentException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] file path must be set.'); |
|
113 | + } |
|
114 | + if (!isset($certificateKeys['private_key'])) { |
|
115 | + throw LEClientException::InvalidArgumentException('certificateKeys[private_key] file path must be set.'); |
|
116 | + } |
|
117 | + if (!isset($certificateKeys['order'])) { |
|
118 | + $certificateKeys['order'] = dirname($certificateKeys['private_key']).'/order'; |
|
119 | + } |
|
120 | + if (!isset($certificateKeys['public_key'])) { |
|
121 | + $certificateKeys['public_key'] = dirname($certificateKeys['private_key']).'/public.pem'; |
|
122 | + } |
|
110 | 123 | |
111 | 124 | foreach ($certificateKeys as $param => $file) { |
112 | 125 | $parentDir = dirname($file); |
113 | - if (!is_dir($parentDir)) throw LEClientException::InvalidDirectoryException($parentDir); |
|
126 | + if (!is_dir($parentDir)) { |
|
127 | + throw LEClientException::InvalidDirectoryException($parentDir); |
|
128 | + } |
|
114 | 129 | } |
115 | 130 | |
116 | 131 | $this->certificateKeys = $certificateKeys; |
117 | - } |
|
118 | - else |
|
132 | + } else |
|
119 | 133 | { |
120 | 134 | throw LEClientException::InvalidArgumentException('certificateKeys must be string or array.'); |
121 | 135 | } |
@@ -134,20 +148,24 @@ discard block |
||
134 | 148 | "private_key" => $accountKeys.'/private.pem', |
135 | 149 | "public_key" => $accountKeys.'/public.pem' |
136 | 150 | ); |
137 | - } |
|
138 | - elseif (is_array($accountKeys)) |
|
151 | + } elseif (is_array($accountKeys)) |
|
139 | 152 | { |
140 | - if (!isset($accountKeys['private_key'])) throw LEClientException::InvalidArgumentException('accountKeys[private_key] file path must be set.'); |
|
141 | - if (!isset($accountKeys['public_key'])) throw LEClientException::InvalidArgumentException('accountKeys[public_key] file path must be set.'); |
|
153 | + if (!isset($accountKeys['private_key'])) { |
|
154 | + throw LEClientException::InvalidArgumentException('accountKeys[private_key] file path must be set.'); |
|
155 | + } |
|
156 | + if (!isset($accountKeys['public_key'])) { |
|
157 | + throw LEClientException::InvalidArgumentException('accountKeys[public_key] file path must be set.'); |
|
158 | + } |
|
142 | 159 | |
143 | 160 | foreach ($accountKeys as $param => $file) { |
144 | 161 | $parentDir = dirname($file); |
145 | - if (!is_dir($parentDir)) throw LEClientException::InvalidDirectoryException($parentDir); |
|
162 | + if (!is_dir($parentDir)) { |
|
163 | + throw LEClientException::InvalidDirectoryException($parentDir); |
|
164 | + } |
|
146 | 165 | } |
147 | 166 | |
148 | 167 | $this->accountKeys = $accountKeys; |
149 | - } |
|
150 | - else |
|
168 | + } else |
|
151 | 169 | { |
152 | 170 | throw LEClientException::InvalidArgumentException('accountKeys must be string or array.'); |
153 | 171 | } |
@@ -158,8 +176,9 @@ discard block |
||
158 | 176 | if($this->log instanceof \Psr\Log\LoggerInterface) |
159 | 177 | { |
160 | 178 | $this->log->info('LEClient finished constructing'); |
179 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
180 | + LEFunctions::log('LEClient finished constructing', 'function LEClient __construct'); |
|
161 | 181 | } |
162 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('LEClient finished constructing', 'function LEClient __construct'); |
|
163 | 182 | } |
164 | 183 | |
165 | 184 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | // Sets the maximum execution time to two minutes, to be sure. |
3 | 3 | ini_set('max_execution_time', 120); |
4 | 4 | // Including the autoloader. |
5 | -include __DIR__.'/../vendor/autoload.php'; |
|
5 | +include __DIR__ . '/../vendor/autoload.php'; |
|
6 | 6 | |
7 | 7 | // Importing the classes. |
8 | 8 | use LEClient\LEClient; |
@@ -20,14 +20,14 @@ discard block |
||
20 | 20 | // 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. |
21 | 21 | $order = $client->getOrCreateOrder($basename, $domains); |
22 | 22 | // Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations. |
23 | -if(!$order->allAuthorizationsValid()) |
|
23 | +if (!$order->allAuthorizationsValid()) |
|
24 | 24 | { |
25 | 25 | // Get the DNS challenges from the pending authorizations. |
26 | 26 | $pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_DNS); |
27 | 27 | // Walk the list of pending authorization DNS challenges. |
28 | - if(!empty($pending)) |
|
28 | + if (!empty($pending)) |
|
29 | 29 | { |
30 | - foreach($pending as $challenge) |
|
30 | + foreach ($pending as $challenge) |
|
31 | 31 | { |
32 | 32 | // For the purpose of this example, a fictitious functions creates or updates the ACME challenge DNS record for this domain. |
33 | 33 | setDNSRecord($challenge['identifier'], $challenge['DNSDigest']); |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | // Sets the maximum execution time to two minutes, to be sure. |
3 | 3 | ini_set('max_execution_time', 120); |
4 | 4 | // Including the autoloader. |
5 | -include __DIR__.'/../vendor/autoload.php'; |
|
5 | +include __DIR__ . '/../vendor/autoload.php'; |
|
6 | 6 | |
7 | 7 | // Importing the classes. |
8 | 8 | use LEClient\LEClient; |
@@ -20,19 +20,19 @@ discard block |
||
20 | 20 | // 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. |
21 | 21 | $order = $client->getOrCreateOrder($basename, $domains); |
22 | 22 | // Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations. |
23 | -if(!$order->allAuthorizationsValid()) |
|
23 | +if (!$order->allAuthorizationsValid()) |
|
24 | 24 | { |
25 | 25 | // Get the HTTP challenges from the pending authorizations. |
26 | 26 | $pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_HTTP); |
27 | 27 | // Walk the list of pending authorization HTTP challenges. |
28 | - if(!empty($pending)) |
|
28 | + if (!empty($pending)) |
|
29 | 29 | { |
30 | - foreach($pending as $challenge) |
|
30 | + foreach ($pending as $challenge) |
|
31 | 31 | { |
32 | 32 | // Define the folder in which to store the challenge. For the purpose of this example, a fictitious path is set. |
33 | 33 | $folder = '/path/to/' . $challenge['identifier'] . '/.well-known/acme-challenge/'; |
34 | 34 | // Check if that directory yet exists. If not, create it. |
35 | - if(!file_exists($folder)) mkdir($folder, 0777, true); |
|
35 | + if (!file_exists($folder)) mkdir($folder, 0777, true); |
|
36 | 36 | // Store the challenge file for this domain. |
37 | 37 | file_put_contents($folder . $challenge['filename'], $challenge['content']); |
38 | 38 | // Let LetsEncrypt verify this challenge. |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | } |
42 | 42 | } |
43 | 43 | // Check once more whether all authorizations are valid before we can finalize the order. |
44 | -if($order->allAuthorizationsValid()) |
|
44 | +if ($order->allAuthorizationsValid()) |
|
45 | 45 | { |
46 | 46 | // Finalize the order first, if that is not yet done. |
47 | - if(!$order->isFinalized()) $order->finalizeOrder(); |
|
47 | + if (!$order->isFinalized()) $order->finalizeOrder(); |
|
48 | 48 | // Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate. |
49 | - if($order->isFinalized()) $order->getCertificate(); |
|
49 | + if ($order->isFinalized()) $order->getCertificate(); |
|
50 | 50 | } |
51 | 51 | ?> |
52 | 52 | \ No newline at end of file |
@@ -28,7 +28,9 @@ discard block |
||
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)) { |
|
32 | + mkdir($folder, 0777, true); |
|
33 | + } |
|
32 | 34 | // Store the challenge file for this domain. |
33 | 35 | file_put_contents($folder . $challenge['filename'], $challenge['content']); |
34 | 36 | // Let LetsEncrypt verify this challenge. |
@@ -40,8 +42,12 @@ discard block |
||
40 | 42 | if($order->allAuthorizationsValid()) |
41 | 43 | { |
42 | 44 | // Finalize the order first, if that is not yet done. |
43 | - if(!$order->isFinalized()) $order->finalizeOrder(); |
|
45 | + if(!$order->isFinalized()) { |
|
46 | + $order->finalizeOrder(); |
|
47 | + } |
|
44 | 48 | // Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate. |
45 | - if($order->isFinalized()) $order->getCertificate(); |
|
46 | -} |
|
49 | + if($order->isFinalized()) { |
|
50 | + $order->getCertificate(); |
|
51 | + } |
|
52 | + } |
|
47 | 53 | ?> |
48 | 54 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | // Sets the maximum execution time to two minutes, to be sure. |
3 | 3 | ini_set('max_execution_time', 120); |
4 | 4 | // Including the autoloader. |
5 | -include __DIR__.'/../vendor/autoload.php'; |
|
5 | +include __DIR__ . '/../vendor/autoload.php'; |
|
6 | 6 | |
7 | 7 | // Importing the classes. |
8 | 8 | use LEClient\LEClient; |
@@ -20,14 +20,14 @@ discard block |
||
20 | 20 | // 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. |
21 | 21 | $order = $client->getOrCreateOrder($basename, $domains); |
22 | 22 | // Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations. |
23 | -if(!$order->allAuthorizationsValid()) |
|
23 | +if (!$order->allAuthorizationsValid()) |
|
24 | 24 | { |
25 | 25 | // Get the DNS challenges from the pending authorizations. |
26 | 26 | $pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_DNS); |
27 | 27 | // Walk the list of pending authorization DNS challenges. |
28 | - if(!empty($pending)) |
|
28 | + if (!empty($pending)) |
|
29 | 29 | { |
30 | - foreach($pending as $challenge) |
|
30 | + foreach ($pending as $challenge) |
|
31 | 31 | { |
32 | 32 | // Let LetsEncrypt verify this challenge, which should have been fulfilled in exampleDNSStart.php. |
33 | 33 | $order->verifyPendingOrderAuthorization($challenge['identifier'], LEOrder::CHALLENGE_TYPE_DNS); |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | } |
36 | 36 | } |
37 | 37 | // Check once more whether all authorizations are valid before we can finalize the order. |
38 | -if($order->allAuthorizationsValid()) |
|
38 | +if ($order->allAuthorizationsValid()) |
|
39 | 39 | { |
40 | 40 | // Finalize the order first, if that is not yet done. |
41 | - if(!$order->isFinalized()) $order->finalizeOrder(); |
|
41 | + if (!$order->isFinalized()) $order->finalizeOrder(); |
|
42 | 42 | // Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate. |
43 | - if($order->isFinalized()) $order->getCertificate(); |
|
43 | + if ($order->isFinalized()) $order->getCertificate(); |
|
44 | 44 | } |
45 | 45 | ?> |
46 | 46 | \ No newline at end of file |
@@ -34,8 +34,12 @@ |
||
34 | 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()) { |
|
38 | + $order->finalizeOrder(); |
|
39 | + } |
|
38 | 40 | // Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate. |
39 | - if($order->isFinalized()) $order->getCertificate(); |
|
40 | -} |
|
41 | + if($order->isFinalized()) { |
|
42 | + $order->getCertificate(); |
|
43 | + } |
|
44 | + } |
|
41 | 45 | ?> |
42 | 46 | \ No newline at end of file |