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

Commit

Permalink
Version 1.2.2
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
yourivw committed Apr 15, 2020
1 parent 7c54c2b commit 0adfcdb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PHP LetsEncrypt client library for ACME v2. The aim of this client is to make an

## Current version

The current version is 1.2.1
The current version is 1.2.2

## Getting Started

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/LEException.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(string $message = "", int $code = 0, Throwable $prev
$this->responsedata = $responsedata;
}

public function getResponseData(): ?array
public function getResponseData()
{
return $this->responsedata;
}
Expand Down
56 changes: 34 additions & 22 deletions src/LEOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ public function generateCSR()
*/
public function finalizeOrder($csr = '')
{
if($this->status == 'pending' || $this->status == 'ready')
$this->updateOrderData();
if($this->status == 'ready')
{
if($this->allAuthorizationsValid())
{
Expand Down Expand Up @@ -623,7 +624,7 @@ public function finalizeOrder($csr = '')
*/
public function isFinalized()
{
return ($this->status == 'processing' || $this->status == 'valid' || $this->status == 'ready');
return ($this->status == 'processing' || $this->status == 'valid');
}

/**
Expand All @@ -646,48 +647,59 @@ public function getCertificate()
$this->updateOrderData();
$polling++;
}
if(($this->status == 'valid' || $this->status == 'ready') && !empty($this->certificateURL))
if($this->status == 'valid')
{
$sign = $this->connector->signRequestKid('', $this->connector->accountURL, $this->certificateURL);
$post = $this->connector->post($this->certificateURL, $sign);
if($post['status'] === 200)
if(!empty($this->certificateURL))
{
if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $post['body'], $matches))
$sign = $this->connector->signRequestKid('', $this->connector->accountURL, $this->certificateURL);
$post = $this->connector->post($this->certificateURL, $sign);
if($post['status'] === 200)
{
if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'], $matches[0][0]);

if(count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate']))
if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $post['body'], $matches))
{
$fullchain = $matches[0][0]."\n";
for($i=1;$i<count($matches[0]);$i++)
if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'], $matches[0][0]);

if(count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate']))
{
$fullchain = $matches[0][0]."\n";
for($i=1;$i<count($matches[0]);$i++)
{
$fullchain .= $matches[0][$i]."\n";
}
file_put_contents(trim($this->certificateKeys['fullchain_certificate']), $fullchain);
}
if($this->log instanceof \Psr\Log\LoggerInterface)
{
$fullchain .= $matches[0][$i]."\n";
$this->log->info('Certificate for \'' . $this->basename . '\' saved');
}
file_put_contents(trim($this->certificateKeys['fullchain_certificate']), $fullchain);
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
return true;
}
if($this->log instanceof \Psr\Log\LoggerInterface)
else
{
$this->log->info('Certificate for \'' . $this->basename . '\' saved');
if($this->log instanceof \Psr\Log\LoggerInterface)
{
$this->log->info('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.');
}
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
}
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
return true;
}
else
{
if($this->log instanceof \Psr\Log\LoggerInterface)
{
$this->log->info('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.');
$this->log->info('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.');
}
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
}
}
else
{
if($this->log instanceof \Psr\Log\LoggerInterface)
{
$this->log->info('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.');
$this->log->info('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.');
}
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.', 'function getCertificate');
}
}
else
Expand Down

0 comments on commit 0adfcdb

Please sign in to comment.