Beispiel #1
0
 /**
  * {@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;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function supports(AuthorizationChallenge $authorizationChallenge)
 {
     return 'dns-01' === $authorizationChallenge->getType();
 }
Beispiel #3
0
 /**
  * @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);
 }
Beispiel #4
0
 /**
  * Retrieves the content that should be returned in the response.
  *
  * @param AuthorizationChallenge $authorizationChallenge
  *
  * @return string
  */
 public function getCheckContent(AuthorizationChallenge $authorizationChallenge)
 {
     return $authorizationChallenge->getPayload();
 }
Beispiel #5
0
 /**
  * Retrieves the value of the TXT record to register.
  *
  * @param AuthorizationChallenge $authorizationChallenge
  *
  * @return string
  */
 public function getRecordValue(AuthorizationChallenge $authorizationChallenge)
 {
     return $this->encoder->encode(hash('sha256', $authorizationChallenge->getPayload(), true));
 }