diff --git a/composer.json b/composer.json index 4cd2d69..1f9b98f 100755 --- a/composer.json +++ b/composer.json @@ -32,5 +32,11 @@ "laravel/pint": "1.2.*", "phpstan/phpstan": "1.8.*", "rregeer/phpunit-coverage-check": "^0.3.1" + }, + "config": { + "allow-plugins": { + "php-http/discovery": true, + "tbachert/spi": true + } } } diff --git a/src/DNS/Client.php b/src/DNS/Client.php index e17c340..8784d3f 100644 --- a/src/DNS/Client.php +++ b/src/DNS/Client.php @@ -36,6 +36,7 @@ class Client 'TXT' => 16, 'AAAA' => 28, 'SRV' => 33, + 'CAA' => 257, ]; public function __construct(string $server = '127.0.0.1', int $port = 53, int $timeout = 5) @@ -241,6 +242,17 @@ private function parseRdata(string $packet, int &$offset, int $type, int $rdleng $offset += 6; $target = $this->decodeDomainName($packet, $offset); return "Priority: {$priority[1]}, Weight: {$weight[1]}, Port: {$port[1]}, Target: {$target}"; + case 257: // CAA record + if ($rdlength < 2) { + throw new Exception("CAA record too short (rdlength={$rdlength})"); + } + $flags = ord($packet[$offset++]); + $tagLength = ord($packet[$offset++]); + $tag = substr($packet, $offset, $tagLength); + $offset += $tagLength; + $value = substr($packet, $offset, $rdlength - 2 - $tagLength); + $offset += $rdlength - 2 - $tagLength; + return "{$flags} {$tag} \"{$value}\""; case 6: // SOA record $mname = $this->decodeDomainName($packet, $offset); $rname = $this->decodeDomainName($packet, $offset); diff --git a/tests/DNS/ClientTest.php b/tests/DNS/ClientTest.php index c18b786..93feab8 100644 --- a/tests/DNS/ClientTest.php +++ b/tests/DNS/ClientTest.php @@ -135,4 +135,29 @@ public function testNSRecords(): void $records = $this->client->query('dev3.appwrite.io', 'NS'); $this->assertCount(0, $records); } + + public function testCAARecords(): void + { + $records = $this->client->query('dev.appwrite.io', 'CAA'); + + $this->assertCount(1, $records); + $this->assertEquals('dev.appwrite.io', $records[0]->getName()); + $this->assertEquals('IN', $records[0]->getClass()); + $this->assertIsNumeric($records[0]->getTTL()); + $this->assertEquals('CAA', $records[0]->getTypeName()); + + $rdata = $records[0]->getRdata(); + $this->assertEquals('0 issue "letsencrypt.org"', $rdata); + + $records = $this->client->query('dev2.appwrite.io', 'CAA'); + + $this->assertCount(2, $records); + $this->assertEquals('0 issue "letsencrypt.org"', $records[0]->getRdata()); + $this->assertEquals('0 issue "sectigo.com"', $records[1]->getRdata()); + + $records = $this->client->query('dev3.appwrite.io', 'CAA'); + + $this->assertCount(1, $records); + $this->assertEquals('255 issuewild "certainly.com;validationmethods=tls-alpn-01;retrytimeout=3600"', $records[0]->getRdata()); + } } diff --git a/tests/DNS/ServerMemory.php b/tests/DNS/ServerMemory.php index 5a747cc..f605324 100644 --- a/tests/DNS/ServerMemory.php +++ b/tests/DNS/ServerMemory.php @@ -77,6 +77,10 @@ 'value' => 'issue "sectigo.com"' ]); +$resolver->addRecord('dev3.appwrite.io', 'CAA', [ + 'value' => '255 issuewild "certainly.com;validationmethods=tls-alpn-01;retrytimeout=3600"' +]); + $resolver->addRecord('dev.appwrite.io', 'NS', [ 'value' => 'ns.appwrite.io', 'ttl' => 60