feat: add RDAP response dto

This commit is contained in:
Maël Gangloff 2025-11-08 17:34:29 +01:00
parent d769c48955
commit b777683c50
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
14 changed files with 325 additions and 0 deletions

View File

@ -0,0 +1,52 @@
<?php
namespace App\Entity\RdapResponse;
use App\Config\EventAction;
use App\Entity\DomainEntity;
use App\Entity\DomainEvent;
class Domain
{
public string $objectClassName = 'domain';
public ?string $handle;
public string $ldhName;
/**
* @var string[]
*/
public ?array $status;
/**
* @var Event[]
*/
public ?array $events;
/**
* @var Entity[]
*/
public ?array $entities;
/**
* @var Nameserver[]
*/
public ?array $nameservers;
public ?SecureDNS $secureDNS;
/**
* @throws \Exception
*/
public function __construct(\App\Entity\Domain $d)
{
$this->handle = $d->getHandle();
$this->ldhName = $d->getLdhName();
$this->status = $d->getStatus();
$events = $d->getEvents()->toArray();
usort($events, fn (DomainEvent $d1, DomainEvent $d2) => $d1->getDate()->getTimestamp() - $d2->getDate()->getTimestamp());
$this->events = [
...array_map(fn (DomainEvent $de) => Event::fromEvent($de), $events),
new Event($d->getUpdatedAt()->format(\DateTimeInterface::ATOM), EventAction::LastUpdateOfRDAPDatabase->value),
];
$this->entities = array_map(fn (DomainEntity $de) => Entity::fromDomainEntity($de), $d->getDomainEntities()->toArray());
$this->nameservers = array_map(fn (\App\Entity\Nameserver $ns) => Nameserver::fromNameserver($ns), $d->getNameservers()->toArray());
$this->secureDNS = SecureDNS::fromDomain($d);
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Entity\RdapResponse;
class DomainRdapResponse extends Domain
{
use RdapResponseTrait;
public function __construct(\App\Entity\Domain $d)
{
parent::__construct($d);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity\RdapResponse;
use App\Entity\DnsKey;
class DsData
{
public int $keyTag;
public int $algorithm;
public string $digest;
public int $digestType;
public static function fromDnsKey(DnsKey $dnsKey): self
{
$d = new DsData();
$d->algorithm = $dnsKey->getAlgorithm()->value;
$d->keyTag = (int) $dnsKey->getKeyTag();
$d->digest = $dnsKey->getDigest();
$d->digestType = $dnsKey->getDigestType()->value;
return $d;
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace App\Entity\RdapResponse;
use App\Config\DomainRole;
use App\Entity\DomainEntity;
use App\Entity\EntityEvent;
class Entity
{
public string $objectClassName = 'entity';
public ?string $handle;
/**
* @var PublicId[]
*/
public ?array $publicIds;
/**
* @var Event[]
*/
public ?array $events;
/**
* @var Link[]
*/
public array $vcardArray;
/**
* @var DomainRole[]
*/
public array $roles;
public ?array $remarks;
public function __construct(\App\Entity\Entity $e)
{
if (!str_starts_with($e->getHandle(), 'DW-FAKEHANDLE')) {
$this->handle = $e->getHandle();
}
if ($e->getIcannAccreditation()) {
$this->publicIds = [new PublicId('IANA Registrar ID', (string) $e->getIcannAccreditation()->getId())];
}
$this->vcardArray = $e->getJCard();
$this->remarks = $e->getRemarks();
}
public static function fromDomainEntity(DomainEntity $de): self
{
$e = new Entity($de->getEntity());
$e->events = array_map(fn (EntityEvent $ee) => Event::fromEvent($ee), $de->getEntity()->getEvents()->toArray());
$e->roles = $de->getRoles();
return $e;
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Entity\RdapResponse;
class EntityRdapResponse extends Entity
{
use RdapResponseTrait;
public function __construct(\App\Entity\Entity $e)
{
parent::__construct($e);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Entity\RdapResponse;
class Event
{
public function __construct(
public string $eventDate,
public string $eventAction,
) {
}
public static function fromEvent(\App\Entity\Event $event): self
{
return new Event($event->getDate()->format(\DateTimeInterface::ATOM), $event->getAction());
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Entity\RdapResponse;
class Link
{
public string $href;
public string $value;
public string $rel;
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Entity\RdapResponse;
class Nameserver
{
public string $objectClassName = 'nameserver';
public function __construct(
public string $ldhName,
) {
}
public static function fromNameserver(\App\Entity\Nameserver $ns): self
{
return new Nameserver($ns->getLdhName());
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Entity\RdapResponse;
class NameserverRdapResponse extends Nameserver
{
use RdapResponseTrait;
public function __construct(\App\Entity\Nameserver $ns)
{
parent::__construct($ns->getLdhName());
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Entity\RdapResponse;
class Notice
{
public function __construct(
public string $title,
/**
* @var string[]
*/
public array $description,
/**
* @var Link[]
*/
public array $links,
) {
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Entity\RdapResponse;
class PublicId
{
public function __construct(
public string $type,
public string $identifier)
{
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Entity\RdapResponse;
trait RdapResponseTrait
{
public array $rdapConformance = [
'rdap_level_0',
'icann_rdap_technical_implementation_guide_1',
'icann_rdap_response_profile_1',
];
/**
* @var Link[]
*/
public array $links;
/**
* @var Notice[]
*/
public array $notices;
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Entity\RdapResponse;
use App\Entity\DnsKey;
class SecureDNS
{
public bool $delegationSigned;
/**
* @var DsData[]
*/
public ?array $dsData = null;
/**
* @throws \Exception
*/
public static function fromDomain(\App\Entity\Domain $d): self
{
$s = new SecureDNS();
$s->delegationSigned = $d->isDelegationSigned();
if ($s->delegationSigned) {
$s->dsData = array_map(fn (DnsKey $dnsKey) => DsData::fromDnsKey($dnsKey), $d->getDnsKey()->toArray());
}
return $s;
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Entity\Domain;
use App\Entity\RdapResponse\DomainRdapResponse;
use App\Repository\DomainRepository;
use App\Service\RDAPService;
readonly class DomainRdapResponseProvider implements ProviderInterface
{
public function __construct(
private DomainRepository $domainRepository,
private AutoRegisterDomainProvider $autoRegisterDomainProvider,
) {
}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
$this->autoRegisterDomainProvider->provide($operation, $uriVariables, $context);
$idnDomain = RDAPService::convertToIdn($uriVariables['ldhName']);
/** @var Domain $domain */
$domain = $this->domainRepository->findOneBy(['ldhName' => $idnDomain]);
return new DomainRdapResponse($domain);
}
}