Skip to content
This repository was archived by the owner on Mar 17, 2024. It is now read-only.

Commit 0adfcdb

Browse files
committed
Version 1.2.2
- Change in LEOrder order status logic, to fix #87. Compliant with RFC8555 (https://tools.ietf.org/html/rfc8555#section-7.1.6) - LEException getResponseData() return type hinting removed for PHP 5 support.
1 parent 7c54c2b commit 0adfcdb

3 files changed

Lines changed: 36 additions & 24 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PHP LetsEncrypt client library for ACME v2. The aim of this client is to make an
33

44
## Current version
55

6-
The current version is 1.2.1
6+
The current version is 1.2.2
77

88
## Getting Started
99

src/Exceptions/LEException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(string $message = "", int $code = 0, Throwable $prev
4545
$this->responsedata = $responsedata;
4646
}
4747

48-
public function getResponseData(): ?array
48+
public function getResponseData()
4949
{
5050
return $this->responsedata;
5151
}

src/LEOrder.php

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,8 @@ public function generateCSR()
570570
*/
571571
public function finalizeOrder($csr = '')
572572
{
573-
if($this->status == 'pending' || $this->status == 'ready')
573+
$this->updateOrderData();
574+
if($this->status == 'ready')
574575
{
575576
if($this->allAuthorizationsValid())
576577
{
@@ -623,7 +624,7 @@ public function finalizeOrder($csr = '')
623624
*/
624625
public function isFinalized()
625626
{
626-
return ($this->status == 'processing' || $this->status == 'valid' || $this->status == 'ready');
627+
return ($this->status == 'processing' || $this->status == 'valid');
627628
}
628629

629630
/**
@@ -646,48 +647,59 @@ public function getCertificate()
646647
$this->updateOrderData();
647648
$polling++;
648649
}
649-
if(($this->status == 'valid' || $this->status == 'ready') && !empty($this->certificateURL))
650+
if($this->status == 'valid')
650651
{
651-
$sign = $this->connector->signRequestKid('', $this->connector->accountURL, $this->certificateURL);
652-
$post = $this->connector->post($this->certificateURL, $sign);
653-
if($post['status'] === 200)
652+
if(!empty($this->certificateURL))
654653
{
655-
if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $post['body'], $matches))
654+
$sign = $this->connector->signRequestKid('', $this->connector->accountURL, $this->certificateURL);
655+
$post = $this->connector->post($this->certificateURL, $sign);
656+
if($post['status'] === 200)
656657
{
657-
if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'], $matches[0][0]);
658-
659-
if(count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate']))
658+
if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $post['body'], $matches))
660659
{
661-
$fullchain = $matches[0][0]."\n";
662-
for($i=1;$i<count($matches[0]);$i++)
660+
if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'], $matches[0][0]);
661+
662+
if(count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate']))
663+
{
664+
$fullchain = $matches[0][0]."\n";
665+
for($i=1;$i<count($matches[0]);$i++)
666+
{
667+
$fullchain .= $matches[0][$i]."\n";
668+
}
669+
file_put_contents(trim($this->certificateKeys['fullchain_certificate']), $fullchain);
670+
}
671+
if($this->log instanceof \Psr\Log\LoggerInterface)
663672
{
664-
$fullchain .= $matches[0][$i]."\n";
673+
$this->log->info('Certificate for \'' . $this->basename . '\' saved');
665674
}
666-
file_put_contents(trim($this->certificateKeys['fullchain_certificate']), $fullchain);
675+
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
676+
return true;
667677
}
668-
if($this->log instanceof \Psr\Log\LoggerInterface)
678+
else
669679
{
670-
$this->log->info('Certificate for \'' . $this->basename . '\' saved');
680+
if($this->log instanceof \Psr\Log\LoggerInterface)
681+
{
682+
$this->log->info('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.');
683+
}
684+
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
671685
}
672-
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
673-
return true;
674686
}
675687
else
676688
{
677689
if($this->log instanceof \Psr\Log\LoggerInterface)
678690
{
679-
$this->log->info('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.');
691+
$this->log->info('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.');
680692
}
681-
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Received invalid certificate 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');
682694
}
683695
}
684696
else
685697
{
686698
if($this->log instanceof \Psr\Log\LoggerInterface)
687699
{
688-
$this->log->info('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.');
700+
$this->log->info('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.');
689701
}
690-
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
702+
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.', 'function getCertificate');
691703
}
692704
}
693705
else

0 commit comments

Comments
 (0)