/** * Retrieves the absolute URL called by the CA. * * @param AuthorizationChallenge $authorizationChallenge * * @return string */ public function getCheckUrl(AuthorizationChallenge $authorizationChallenge) { return sprintf('http://%s/.well-known/acme-challenge/%s', $authorizationChallenge->getDomain(), $authorizationChallenge->getToken()); }
/** * {@inheritdoc} */ public function challengeAuthorization(AuthorizationChallenge $challenge, $timeout = 180) { Assert::integer($timeout, 'challengeAuthorization::$timeout expected an integer. Got: %s'); $payload = ['resource' => ResourcesDirectory::CHALLENGE, 'type' => $challenge->getType(), 'keyAuthorization' => $challenge->getPayload(), 'token' => $challenge->getToken()]; if (!$this->directory) { $this->initializeDirectory(); } $response = (array) $this->httpClient->signedRequest('POST', $challenge->getUrl(), $payload); // Waiting loop $endTime = time() + $timeout; while (time() <= $endTime && (!isset($response['status']) || 'pending' === $response['status'])) { sleep(1); $response = (array) $this->httpClient->signedRequest('GET', $challenge->getUrl()); } if (!isset($response['status']) || 'valid' !== $response['status']) { throw new ChallengeFailedException($response); } elseif ('pending' === $response['status']) { throw new ChallengeTimedOutException($response); } return $response; }
/** * @param AuthorizationChallenge $challenge * * @return Process */ private function createServerProcess(AuthorizationChallenge $challenge) { $listen = '0.0.0.0:5002'; $documentRoot = __DIR__ . '/Fixtures/challenges'; // Create file file_put_contents($documentRoot . '/.well-known/acme-challenge/' . $challenge->getToken(), $challenge->getPayload()); // Start server $finder = new PhpExecutableFinder(); if (false === ($binary = $finder->find())) { throw new \RuntimeException('Unable to find PHP binary to start server.'); } $script = implode(' ', array_map(['Symfony\\Component\\Process\\ProcessUtils', 'escapeArgument'], [$binary, '-S', $listen, '-t', $documentRoot])); return new Process('exec ' . $script, $documentRoot, null, null, null); }