Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s

- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3)
- Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung
- Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü
- Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person
- Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“
- Benutzerverwaltung im Admin, Zugang vorläufig über is_admin
- vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/
- PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung
- VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-25 20:35:30 +00:00
parent 7197eaebf2
commit 9c0f8de791
15771 changed files with 1564103 additions and 5 deletions

View file

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService;
use Psr\Log\LoggerInterface;
interface CanLogData
{
public function setLogger(LoggerInterface $logger): void;
}

View file

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\CertificateChain;
interface CertificateChainValidator
{
/**
* @param string[] $untrustedCertificates
* @param string[] $trustedCertificates
*/
public function check(array $untrustedCertificates, array $trustedCertificates): void;
}

View file

@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\CertificateChain;
use const PHP_EOL;
final readonly class CertificateToolbox
{
private const PEM_HEADER = '-----BEGIN ';
private const PEM_FOOTER = '-----END ';
/**
* @param string[] $data
*
* @return string[]
*/
public static function fixPEMStructures(array $data, string $type = 'CERTIFICATE'): array
{
return array_map(static fn ($d): string => self::fixPEMStructure($d, $type), $data);
}
public static function fixPEMStructure(string $data, string $type = 'CERTIFICATE'): string
{
if (str_contains($data, self::PEM_HEADER)) {
return trim($data);
}
$pem = self::PEM_HEADER . $type . '-----' . PHP_EOL;
$pem .= chunk_split($data, 64, PHP_EOL);
return $pem . (self::PEM_FOOTER . $type . '-----' . PHP_EOL);
}
public static function convertDERToPEM(string $data, string $type = 'CERTIFICATE'): string
{
if (str_contains($data, self::PEM_HEADER)) {
return $data;
}
return self::fixPEMStructure(base64_encode($data), $type);
}
/**
* @param string[] $data
*
* @return string[]
*/
public static function convertAllDERToPEM(array $data, string $type = 'CERTIFICATE'): array
{
return array_map(static fn ($d): string => self::convertDERToPEM($d, $type), $data);
}
}

View file

@ -0,0 +1,262 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\CertificateChain;
use function count;
use function in_array;
use function parse_url;
use const PHP_EOL;
use const PHP_URL_SCHEME;
use Psr\Clock\ClockInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType;
use SpomkyLabs\Pki\CryptoEncoding\PEM;
use SpomkyLabs\Pki\X509\Certificate\Certificate;
use SpomkyLabs\Pki\X509\CertificationPath\CertificationPath;
use SpomkyLabs\Pki\X509\CertificationPath\PathValidation\PathValidationConfig;
use function sprintf;
use Symfony\Component\Clock\NativeClock;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Throwable;
use Webauthn\Event\BeforeCertificateChainValidation;
use Webauthn\Event\CanDispatchEvents;
use Webauthn\Event\CertificateChainValidationFailed;
use Webauthn\Event\CertificateChainValidationSucceeded;
use Webauthn\Event\NullEventDispatcher;
use Webauthn\Exception\CertificateChainException;
use Webauthn\Exception\CertificateRevocationListException;
use Webauthn\Exception\InvalidCertificateException;
final class PhpCertificateChainValidator implements CertificateChainValidator, CanDispatchEvents
{
private const MAX_VALIDATION_LENGTH = 5;
private readonly ClockInterface $clock;
private EventDispatcherInterface $dispatcher;
public function __construct(
private readonly HttpClientInterface $client,
null|ClockInterface $clock = null,
private readonly bool $allowFailures = true
) {
$this->clock = $clock ?? new NativeClock();
$this->dispatcher = new NullEventDispatcher();
}
public static function create(
HttpClientInterface $client,
null|ClockInterface $clock = null,
bool $allowFailures = true
): self {
return new self($client, $clock, $allowFailures);
}
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->dispatcher = $eventDispatcher;
}
/**
* @param string[] $untrustedCertificates
* @param string[] $trustedCertificates
*/
public function check(array $untrustedCertificates, array $trustedCertificates): void
{
foreach ($trustedCertificates as $trustedCertificate) {
$this->dispatcher->dispatch(
BeforeCertificateChainValidation::create($untrustedCertificates, $trustedCertificate)
);
try {
if ($this->validateChain($untrustedCertificates, $trustedCertificate)) {
$this->dispatcher->dispatch(
CertificateChainValidationSucceeded::create($untrustedCertificates, $trustedCertificate)
);
return;
}
} catch (Throwable $exception) {
$this->dispatcher->dispatch(
CertificateChainValidationFailed::create($untrustedCertificates, $trustedCertificate)
);
throw $exception;
}
}
throw CertificateChainException::create($untrustedCertificates, $trustedCertificates);
}
/**
* @param string[] $untrustedCertificates
*/
private function validateChain(array $untrustedCertificates, string $trustedCertificate): bool
{
$untrustedCertificateObjects = array_map(
static fn (string $cert): Certificate => Certificate::fromPEM(PEM::fromString($cert)),
array_reverse($untrustedCertificates)
);
$trustedCertificateObject = Certificate::fromPEM(PEM::fromString($trustedCertificate));
// The trust path and the authenticator certificate are the same
if (count(
$untrustedCertificateObjects
) === 1 && $untrustedCertificateObjects[0]->toPEM()->string() === $trustedCertificateObject->toPEM()->string()) {
return true;
}
$uniqueCertificates = array_map(
static fn (Certificate $cert): string => $cert->toPEM()
->string(),
[...$untrustedCertificateObjects, $trustedCertificateObject]
);
count(array_unique($uniqueCertificates)) === count(
$uniqueCertificates
) || throw CertificateChainException::create(
$untrustedCertificates,
[$trustedCertificate],
'Invalid certificate chain with duplicated certificates.'
);
if (! $this->validateCertificates($trustedCertificateObject, ...$untrustedCertificateObjects)) {
return false;
}
$certificates = [$trustedCertificateObject, ...$untrustedCertificateObjects];
$numCerts = count($certificates);
for ($i = 1; $i < $numCerts; $i++) {
if ($this->isRevoked($certificates[$i])) {
throw CertificateChainException::create(
$untrustedCertificates,
[$trustedCertificate],
'Unable to validate the certificate chain. Revoked certificate found.'
);
}
}
return true;
}
private function isRevoked(Certificate $subject): bool
{
try {
$csn = $subject->tbsCertificate()
->serialNumber();
} catch (Throwable $e) {
throw InvalidCertificateException::create(
$subject->toPEM()
->string(),
sprintf('Failed to parse certificate: %s', $e->getMessage()),
$e
);
}
try {
$urls = $this->getCrlUrlList($subject);
} catch (Throwable $e) {
if ($this->allowFailures) {
return false;
}
throw InvalidCertificateException::create(
$subject->toPEM()
->string(),
'Failed to get CRL distribution points: ' . $e->getMessage(),
$e
);
}
foreach ($urls as $url) {
try {
$revokedCertificates = $this->retrieveRevokedSerialNumbers($url);
if (in_array($csn, $revokedCertificates, true)) {
return true;
}
} catch (Throwable $e) {
if ($this->allowFailures) {
return false;
}
throw CertificateRevocationListException::create($url, sprintf(
'Failed to retrieve the CRL:' . PHP_EOL . '%s',
$e->getMessage()
), $e);
}
}
return false;
}
private function validateCertificates(Certificate $trustAnchor, Certificate ...$certificates): bool
{
try {
$config = PathValidationConfig::create($this->clock->now(), self::MAX_VALIDATION_LENGTH)->withTrustAnchor(
$trustAnchor
);
CertificationPath::create(...$certificates)->validate($config);
return true;
} catch (Throwable) {
return false;
}
}
/**
* @return string[]
*/
private function retrieveRevokedSerialNumbers(string $url): array
{
try {
$crlData = $this->client->request('GET', $url)
->getContent();
$crl = UnspecifiedType::fromDER($crlData)->asSequence();
count($crl) === 3 || throw CertificateRevocationListException::create($url);
$tbsCertList = $crl->at(0)
->asSequence();
count($tbsCertList) >= 6 || throw CertificateRevocationListException::create($url);
$list = $tbsCertList->at(5)
->asSequence();
return array_map(static function (UnspecifiedType $r) use ($url): string {
$sequence = $r->asSequence();
count($sequence) >= 1 || throw CertificateRevocationListException::create($url);
return $sequence->at(0)
->asInteger()
->number();
}, $list->elements());
} catch (Throwable $e) {
throw CertificateRevocationListException::create($url, 'Failed to download the CRL', $e);
}
}
/**
* @return string[]
*/
private function getCrlUrlList(Certificate $subject): array
{
try {
$urls = [];
$extensions = $subject->tbsCertificate()
->extensions();
if ($extensions->hasCRLDistributionPoints()) {
$crlDists = $extensions->crlDistributionPoints();
foreach ($crlDists->distributionPoints() as $dist) {
$url = $dist->fullName()
->names()
->firstURI();
$scheme = parse_url($url, PHP_URL_SCHEME);
if (! in_array($scheme, ['http', 'https'], true)) {
continue;
}
$urls[] = $url;
}
}
return $urls;
} catch (Throwable $e) {
throw InvalidCertificateException::create(
$subject->toPEM()
->string(),
'Failed to get CRL distribution points from certificate: ' . $e->getMessage(),
$e
);
}
}
}

View file

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService;
use Webauthn\MetadataService\Statement\MetadataStatement;
interface MetadataStatementRepository
{
public function findOneByAAGUID(string $aaguid): ?MetadataStatement;
}

View file

@ -0,0 +1,138 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService;
use function is_array;
use const JSON_ERROR_NONE;
use JsonException;
use LogicException;
use const PHP_QUERY_RFC3986;
use Psr\Http\Client\ClientInterface as Psr18ClientInterface;
use Psr\Http\Message\RequestFactoryInterface as Psr17RequestFactoryInterface;
use Psr\Http\Message\ResponseInterface as Psr17ResponseInterface;
use Psr\Http\Message\StreamFactoryInterface as Psr17StreamFactoryInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
class Psr18HttpClient implements HttpClientInterface
{
/**
* @var array<string, string>
*/
private array $options = [];
public function __construct(
private readonly Psr18ClientInterface $client,
private readonly Psr17RequestFactoryInterface $requestFactory,
private readonly Psr17StreamFactoryInterface $streamFactory,
) {
}
/**
* @param array{base_uri?: string, query?: array<string, string>, body?: string, headers?: array<string, string>, ...} $options
*/
public function request(string $method, string $url, array $options = []): ResponseInterface
{
$baseUri = $options['base_uri'] ?? '';
$query = $options['query'] ?? [];
if ($query !== []) {
$url .= (! str_contains($url, '?') ? '?' : '&') . http_build_query($query, '', '&', PHP_QUERY_RFC3986);
}
$request = $this->requestFactory->createRequest($method, $baseUri . $url);
$body = $options['body'] ?? null;
if ($body !== null) {
$request = $request->withBody($this->streamFactory->createStream($body));
}
foreach ($this->options as $name => $value) {
$request = $request->withHeader($name, $value);
}
foreach ($options['headers'] ?? [] as $name => $value) {
$request = $request->withHeader($name, $value);
}
$response = $this->client->sendRequest($request);
return static::fromPsr17($response);
}
/**
* @param ResponseInterface|iterable<array-key, ResponseInterface> $responses
*/
public function stream(iterable|ResponseInterface $responses, ?float $timeout = null): ResponseStreamInterface
{
throw new LogicException('Not implemented');
}
/**
* @param array<string, string> $options
*/
public function withOptions(array $options): static
{
$this->options = $options;
return $this;
}
protected static function fromPsr17(Psr17ResponseInterface $response): ResponseInterface
{
/** @var array<string, list<string>> $headers */
$headers = $response->getHeaders();
$content = $response->getBody()
->getContents();
$status = $response->getStatusCode();
return new class($status, $headers, $content) implements ResponseInterface {
/**
* @param array<string, list<string>> $headers
*/
public function __construct(
private readonly int $status,
private readonly array $headers,
private readonly string $content,
) {
}
public function getStatusCode(): int
{
return $this->status;
}
/**
* @return array<string, list<string>>
*/
public function getHeaders(bool $throw = true): array
{
return $this->headers;
}
public function getContent(bool $throw = true): string
{
return $this->content;
}
/**
* @return array<array-key, mixed>
*/
public function toArray(bool $throw = true): array
{
$result = json_decode($this->content, true);
if (! is_array($result) || json_last_error() !== JSON_ERROR_NONE) {
throw new JsonException('Failed to decode JSON response: ' . json_last_error_msg());
}
return $result;
}
public function cancel(): void
{
// noop
}
public function getInfo(?string $type = null): mixed
{
return null;
}
};
}
}

View file

@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Service;
use Webauthn\Exception\MissingMetadataStatementException;
use Webauthn\MetadataService\Statement\MetadataStatement;
final class ChainedMetadataServices implements MetadataService
{
/**
* @var MetadataService[]
*/
private array $services = [];
public function __construct(MetadataService ...$services)
{
foreach ($services as $service) {
$this->addServices($service);
}
}
public static function create(MetadataService ...$services): self
{
return new self(...$services);
}
public function addServices(MetadataService ...$services): self
{
foreach ($services as $service) {
$this->services[] = $service;
}
return $this;
}
public function list(): iterable
{
foreach ($this->services as $service) {
yield from $service->list();
}
}
public function has(string $aaguid): bool
{
foreach ($this->services as $service) {
if ($service->has($aaguid)) {
return true;
}
}
return false;
}
public function get(string $aaguid): MetadataStatement
{
foreach ($this->services as $service) {
if ($service->has($aaguid)) {
return $service->get($aaguid);
}
}
throw MissingMetadataStatementException::create($aaguid);
}
}

View file

@ -0,0 +1,128 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Service;
use ParagonIE\ConstantTime\Base64;
use Psr\EventDispatcher\EventDispatcherInterface;
use function sprintf;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Webauthn\AttestationStatement\AttestationStatementSupportManager;
use Webauthn\Denormalizer\WebauthnSerializerFactory;
use Webauthn\Event\CanDispatchEvents;
use Webauthn\Event\MetadataStatementFound;
use Webauthn\Event\NullEventDispatcher;
use Webauthn\Exception\MetadataStatementLoadingException;
use Webauthn\Exception\MissingMetadataStatementException;
use Webauthn\MetadataService\Statement\MetadataStatement;
final class DistantResourceMetadataService implements MetadataService, CanDispatchEvents
{
private ?MetadataStatement $statement = null;
private EventDispatcherInterface $dispatcher;
private readonly SerializerInterface $serializer;
/**
* @param array<string, string> $additionalHeaderParameters
*/
public function __construct(
private readonly HttpClientInterface $httpClient,
private readonly string $uri,
private readonly bool $isBase64Encoded = false,
private readonly array $additionalHeaderParameters = [],
?SerializerInterface $serializer = null,
) {
$this->serializer = $serializer ?? (new WebauthnSerializerFactory(
AttestationStatementSupportManager::create()
))->create();
$this->dispatcher = new NullEventDispatcher();
}
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->dispatcher = $eventDispatcher;
}
/**
* @param array<string, string> $additionalHeaderParameters
*/
public static function create(
HttpClientInterface $httpClient,
string $uri,
bool $isBase64Encoded = false,
array $additionalHeaderParameters = [],
?SerializerInterface $serializer = null
): self {
return new self($httpClient, $uri, $isBase64Encoded, $additionalHeaderParameters, $serializer);
}
public function list(): iterable
{
$this->loadData();
$this->statement !== null || throw MetadataStatementLoadingException::create();
$aaguid = $this->statement->aaguid;
if ($aaguid === null) {
yield from [];
} else {
yield from [$aaguid];
}
}
public function has(string $aaguid): bool
{
$this->loadData();
$this->statement !== null || throw MetadataStatementLoadingException::create();
return $aaguid === $this->statement->aaguid;
}
public function get(string $aaguid): MetadataStatement
{
$this->loadData();
$this->statement !== null || throw MetadataStatementLoadingException::create();
if ($aaguid === $this->statement->aaguid) {
$this->dispatcher->dispatch(MetadataStatementFound::create($this->statement));
return $this->statement;
}
throw MissingMetadataStatementException::create($aaguid);
}
private function loadData(): void
{
if ($this->statement !== null) {
return;
}
$content = $this->fetch();
if ($this->isBase64Encoded) {
$content = Base64::decode($content, true);
}
$this->statement = $this->serializer->deserialize($content, MetadataStatement::class, JsonEncoder::FORMAT);
}
private function fetch(): string
{
$response = $this->httpClient->request('GET', $this->uri, [
'headers' => $this->additionalHeaderParameters,
]);
$response->getStatusCode() === 200 || throw MetadataStatementLoadingException::create(sprintf(
'Unable to contact the server. Response code is %d',
$response->getStatusCode()
));
$content = $response->getContent();
$content !== '' || throw MetadataStatementLoadingException::create(
'Unable to contact the server. The response has no content'
);
return $content;
}
}

View file

@ -0,0 +1,236 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Service;
use function array_key_exists;
use function is_array;
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\KeyManagement\JWKFactory;
use Jose\Component\Signature\Algorithm\ES256;
use Jose\Component\Signature\Algorithm\RS256;
use Jose\Component\Signature\JWSVerifier;
use Jose\Component\Signature\Serializer\CompactSerializer;
use LogicException;
use Psr\EventDispatcher\EventDispatcherInterface;
use function sprintf;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Throwable;
use Webauthn\AttestationStatement\AttestationStatementSupportManager;
use Webauthn\Denormalizer\WebauthnSerializerFactory;
use Webauthn\Event\CanDispatchEvents;
use Webauthn\Event\MetadataStatementFound;
use Webauthn\Event\NullEventDispatcher;
use Webauthn\Exception\MetadataStatementLoadingException;
use Webauthn\Exception\MissingMetadataStatementException;
use Webauthn\MetadataService\CertificateChain\CertificateChainValidator;
use Webauthn\MetadataService\CertificateChain\CertificateToolbox;
use Webauthn\MetadataService\Statement\MetadataStatement;
use Webauthn\MetadataService\Statement\StatusReport;
final class FidoAllianceCompliantMetadataService implements MetadataService, CanDispatchEvents
{
private bool $loaded = false;
/**
* @var MetadataStatement[]
*/
private array $statements = [];
/**
* @var array<string, StatusReport[]>
*/
private array $statusReports = [];
private EventDispatcherInterface $dispatcher;
private readonly SerializerInterface $serializer;
/**
* @param array<string, mixed> $additionalHeaderParameters
*/
public function __construct(
private readonly HttpClientInterface $httpClient,
private readonly string $uri,
private readonly array $additionalHeaderParameters = [],
private readonly ?CertificateChainValidator $certificateChainValidator = null,
private readonly ?string $rootCertificateUri = null,
?SerializerInterface $serializer = null,
) {
if (! class_exists(CompactSerializer::class)) {
throw new LogicException(
'The "web-token/jwt-library" package is required to use this service. Please run "composer require web-token/jwt-library".'
);
}
$this->serializer = $serializer ?? (new WebauthnSerializerFactory(
AttestationStatementSupportManager::create()
))->create();
$this->dispatcher = new NullEventDispatcher();
}
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->dispatcher = $eventDispatcher;
}
/**
* @param array<string, mixed> $additionalHeaderParameters
*/
public static function create(
HttpClientInterface $httpClient,
string $uri,
array $additionalHeaderParameters = [],
?CertificateChainValidator $certificateChainValidator = null,
?string $rootCertificateUri = null,
?SerializerInterface $serializer = null,
): self {
return new self(
$httpClient,
$uri,
$additionalHeaderParameters,
$certificateChainValidator,
$rootCertificateUri,
$serializer,
);
}
/**
* @return string[]
*/
public function list(): iterable
{
$this->loadData();
yield from array_keys($this->statements);
}
public function has(string $aaguid): bool
{
$this->loadData();
return array_key_exists($aaguid, $this->statements);
}
public function get(string $aaguid): MetadataStatement
{
$this->loadData();
array_key_exists($aaguid, $this->statements) || throw MissingMetadataStatementException::create($aaguid);
$mds = $this->statements[$aaguid];
$this->dispatcher->dispatch(MetadataStatementFound::create($mds));
return $mds;
}
/**
* @return StatusReport[]
*/
public function getStatusReports(string $aaguid): iterable
{
$this->loadData();
return $this->statusReports[$aaguid] ?? [];
}
private function loadData(): void
{
if ($this->loaded) {
return;
}
$content = $this->fetch($this->uri, $this->additionalHeaderParameters);
$jwtCertificates = [];
try {
$payload = $this->getJwsPayload($content, $jwtCertificates);
$this->validateCertificates(...$jwtCertificates);
/** @var MetadataBLOBPayload $blob */
$blob = $this->serializer->deserialize($payload, MetadataBLOBPayload::class, JsonEncoder::FORMAT);
foreach ($blob->entries as $entry) {
$mds = $entry->metadataStatement;
if ($mds !== null && $entry->aaguid !== null) {
$this->statements[$entry->aaguid] = $mds;
$this->statusReports[$entry->aaguid] = $entry->statusReports;
}
}
} catch (Throwable) {
// Nothing to do
} finally {
$this->loaded = true;
}
}
/**
* @param array<string, mixed> $headerParameters
*/
private function fetch(string $uri, array $headerParameters): string
{
$response = $this->httpClient->request('GET', $uri, [
'headers' => $headerParameters,
]);
$response->getStatusCode() === 200 || throw MetadataStatementLoadingException::create(sprintf(
'Unable to contact the server. Response code is %d',
$response->getStatusCode()
));
$content = $response->getContent();
$content !== '' || throw MetadataStatementLoadingException::create(
'Unable to contact the server. The response has no content'
);
return $content;
}
/**
* @param string[] $rootCertificates
*/
private function getJwsPayload(string $token, array &$rootCertificates): string
{
$jws = (new CompactSerializer())->unserialize($token);
$jws->countSignatures() === 1 || throw MetadataStatementLoadingException::create(
'Invalid response from the metadata service. Only one signature shall be present.'
);
$signature = $jws->getSignature(0);
$payload = $jws->getPayload();
$payload !== '' || throw MetadataStatementLoadingException::create(
'Invalid response from the metadata service. The token payload is empty.'
);
$header = $signature->getProtectedHeader();
array_key_exists('alg', $header) || throw MetadataStatementLoadingException::create(
'The "alg" parameter is missing.'
);
array_key_exists('x5c', $header) || throw MetadataStatementLoadingException::create(
'The "x5c" parameter is missing.'
);
is_array($header['x5c']) || throw MetadataStatementLoadingException::create(
'The "x5c" parameter should be an array.'
);
/** @var string[] $x5c */
$x5c = $header['x5c'];
$key = JWKFactory::createFromX5C($x5c);
$rootCertificates = $x5c;
$verifier = new JWSVerifier(new AlgorithmManager([new ES256(), new RS256()]));
$isValid = $verifier->verifyWithKey($jws, $key, 0);
$isValid || throw MetadataStatementLoadingException::create(
'Invalid response from the metadata service. The token signature is invalid.'
);
$payload = $jws->getPayload();
$payload !== null || throw MetadataStatementLoadingException::create(
'Invalid response from the metadata service. The payload is missing.'
);
return $payload;
}
private function validateCertificates(string ...$untrustedCertificates): void
{
if ($this->certificateChainValidator === null || $this->rootCertificateUri === null) {
return;
}
$untrustedCertificates = CertificateToolbox::fixPEMStructures($untrustedCertificates);
$rootCertificate = CertificateToolbox::convertDERToPEM($this->fetch($this->rootCertificateUri, []));
$this->certificateChainValidator->check($untrustedCertificates, [$rootCertificate]);
}
}

View file

@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Service;
use function assert;
use const DIRECTORY_SEPARATOR;
use function file_get_contents;
use InvalidArgumentException;
use function is_array;
use function sprintf;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\SerializerInterface;
use Webauthn\AttestationStatement\AttestationStatementSupportManager;
use Webauthn\Denormalizer\WebauthnSerializerFactory;
use Webauthn\Exception\MetadataStatementLoadingException;
use Webauthn\MetadataService\Statement\MetadataStatement;
final class FolderResourceMetadataService implements MetadataService
{
private readonly SerializerInterface $serializer;
public function __construct(
private string $rootPath,
?SerializerInterface $serializer = null,
) {
$this->serializer = $serializer ?? (new WebauthnSerializerFactory(
AttestationStatementSupportManager::create()
))->create();
$this->rootPath = rtrim($rootPath, DIRECTORY_SEPARATOR);
is_dir($this->rootPath) || throw new InvalidArgumentException('The given parameter is not a valid folder.');
is_readable($this->rootPath) || throw new InvalidArgumentException(
'The given parameter is not a valid folder.'
);
}
public static function create(string $rootPath, ?SerializerInterface $serializer = null): self
{
return new self($rootPath, $serializer);
}
public function list(): iterable
{
$files = glob($this->rootPath . DIRECTORY_SEPARATOR . '*');
is_array($files) || throw MetadataStatementLoadingException::create('Unable to read files.');
foreach ($files as $file) {
if (is_dir($file) || ! is_readable($file)) {
continue;
}
yield basename($file);
}
}
public function has(string $aaguid): bool
{
$filename = $this->rootPath . DIRECTORY_SEPARATOR . $aaguid;
return is_file($filename) && is_readable($filename);
}
public function get(string $aaguid): MetadataStatement
{
$this->has($aaguid) || throw new InvalidArgumentException(sprintf(
'The MDS with the AAGUID "%s" does not exist.',
$aaguid
));
$filename = $this->rootPath . DIRECTORY_SEPARATOR . $aaguid;
$content = file_get_contents($filename);
assert($content !== false, 'The file exists and is readable.');
$data = trim($content);
$mds = $this->serializer->deserialize($data, MetadataStatement::class, JsonEncoder::FORMAT);
$mds->aaguid !== null || throw MetadataStatementLoadingException::create('Invalid Metadata Statement.');
return $mds;
}
}

View file

@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Service;
use function array_key_exists;
use Psr\EventDispatcher\EventDispatcherInterface;
use Webauthn\Event\CanDispatchEvents;
use Webauthn\Event\MetadataStatementFound;
use Webauthn\Event\NullEventDispatcher;
use Webauthn\Exception\MissingMetadataStatementException;
use Webauthn\MetadataService\Statement\MetadataStatement;
final class InMemoryMetadataService implements MetadataService, CanDispatchEvents
{
/**
* @var MetadataStatement[]
*/
private array $statements = [];
private EventDispatcherInterface $dispatcher;
public function __construct(MetadataStatement ...$statements)
{
foreach ($statements as $statement) {
$this->addStatements($statement);
}
$this->dispatcher = new NullEventDispatcher();
}
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->dispatcher = $eventDispatcher;
}
public static function create(MetadataStatement ...$statements): self
{
return new self(...$statements);
}
public function addStatements(MetadataStatement ...$statements): self
{
foreach ($statements as $statement) {
$aaguid = $statement->aaguid;
if ($aaguid === null) {
continue;
}
$this->statements[$aaguid] = $statement;
}
return $this;
}
public function list(): iterable
{
yield from array_keys($this->statements);
}
public function has(string $aaguid): bool
{
return array_key_exists($aaguid, $this->statements);
}
public function get(string $aaguid): MetadataStatement
{
array_key_exists($aaguid, $this->statements) || throw MissingMetadataStatementException::create($aaguid);
$mds = $this->statements[$aaguid];
$this->dispatcher->dispatch(MetadataStatementFound::create($mds));
return $mds;
}
}

View file

@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Service;
use function array_key_exists;
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\SerializerInterface;
use Webauthn\AttestationStatement\AttestationStatementSupportManager;
use Webauthn\Denormalizer\WebauthnSerializerFactory;
use Webauthn\Event\CanDispatchEvents;
use Webauthn\Event\MetadataStatementFound;
use Webauthn\Event\NullEventDispatcher;
use Webauthn\Exception\MissingMetadataStatementException;
use Webauthn\MetadataService\Statement\MetadataStatement;
final class JsonMetadataService implements MetadataService, CanDispatchEvents
{
/**
* @var MetadataStatement[]
*/
private array $statements = [];
private EventDispatcherInterface $dispatcher;
private readonly SerializerInterface $serializer;
/**
* @param string[] $statements
*/
public function __construct(array $statements, ?SerializerInterface $serializer = null)
{
$this->dispatcher = new NullEventDispatcher();
$this->serializer = $serializer ?? (new WebauthnSerializerFactory(
AttestationStatementSupportManager::create()
))->create();
foreach ($statements as $statement) {
$this->addStatement($statement);
}
}
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->dispatcher = $eventDispatcher;
}
public function list(): iterable
{
yield from array_keys($this->statements);
}
public function has(string $aaguid): bool
{
return array_key_exists($aaguid, $this->statements);
}
public function get(string $aaguid): MetadataStatement
{
array_key_exists($aaguid, $this->statements) || throw MissingMetadataStatementException::create($aaguid);
$mds = $this->statements[$aaguid];
$this->dispatcher->dispatch(MetadataStatementFound::create($mds));
return $mds;
}
private function addStatement(string $statement): void
{
$mds = $this->serializer->deserialize($statement, MetadataStatement::class, JsonEncoder::FORMAT);
if ($mds->aaguid === null) {
return;
}
$this->statements[$mds->aaguid] = $mds;
}
}

View file

@ -0,0 +1,101 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Service;
use function assert;
use function file_get_contents;
use ParagonIE\ConstantTime\Base64;
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\SerializerInterface;
use Webauthn\AttestationStatement\AttestationStatementSupportManager;
use Webauthn\Denormalizer\WebauthnSerializerFactory;
use Webauthn\Event\CanDispatchEvents;
use Webauthn\Event\MetadataStatementFound;
use Webauthn\Event\NullEventDispatcher;
use Webauthn\Exception\MetadataStatementLoadingException;
use Webauthn\Exception\MissingMetadataStatementException;
use Webauthn\MetadataService\Statement\MetadataStatement;
final class LocalResourceMetadataService implements MetadataService, CanDispatchEvents
{
private ?MetadataStatement $statement = null;
private EventDispatcherInterface $dispatcher;
private readonly SerializerInterface $serializer;
public function __construct(
private readonly string $filename,
private readonly bool $isBase64Encoded = false,
?SerializerInterface $serializer = null,
) {
$this->serializer = $serializer ?? (new WebauthnSerializerFactory(
AttestationStatementSupportManager::create()
))->create();
$this->dispatcher = new NullEventDispatcher();
}
public static function create(
string $filename,
bool $isBase64Encoded = false,
?SerializerInterface $serializer = null
): self {
return new self($filename, $isBase64Encoded, $serializer);
}
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->dispatcher = $eventDispatcher;
}
public function list(): iterable
{
$this->loadData();
$this->statement !== null || throw MetadataStatementLoadingException::create();
$aaguid = $this->statement->aaguid;
if ($aaguid === null) {
yield from [];
} else {
yield from [$aaguid];
}
}
public function has(string $aaguid): bool
{
$this->loadData();
$this->statement !== null || throw MetadataStatementLoadingException::create();
return $aaguid === $this->statement->aaguid;
}
public function get(string $aaguid): MetadataStatement
{
$this->loadData();
$this->statement !== null || throw MetadataStatementLoadingException::create();
if ($aaguid === $this->statement->aaguid) {
$this->dispatcher->dispatch(MetadataStatementFound::create($this->statement));
return $this->statement;
}
throw MissingMetadataStatementException::create($aaguid);
}
private function loadData(): void
{
if ($this->statement !== null) {
return;
}
$content = file_get_contents($this->filename);
assert($content !== false, 'The file could not be read');
if ($this->isBase64Encoded) {
$content = Base64::decode($content, true);
}
$this->statement = $this->serializer->deserialize($content, MetadataStatement::class, JsonEncoder::FORMAT);
}
}

View file

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Service;
class MetadataBLOBPayload
{
/**
* @param MetadataBLOBPayloadEntry[] $entries
*/
public function __construct(
public readonly int $no,
public readonly string $nextUpdate,
public readonly ?string $legalHeader = null,
public array $entries = [],
) {
}
}

View file

@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Service;
use function count;
use function is_string;
use Webauthn\Exception\MetadataStatementLoadingException;
use Webauthn\MetadataService\Statement\BiometricStatusReport;
use Webauthn\MetadataService\Statement\MetadataStatement;
use Webauthn\MetadataService\Statement\StatusReport;
class MetadataBLOBPayloadEntry
{
/**
* @param StatusReport[] $statusReports
* @param BiometricStatusReport[] $biometricStatusReports
* @param string[] $attestationCertificateKeyIdentifiers
*/
public function __construct(
public readonly string $timeOfLastStatusChange,
public array $statusReports,
public readonly ?string $aaid = null,
public readonly ?string $aaguid = null,
public array $attestationCertificateKeyIdentifiers = [],
public readonly ?MetadataStatement $metadataStatement = null,
public readonly ?string $rogueListURL = null,
public readonly ?string $rogueListHash = null,
public array $biometricStatusReports = []
) {
if ($aaid !== null && $aaguid !== null) {
throw MetadataStatementLoadingException::create('Authenticators cannot support both AAID and AAGUID');
}
if ($aaid === null && $aaguid === null && count($attestationCertificateKeyIdentifiers) === 0) {
throw MetadataStatementLoadingException::create(
'If neither AAID nor AAGUID are set, the attestation certificate identifier list shall not be empty'
);
}
foreach ($attestationCertificateKeyIdentifiers as $attestationCertificateKeyIdentifier) {
is_string($attestationCertificateKeyIdentifier) || throw MetadataStatementLoadingException::create(
'Invalid attestation certificate identifier. Shall be a list of strings'
);
preg_match(
'/^[0-9a-f]+$/',
$attestationCertificateKeyIdentifier
) === 1 || throw MetadataStatementLoadingException::create(
'Invalid attestation certificate identifier. Shall be a list of strings'
);
}
}
}

View file

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Service;
use Webauthn\MetadataService\Statement\MetadataStatement;
interface MetadataService
{
/**
* @return string[] The list of AAGUID supported by the service
*/
public function list(): iterable;
public function has(string $aaguid): bool;
public function get(string $aaguid): MetadataStatement;
}

View file

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
use Webauthn\Exception\MetadataStatementLoadingException;
abstract class AbstractDescriptor
{
public function __construct(
public readonly ?int $maxRetries = null,
public readonly ?int $blockSlowdown = null
) {
$maxRetries >= 0 || throw MetadataStatementLoadingException::create(
'Invalid data. The value of "maxRetries" must be a positive integer'
);
$blockSlowdown >= 0 || throw MetadataStatementLoadingException::create(
'Invalid data. The value of "blockSlowdown" must be a positive integer'
);
}
}

View file

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
class AlternativeDescriptions
{
/**
* @param array<string, string> $descriptions
*/
public function __construct(
public array $descriptions = []
) {
}
/**
* @param array<string, string> $descriptions
*/
public static function create(array $descriptions = []): self
{
return new self($descriptions);
}
}

View file

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
class AuthenticatorGetInfo
{
/**
* @param array<array-key, mixed> $info
*/
public function __construct(
public array $info = []
) {
}
/**
* @param array<array-key, mixed> $info
*/
public static function create(array $info = []): self
{
return new self($info);
}
}

View file

@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
final class AuthenticatorStatus
{
public const NOT_FIDO_CERTIFIED = 'NOT_FIDO_CERTIFIED';
public const FIDO_CERTIFIED = 'FIDO_CERTIFIED';
public const USER_VERIFICATION_BYPASS = 'USER_VERIFICATION_BYPASS';
public const ATTESTATION_KEY_COMPROMISE = 'ATTESTATION_KEY_COMPROMISE';
public const USER_KEY_REMOTE_COMPROMISE = 'USER_KEY_REMOTE_COMPROMISE';
public const USER_KEY_PHYSICAL_COMPROMISE = 'USER_KEY_PHYSICAL_COMPROMISE';
public const UPDATE_AVAILABLE = 'UPDATE_AVAILABLE';
public const REVOKED = 'REVOKED';
public const SELF_ASSERTION_SUBMITTED = 'SELF_ASSERTION_SUBMITTED';
public const FIDO_CERTIFIED_L1 = 'FIDO_CERTIFIED_L1';
public const FIDO_CERTIFIED_L1plus = 'FIDO_CERTIFIED_L1plus';
public const FIDO_CERTIFIED_L2 = 'FIDO_CERTIFIED_L2';
public const FIDO_CERTIFIED_L2plus = 'FIDO_CERTIFIED_L2plus';
public const FIDO_CERTIFIED_L3 = 'FIDO_CERTIFIED_L3';
public const FIDO_CERTIFIED_L3plus = 'FIDO_CERTIFIED_L3plus';
public const FIDO_CERTIFIED_L4 = 'FIDO_CERTIFIED_L4';
public const FIDO_CERTIFIED_L5 = 'FIDO_CERTIFIED_L5';
public const STATUSES = [
self::NOT_FIDO_CERTIFIED,
self::FIDO_CERTIFIED,
self::USER_VERIFICATION_BYPASS,
self::ATTESTATION_KEY_COMPROMISE,
self::USER_KEY_REMOTE_COMPROMISE,
self::USER_KEY_PHYSICAL_COMPROMISE,
self::UPDATE_AVAILABLE,
self::REVOKED,
self::SELF_ASSERTION_SUBMITTED,
self::FIDO_CERTIFIED_L1,
self::FIDO_CERTIFIED_L1plus,
self::FIDO_CERTIFIED_L2,
self::FIDO_CERTIFIED_L2plus,
self::FIDO_CERTIFIED_L3,
self::FIDO_CERTIFIED_L3plus,
self::FIDO_CERTIFIED_L4,
self::FIDO_CERTIFIED_L5,
];
}

View file

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
class BiometricAccuracyDescriptor extends AbstractDescriptor
{
public function __construct(
public readonly ?float $selfAttestedFRR,
public readonly ?float $selfAttestedFAR,
public readonly ?float $maxTemplates,
?int $maxRetries = null,
?int $blockSlowdown = null
) {
parent::__construct($maxRetries, $blockSlowdown);
}
public static function create(
?float $selfAttestedFRR,
?float $selfAttestedFAR,
?float $maxTemplates,
?int $maxRetries = null,
?int $blockSlowdown = null
): self {
return new self($selfAttestedFRR, $selfAttestedFAR, $maxTemplates, $maxRetries, $blockSlowdown);
}
}

View file

@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
readonly class BiometricStatusReport
{
private function __construct(
public ?int $certLevel,
public ?int $modality,
public ?string $effectiveDate,
public ?string $certificationDescriptor,
public ?string $certificateNumber,
public ?string $certificationPolicyVersion,
public ?string $certificationRequirementsVersion,
) {
}
public static function create(
?int $certLevel,
?int $modality,
?string $effectiveDate,
?string $certificationDescriptor,
?string $certificateNumber,
?string $certificationPolicyVersion,
?string $certificationRequirementsVersion,
): self {
return new self(
$certLevel,
$modality,
$effectiveDate,
$certificationDescriptor,
$certificateNumber,
$certificationPolicyVersion,
$certificationRequirementsVersion,
);
}
}

View file

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
use Webauthn\Exception\MetadataStatementLoadingException;
class CodeAccuracyDescriptor extends AbstractDescriptor
{
public function __construct(
public readonly int $base,
public readonly int $minLength,
?int $maxRetries = null,
?int $blockSlowdown = null
) {
$base >= 0 || throw MetadataStatementLoadingException::create(
'Invalid data. The value of "base" must be a positive integer'
);
$minLength >= 0 || throw MetadataStatementLoadingException::create(
'Invalid data. The value of "minLength" must be a positive integer'
);
parent::__construct($maxRetries, $blockSlowdown);
}
public static function create(int $base, int $minLength, ?int $maxRetries = null, ?int $blockSlowdown = null): self
{
return new self($base, $minLength, $maxRetries, $blockSlowdown);
}
}

View file

@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
use Webauthn\Exception\MetadataStatementLoadingException;
class DisplayPNGCharacteristicsDescriptor
{
/**
* @param RgbPaletteEntry[] $plte
*/
public function __construct(
public readonly int $width,
public readonly int $height,
public readonly int $bitDepth,
public readonly int $colorType,
public readonly int $compression,
public readonly int $filter,
public readonly int $interlace,
/**
* @readonly
*/
public array $plte = [],
) {
$width >= 0 || throw MetadataStatementLoadingException::create('Invalid width');
$height >= 0 || throw MetadataStatementLoadingException::create('Invalid height');
($bitDepth >= 0 && $bitDepth <= 254) || throw MetadataStatementLoadingException::create('Invalid bit depth');
($colorType >= 0 && $colorType <= 254) || throw MetadataStatementLoadingException::create(
'Invalid color type'
);
($compression >= 0 && $compression <= 254) || throw MetadataStatementLoadingException::create(
'Invalid compression'
);
($filter >= 0 && $filter <= 254) || throw MetadataStatementLoadingException::create('Invalid filter');
($interlace >= 0 && $interlace <= 254) || throw MetadataStatementLoadingException::create(
'Invalid interlace'
);
}
/**
* @param RgbPaletteEntry[] $plte
*/
public static function create(
int $width,
int $height,
int $bitDepth,
int $colorType,
int $compression,
int $filter,
int $interlace,
array $plte = []
): self {
return new self($width, $height, $bitDepth, $colorType, $compression, $filter, $interlace, $plte);
}
}

View file

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
use Symfony\Component\Serializer\Attribute\SerializedName;
use Webauthn\Exception\MetadataStatementLoadingException;
readonly class ExtensionDescriptor
{
public function __construct(
public string $id,
public ?int $tag,
public ?string $data,
#[SerializedName('fail_if_unknown')]
public bool $failIfUnknown
) {
if ($tag !== null) {
$tag >= 0 || throw MetadataStatementLoadingException::create(
'Invalid data. The parameter "tag" shall be a positive integer'
);
}
}
public static function create(
string $id,
?int $tag = null,
?string $data = null,
bool $failIfUnknown = false
): self {
return new self($id, $tag, $data, $failIfUnknown);
}
}

View file

@ -0,0 +1,275 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
class MetadataStatement
{
final public const KEY_PROTECTION_SOFTWARE = 'software';
final public const KEY_PROTECTION_SOFTWARE_INT = 0x0001;
final public const KEY_PROTECTION_HARDWARE = 'hardware';
final public const KEY_PROTECTION_HARDWARE_INT = 0x0002;
final public const KEY_PROTECTION_TEE = 'tee';
final public const KEY_PROTECTION_TEE_INT = 0x0004;
final public const KEY_PROTECTION_SECURE_ELEMENT = 'secure_element';
final public const KEY_PROTECTION_SECURE_ELEMENT_INT = 0x0008;
final public const KEY_PROTECTION_REMOTE_HANDLE = 'remote_handle';
final public const KEY_PROTECTION_REMOTE_HANDLE_INT = 0x0010;
final public const KEY_PROTECTION_TYPES = [
self::KEY_PROTECTION_SOFTWARE,
self::KEY_PROTECTION_HARDWARE,
self::KEY_PROTECTION_TEE,
self::KEY_PROTECTION_SECURE_ELEMENT,
self::KEY_PROTECTION_REMOTE_HANDLE,
];
final public const KEY_PROTECTION_TYPES_INT = [
self::KEY_PROTECTION_SOFTWARE_INT,
self::KEY_PROTECTION_HARDWARE_INT,
self::KEY_PROTECTION_TEE_INT,
self::KEY_PROTECTION_SECURE_ELEMENT_INT,
self::KEY_PROTECTION_REMOTE_HANDLE_INT,
];
final public const MATCHER_PROTECTION_SOFTWARE = 'software';
final public const MATCHER_PROTECTION_SOFTWARE_INT = 0x0001;
final public const MATCHER_PROTECTION_TEE = 'tee';
final public const MATCHER_PROTECTION_TEE_INT = 0x0002;
final public const MATCHER_PROTECTION_ON_CHIP = 'on_chip';
final public const MATCHER_PROTECTION_ON_CHIP_INT = 0x0004;
final public const MATCHER_PROTECTION_TYPES = [
self::MATCHER_PROTECTION_SOFTWARE,
self::MATCHER_PROTECTION_TEE,
self::MATCHER_PROTECTION_ON_CHIP,
];
final public const MATCHER_PROTECTION_TYPES_INT = [
self::MATCHER_PROTECTION_SOFTWARE_INT,
self::MATCHER_PROTECTION_TEE_INT,
self::MATCHER_PROTECTION_ON_CHIP_INT,
];
final public const ATTACHMENT_HINT_INTERNAL = 'internal';
final public const ATTACHMENT_HINT_EXTERNAL = 'external';
final public const ATTACHMENT_HINT_WIRED = 'wired';
final public const ATTACHMENT_HINT_WIRELESS = 'wireless';
final public const ATTACHMENT_HINT_NFC = 'nfc';
final public const ATTACHMENT_HINT_BLUETOOTH = 'bluetooth';
final public const ATTACHMENT_HINT_NETWORK = 'network';
final public const ATTACHMENT_HINT_READY = 'ready';
final public const ATTACHMENT_HINT_WIFI_DIRECT = 'wifi_direct';
final public const TRANSACTION_CONFIRMATION_DISPLAY_ANY = 'any';
final public const TRANSACTION_CONFIRMATION_DISPLAY_PRIVILEGED_SOFTWARE = 'privileged_software';
final public const TRANSACTION_CONFIRMATION_DISPLAY_TEE = 'tee';
final public const TRANSACTION_CONFIRMATION_DISPLAY_HARDWARE = 'hardware';
final public const TRANSACTION_CONFIRMATION_DISPLAY_REMOTE = 'remote';
final public const ALG_SIGN_SECP256R1_ECDSA_SHA256_RAW = 'secp256r1_ecdsa_sha256_raw';
final public const ALG_SIGN_SECP256R1_ECDSA_SHA256_DER = 'secp256r1_ecdsa_sha256_der';
final public const ALG_SIGN_RSASSA_PSS_SHA256_RAW = 'rsassa_pss_sha256_raw';
final public const ALG_SIGN_RSASSA_PSS_SHA256_DER = 'rsassa_pss_sha256_der';
final public const ALG_SIGN_SECP256K1_ECDSA_SHA256_RAW = 'secp256k1_ecdsa_sha256_raw';
final public const ALG_SIGN_SECP256K1_ECDSA_SHA256_DER = 'secp256k1_ecdsa_sha256_der';
final public const ALG_SIGN_SM2_SM3_RAW = 'sm2_sm3_raw';
final public const ALG_SIGN_RSA_EMSA_PKCS1_SHA256_RAW = 'rsa_emsa_pkcs1_sha256_raw';
final public const ALG_SIGN_RSA_EMSA_PKCS1_SHA256_DER = 'rsa_emsa_pkcs1_sha256_der';
final public const ALG_SIGN_RSASSA_PSS_SHA384_RAW = 'rsassa_pss_sha384_raw';
final public const ALG_SIGN_RSASSA_PSS_SHA512_RAW = 'rsassa_pss_sha256_raw';
final public const ALG_SIGN_RSASSA_PKCSV15_SHA256_RAW = 'rsassa_pkcsv15_sha256_raw';
final public const ALG_SIGN_RSASSA_PKCSV15_SHA384_RAW = 'rsassa_pkcsv15_sha384_raw';
final public const ALG_SIGN_RSASSA_PKCSV15_SHA512_RAW = 'rsassa_pkcsv15_sha512_raw';
final public const ALG_SIGN_RSASSA_PKCSV15_SHA1_RAW = 'rsassa_pkcsv15_sha1_raw';
final public const ALG_SIGN_SECP384R1_ECDSA_SHA384_RAW = 'secp384r1_ecdsa_sha384_raw';
final public const ALG_SIGN_SECP521R1_ECDSA_SHA512_RAW = 'secp512r1_ecdsa_sha256_raw';
final public const ALG_SIGN_ED25519_EDDSA_SHA256_RAW = 'ed25519_eddsa_sha512_raw';
final public const ALG_KEY_ECC_X962_RAW = 'ecc_x962_raw';
final public const ALG_KEY_ECC_X962_DER = 'ecc_x962_der';
final public const ALG_KEY_RSA_2048_RAW = 'rsa_2048_raw';
final public const ALG_KEY_RSA_2048_DER = 'rsa_2048_der';
final public const ALG_KEY_COSE = 'cose';
final public const ATTESTATION_BASIC_FULL = 'basic_full';
final public const ATTESTATION_BASIC_SURROGATE = 'basic_surrogate';
final public const ATTESTATION_ATTCA = 'attca';
final public const ATTESTATION_ANONCA = 'anonca';
public readonly AuthenticatorGetInfo $authenticatorGetInfo;
/**
* @param Version[] $upv
* @param string[] $authenticationAlgorithms
* @param string[] $publicKeyAlgAndEncodings
* @param string[] $attestationTypes
* @param VerificationMethodANDCombinations[] $userVerificationDetails
* @param string[] $matcherProtection
* @param string[] $tcDisplay
* @param string[] $attestationRootCertificates
* @param string[] $attestationCertificateKeyIdentifiers
* @param string[] $keyProtection
* @param string[] $attachmentHint
* @param ExtensionDescriptor[] $supportedExtensions
* @param DisplayPNGCharacteristicsDescriptor[] $tcDisplayPNGCharacteristics
*/
public function __construct(
public readonly string $description,
public readonly int $authenticatorVersion,
public readonly string $protocolFamily,
public readonly int $schema,
public readonly array $upv,
public readonly array $authenticationAlgorithms,
public readonly array $publicKeyAlgAndEncodings,
public readonly array $attestationTypes,
public readonly array $userVerificationDetails,
public readonly array $matcherProtection,
public readonly array $tcDisplay,
public readonly array $attestationRootCertificates,
public readonly ?AlternativeDescriptions $alternativeDescriptions = null,
public ?string $legalHeader = null,
public ?string $aaid = null,
public ?string $aaguid = null,
public array $attestationCertificateKeyIdentifiers = [],
public array $keyProtection = [],
public ?bool $isKeyRestricted = null,
public ?bool $isFreshUserVerificationRequired = null,
public ?int $cryptoStrength = null,
public array $attachmentHint = [],
public ?string $tcDisplayContentType = null,
public array $tcDisplayPNGCharacteristics = [],
public ?string $icon = null,
public array $supportedExtensions = [],
?AuthenticatorGetInfo $authenticatorGetInfo = null,
) {
$this->authenticatorGetInfo = $authenticatorGetInfo ?? AuthenticatorGetInfo::create($attestationTypes);
}
/**
* @param Version[] $upv
* @param string[] $authenticationAlgorithms
* @param string[] $publicKeyAlgAndEncodings
* @param string[] $attestationTypes
* @param VerificationMethodANDCombinations[] $userVerificationDetails
* @param string[] $matcherProtection
* @param string[] $tcDisplay
* @param string[] $attestationRootCertificates
* @param string[] $attestationCertificateKeyIdentifiers
* @param string[] $keyProtection
* @param string[] $attachmentHint
* @param ExtensionDescriptor[] $supportedExtensions
* @param DisplayPNGCharacteristicsDescriptor[] $tcDisplayPNGCharacteristics
* @param array<string, string> $alternativeDescriptions
*/
public static function create(
string $description,
int $authenticatorVersion,
string $protocolFamily,
int $schema,
array $upv,
array $authenticationAlgorithms,
array $publicKeyAlgAndEncodings,
array $attestationTypes,
array $userVerificationDetails,
array $matcherProtection,
array $tcDisplay,
array $attestationRootCertificates,
array $alternativeDescriptions = [],
?string $legalHeader = null,
?string $aaid = null,
?string $aaguid = null,
array $attestationCertificateKeyIdentifiers = [],
array $keyProtection = [],
?bool $isKeyRestricted = null,
?bool $isFreshUserVerificationRequired = null,
?int $cryptoStrength = null,
array $attachmentHint = [],
?string $tcDisplayContentType = null,
array $tcDisplayPNGCharacteristics = [],
?string $icon = null,
array $supportedExtensions = [],
?AuthenticatorGetInfo $authenticatorGetInfo = null,
): self {
return new self(
$description,
$authenticatorVersion,
$protocolFamily,
$schema,
$upv,
$authenticationAlgorithms,
$publicKeyAlgAndEncodings,
$attestationTypes,
$userVerificationDetails,
$matcherProtection,
$tcDisplay,
$attestationRootCertificates,
AlternativeDescriptions::create($alternativeDescriptions),
$legalHeader,
$aaid,
$aaguid,
$attestationCertificateKeyIdentifiers,
$keyProtection,
$isKeyRestricted,
$isFreshUserVerificationRequired,
$cryptoStrength,
$attachmentHint,
$tcDisplayContentType,
$tcDisplayPNGCharacteristics,
$icon,
$supportedExtensions,
$authenticatorGetInfo,
);
}
}

View file

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
use Webauthn\Exception\MetadataStatementLoadingException;
class PatternAccuracyDescriptor extends AbstractDescriptor
{
public function __construct(
public readonly int $minComplexity,
?int $maxRetries = null,
?int $blockSlowdown = null
) {
$minComplexity >= 0 || throw MetadataStatementLoadingException::create(
'Invalid data. The value of "minComplexity" must be a positive integer'
);
parent::__construct($maxRetries, $blockSlowdown);
}
public static function create(int $minComplexity, ?int $maxRetries = null, ?int $blockSlowdown = null): self
{
return new self($minComplexity, $maxRetries, $blockSlowdown);
}
}

View file

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
use Webauthn\Exception\MetadataStatementLoadingException;
readonly class RgbPaletteEntry
{
public function __construct(
public int $r,
public int $g,
public int $b,
) {
($r >= 0 && $r <= 255) || throw MetadataStatementLoadingException::create('The key "r" is invalid');
($g >= 0 && $g <= 255) || throw MetadataStatementLoadingException::create('The key "g" is invalid');
($b >= 0 && $b <= 255) || throw MetadataStatementLoadingException::create('The key "b" is invalid');
}
public static function create(int $r, int $g, int $b): self
{
return new self($r, $g, $b);
}
}

View file

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
readonly class RogueListEntry
{
public function __construct(
public string $sk,
public string $date
) {
}
public static function create(string $sk, string $date): self
{
return new self($sk, $date);
}
}

View file

@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
use function in_array;
use Webauthn\Exception\MetadataStatementLoadingException;
readonly class StatusReport
{
/**
* @see AuthenticatorStatus
*/
public function __construct(
public string $status,
public ?string $effectiveDate,
public ?string $certificate,
public ?string $url,
public ?string $certificationDescriptor,
public ?string $certificateNumber,
public ?string $certificationPolicyVersion,
public ?string $certificationRequirementsVersion
) {
in_array($status, AuthenticatorStatus::STATUSES, true) || throw MetadataStatementLoadingException::create(
'The value of the key "status" is not acceptable'
);
}
public static function create(
string $status,
?string $effectiveDate,
?string $certificate,
?string $url,
?string $certificationDescriptor,
?string $certificateNumber,
?string $certificationPolicyVersion,
?string $certificationRequirementsVersion
): self {
return new self(
$status,
$effectiveDate,
$certificate,
$url,
$certificationDescriptor,
$certificateNumber,
$certificationPolicyVersion,
$certificationRequirementsVersion
);
}
public function isCompromised(): bool
{
return in_array($this->status, [
AuthenticatorStatus::ATTESTATION_KEY_COMPROMISE,
AuthenticatorStatus::USER_KEY_PHYSICAL_COMPROMISE,
AuthenticatorStatus::USER_KEY_REMOTE_COMPROMISE,
AuthenticatorStatus::USER_VERIFICATION_BYPASS,
], true);
}
}

View file

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
class VerificationMethodANDCombinations
{
/**
* @param VerificationMethodDescriptor[] $verificationMethods
*/
public function __construct(
/**
* @readonly
*/
public array $verificationMethods = []
) {
}
/**
* @param VerificationMethodDescriptor[] $verificationMethods
*/
public static function create(array $verificationMethods): self
{
return new self($verificationMethods);
}
}

View file

@ -0,0 +1,179 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
use Webauthn\Exception\MetadataStatementLoadingException;
class VerificationMethodDescriptor
{
final public const USER_VERIFY_PRESENCE_INTERNAL = 'presence_internal';
final public const USER_VERIFY_PRESENCE_INTERNAL_INT = 0x00000001;
final public const USER_VERIFY_FINGERPRINT_INTERNAL = 'fingerprint_internal';
final public const USER_VERIFY_FINGERPRINT_INTERNAL_INT = 0x00000002;
final public const USER_VERIFY_PASSCODE_INTERNAL = 'passcode_internal';
final public const USER_VERIFY_PASSCODE_INTERNAL_INT = 0x00000004;
final public const USER_VERIFY_VOICEPRINT_INTERNAL = 'voiceprint_internal';
final public const USER_VERIFY_VOICEPRINT_INTERNAL_INT = 0x00000008;
final public const USER_VERIFY_FACEPRINT_INTERNAL = 'faceprint_internal';
final public const USER_VERIFY_FACEPRINT_INTERNAL_INT = 0x00000010;
final public const USER_VERIFY_LOCATION_INTERNAL = 'location_internal';
final public const USER_VERIFY_LOCATION_INTERNAL_INT = 0x00000020;
final public const USER_VERIFY_EYEPRINT_INTERNAL = 'eyeprint_internal';
final public const USER_VERIFY_EYEPRINT_INTERNAL_INT = 0x00000040;
final public const USER_VERIFY_PATTERN_INTERNAL = 'pattern_internal';
final public const USER_VERIFY_PATTERN_INTERNAL_INT = 0x00000080;
final public const USER_VERIFY_HANDPRINT_INTERNAL = 'handprint_internal';
final public const USER_VERIFY_HANDPRINT_INTERNAL_INT = 0x00000100;
final public const USER_VERIFY_PASSCODE_EXTERNAL = 'passcode_external';
final public const USER_VERIFY_PASSCODE_EXTERNAL_INT = 0x00000800;
final public const USER_VERIFY_PATTERN_EXTERNAL = 'pattern_external';
final public const USER_VERIFY_PATTERN_EXTERNAL_INT = 0x00001000;
final public const USER_VERIFY_NONE = 'none';
final public const USER_VERIFY_NONE_INT = 0x00000200;
final public const USER_VERIFY_ALL = 'all';
final public const USER_VERIFY_ALL_INT = 0x00000400;
final public const USER_VERIFICATION_METHODS = [
self::USER_VERIFY_PRESENCE_INTERNAL,
self::USER_VERIFY_FINGERPRINT_INTERNAL,
self::USER_VERIFY_PASSCODE_INTERNAL,
self::USER_VERIFY_VOICEPRINT_INTERNAL,
self::USER_VERIFY_FACEPRINT_INTERNAL,
self::USER_VERIFY_LOCATION_INTERNAL,
self::USER_VERIFY_EYEPRINT_INTERNAL,
self::USER_VERIFY_PATTERN_INTERNAL,
self::USER_VERIFY_HANDPRINT_INTERNAL,
self::USER_VERIFY_PASSCODE_EXTERNAL,
self::USER_VERIFY_PATTERN_EXTERNAL,
self::USER_VERIFY_NONE,
self::USER_VERIFY_ALL,
];
final public const USER_VERIFICATION_METHODS_INT = [
self::USER_VERIFY_PRESENCE_INTERNAL_INT,
self::USER_VERIFY_FINGERPRINT_INTERNAL_INT,
self::USER_VERIFY_PASSCODE_INTERNAL_INT,
self::USER_VERIFY_VOICEPRINT_INTERNAL_INT,
self::USER_VERIFY_FACEPRINT_INTERNAL_INT,
self::USER_VERIFY_LOCATION_INTERNAL_INT,
self::USER_VERIFY_EYEPRINT_INTERNAL_INT,
self::USER_VERIFY_PATTERN_INTERNAL_INT,
self::USER_VERIFY_HANDPRINT_INTERNAL_INT,
self::USER_VERIFY_PASSCODE_EXTERNAL_INT,
self::USER_VERIFY_PATTERN_EXTERNAL_INT,
self::USER_VERIFY_NONE_INT,
self::USER_VERIFY_ALL_INT,
];
public function __construct(
public readonly string $userVerificationMethod,
public readonly ?CodeAccuracyDescriptor $caDesc = null,
public readonly ?BiometricAccuracyDescriptor $baDesc = null,
public readonly ?PatternAccuracyDescriptor $paDesc = null
) {
$userVerificationMethod >= 0 || throw MetadataStatementLoadingException::create(
'The parameter "userVerificationMethod" is invalid'
);
}
public static function create(
string $userVerificationMethod,
?CodeAccuracyDescriptor $caDesc = null,
?BiometricAccuracyDescriptor $baDesc = null,
?PatternAccuracyDescriptor $paDesc = null
): self {
return new self($userVerificationMethod, $caDesc, $baDesc, $paDesc);
}
public function userPresence(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_PRESENCE_INTERNAL;
}
public function fingerprint(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_FINGERPRINT_INTERNAL;
}
public function passcodeInternal(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_PASSCODE_INTERNAL;
}
public function voicePrint(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_VOICEPRINT_INTERNAL;
}
public function facePrint(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_FACEPRINT_INTERNAL;
}
public function location(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_LOCATION_INTERNAL;
}
public function eyePrint(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_EYEPRINT_INTERNAL;
}
public function patternInternal(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_PATTERN_INTERNAL;
}
public function handprint(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_HANDPRINT_INTERNAL;
}
public function passcodeExternal(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_PASSCODE_EXTERNAL;
}
public function patternExternal(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_PATTERN_EXTERNAL;
}
public function none(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_NONE;
}
public function all(): bool
{
return $this->userVerificationMethod === self::USER_VERIFY_ALL;
}
}

View file

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService\Statement;
use Webauthn\Exception\MetadataStatementLoadingException;
readonly class Version
{
public function __construct(
public ?int $major,
public ?int $minor
) {
if ($major === null && $minor === null) {
throw MetadataStatementLoadingException::create('Invalid data. Must contain at least one item');
}
$major >= 0 || throw MetadataStatementLoadingException::create('Invalid argument "major"');
$minor >= 0 || throw MetadataStatementLoadingException::create('Invalid argument "minor"');
}
public static function create(?int $major, ?int $minor): self
{
return new self($major, $minor);
}
}

View file

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Webauthn\MetadataService;
use Webauthn\MetadataService\Statement\StatusReport;
interface StatusReportRepository
{
/**
* @return StatusReport[]
*/
public function findStatusReportsByAAGUID(string $aaguid): array;
}