Kelunik\Acme\Verifiers\Dns01::doVerifyChallenge PHP Method

doVerifyChallenge() private method

Can be used to verify a challenge before requesting validation from a CA to catch errors early.
private doVerifyChallenge ( string $domain, string $expectedPayload ) : Generator
$domain string domain to verify
$expectedPayload string expected DNS record value
return Generator coroutine resolved to the DNS entry found
    private function doVerifyChallenge($domain, $expectedPayload)
    {
        if (!is_string($domain)) {
            throw new InvalidArgumentException(sprintf("\$domain must be of type string, %s given.", gettype($domain)));
        }
        if (!is_string($expectedPayload)) {
            throw new InvalidArgumentException(sprintf("\$expectedPayload must be of type string, %s given.", gettype($expectedPayload)));
        }
        $uri = "_acme-challenge." . $domain;
        try {
            $dnsResponse = (yield $this->resolver->query($uri, ["types" => Record::TXT]));
        } catch (NoRecordException $e) {
            throw new AcmeException("Verification failed, no TXT record found for '{$uri}'.", 0, $e);
        } catch (ResolutionException $e) {
            throw new AcmeException("Verification failed, couldn't query TXT record of '{$uri}': " . $e->getMessage(), 0, $e);
        }
        list($record) = $dnsResponse;
        list($payload) = $record;
        if ($payload !== $expectedPayload) {
            throw new AcmeException("Verification failed, please check DNS record under '{$uri}'. Expected: '{$expectedPayload}', Got: '{$payload}'.");
        }
        (yield new CoroutineResult($dnsResponse));
        return;
    }