1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LE_ACME2\Authorizer; |
4
|
|
|
|
5
|
|
|
use LE_ACME2\Request; |
6
|
|
|
use LE_ACME2\Response; |
7
|
|
|
use LE_ACME2\Exception; |
8
|
|
|
|
9
|
|
|
use LE_ACME2\Order; |
10
|
|
|
use LE_ACME2\Struct\ChallengeAuthorizationKey; |
11
|
|
|
use LE_ACME2\Utilities; |
12
|
|
|
|
13
|
|
|
class DNS extends AbstractAuthorizer { |
14
|
|
|
|
15
|
|
|
protected function _getChallengeType(): string { |
16
|
|
|
return Order::CHALLENGE_TYPE_DNS; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** @var AbstractDNSWriter $_dnsWriter */ |
20
|
|
|
private static $_dnsWriter = null; |
21
|
|
|
|
22
|
|
|
public static function setWriter(AbstractDNSWriter $dnsWriter) : void { |
23
|
|
|
self::$_dnsWriter = $dnsWriter; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @throws Exception\AuthorizationInvalid |
28
|
|
|
* @throws Exception\DNSAuthorizationInvalid |
29
|
|
|
* @throws Exception\ExpiredAuthorization |
30
|
|
|
* @throws Exception\InvalidResponse |
31
|
|
|
* @throws Exception\RateLimitReached |
32
|
|
|
* @throws Exception\ServiceUnavailable |
33
|
|
|
*/ |
34
|
|
|
protected function _existsNotValidChallenges(Response\Authorization\Struct\Challenge $challenge, |
35
|
|
|
Response\Authorization\Get $authorizationResponse |
36
|
|
|
) : bool { |
37
|
|
|
|
38
|
|
|
if($challenge->status == Response\Authorization\Struct\Challenge::STATUS_PENDING) { |
39
|
|
|
|
40
|
|
|
if(self::$_dnsWriter === null) { |
41
|
|
|
throw new \RuntimeException('DNS writer is not set'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if( self::$_dnsWriter->write( |
45
|
|
|
$this->_order, |
46
|
|
|
$authorizationResponse->getIdentifier()->value, |
47
|
|
|
(new ChallengeAuthorizationKey($this->_account))->getEncoded($challenge->token) |
48
|
|
|
) |
49
|
|
|
) { |
50
|
|
|
$request = new Request\Authorization\Start($this->_account, $this->_order, $challenge); |
51
|
|
|
/* $response = */ $request->getResponse(); |
52
|
|
|
} else { |
53
|
|
|
|
54
|
|
|
Utilities\Logger::getInstance()->add(Utilities\Logger::LEVEL_INFO, 'Pending challenge deferred'); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if($challenge->status == Response\Authorization\Struct\Challenge::STATUS_INVALID) { |
59
|
|
|
throw new Exception\DNSAuthorizationInvalid( |
60
|
|
|
'Received status "' . Response\Authorization\Struct\Challenge::STATUS_INVALID . '" while challenge should be verified' |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return parent::_existsNotValidChallenges($challenge, $authorizationResponse); |
65
|
|
|
} |
66
|
|
|
} |