add support for DNS validation

- new constant Client::VALIDATION_DNS
- added Authorization::getDnsChallenge to get the challenge
- added Authorization::getTxtRecord to get the TXT record value
- added Helper::waitForDNS to provide an easy way to wait for changes
- updated documentation to illustrate DNS validation
This commit is contained in:
Paul Dixon
2020-03-17 18:27:27 +00:00
parent 4c7b6b8e60
commit c2532e0dab
4 changed files with 111 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
namespace Afosto\Acme\Data;
use Afosto\Acme\Client;
use Afosto\Acme\Helper;
class Authorization
{
@@ -78,6 +79,20 @@ class Authorization
return false;
}
/**
* @return Challenge|bool
*/
public function getDnsChallenge()
{
foreach ($this->getChallenges() as $challenge) {
if ($challenge->getType() == Client::VALIDATION_DNS) {
return $challenge;
}
}
return false;
}
/**
* @param Challenge $challenge
* @return File|bool
@@ -90,4 +105,15 @@ class Authorization
}
return false;
}
/**
* @param Challenge $challenge
* @return string containing TXT record for DNS challenge
*/
public function getTxtRecord(Challenge $challenge)
{
$raw=$challenge->getToken() . '.' . $this->digest;
$hash=hash('sha256', $raw, true);
return Helper::toSafeString($hash);
}
}