yourivw / LEClient

An easy-to-use PHP ACME v2 client library, designed to be used with LetsEncrypt.
MIT License
204 stars 98 forks source link

Error retrieving pending authorizations #112

Closed milesizzo closed 3 years ago

milesizzo commented 3 years ago

I'm not sure if I'm doing this incorrectly, but I'll outline what I'm seeing.

I'm calling LEOrder::getPendingAuthorizations on an order with a wildcard domain (eg. *.example.com), and a bunch of subdomains (eg. mysite.mydomain.com). I collect all authorizations in the following way:

try {
    $httpAuthorizations = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_HTTP) ?: [];
} catch (Exception $e) {
    $httpAuthorizations = [];
}
try {
    $dnsAuthorizations = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_DNS) ?: [];
} catch (Exception $e) {
    $dnsAuthorizations = [];
}

$authorizations = array_merge($httpAuthorizations, $dnsAuthorizations);

This is so I can process http-01 challenges before falling back to dns-01 challenges (eg. for wildcard domains).

However, when I call $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_HTTP), I get an exception because the first authorization doesn't contain an http-01 challenge. I would have expected it to continue and find http-01 challenges in other authorizations.

As far as I can tell, this could be fixed by adding an exception handler in LEOrder.php on line 346:

try {
    $challenge = $auth->getChallenge($type);
} catch (LEAuthorizationException $e) {
    continue;
}

Is this something I can submit a PR for, or am I not using it as intended?