Skip to content

Commit

Permalink
Merge pull request #46 from futureweb/patch-6
Browse files Browse the repository at this point in the history
enhance ACME protocol compatibility (User-Agent Header)
  • Loading branch information
analogic authored Apr 11, 2023
2 parents 3e27ae0 + bcb74f8 commit 42f9d3e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Lescript.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Lescript
public $contact = array(); // optional
// public $contact = array("mailto:cert-admin@example.com", "tel:+12025551212")

public $clientUserAgent = "analogic-lescript/0.3.0";

protected $certificatesDir;
protected $webRootDir;

Expand All @@ -34,7 +36,7 @@ public function __construct($certificatesDir, $webRootDir, $logger = null, Clien
$this->certificatesDir = $certificatesDir;
$this->webRootDir = $webRootDir;
$this->logger = $logger;
$this->client = $client ? $client : new Client($this->ca);
$this->client = $client ? $client : new Client($this->ca, $this->clientUserAgent);
$this->accountKeyPath = $certificatesDir . '/_account/private.pem';
}

Expand Down Expand Up @@ -65,6 +67,7 @@ public function initAccount()

public function initCommunication()
{
$this->log('ACME Client: '.$this->clientUserAgent);
$this->log('Getting list of URLs for API');

$directory = $this->client->get('/directory');
Expand Down Expand Up @@ -461,8 +464,9 @@ interface ClientInterface
* Constructor
*
* @param string $base the ACME API base all relative requests are sent to
* @param string $userAgent ACME Client User-Agent
*/
public function __construct($base);
public function __construct($base, $userAgent);

/**
* Send a POST request
Expand Down Expand Up @@ -519,10 +523,12 @@ class Client implements ClientInterface
protected $lastHeader;

protected $base;
protected $userAgent;

public function __construct($base)
public function __construct($base, $userAgent)
{
$this->base = $base;
$this->userAgent = $userAgent;
}

protected function curl($method, $url, $data = null)
Expand All @@ -533,6 +539,7 @@ protected function curl($method, $url, $data = null)
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_HEADER, true);
curl_setopt($handle, CURLOPT_USERAGENT, $this->userAgent);

// DO NOT DO THAT!
// curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
Expand Down

0 comments on commit 42f9d3e

Please sign in to comment.