| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Webauthn\AttestationStatement; |
| 6 |
|
| 7 |
use function count; |
| 8 |
use function is_array; |
| 9 |
use function is_string; |
| 10 |
use Psr\EventDispatcher\EventDispatcherInterface; |
| 11 |
use Webauthn\AuthenticatorData; |
| 12 |
use Webauthn\Event\AttestationStatementLoaded; |
| 13 |
use Webauthn\Event\CanDispatchEvents; |
| 14 |
use Webauthn\Event\NullEventDispatcher; |
| 15 |
use Webauthn\Exception\AttestationStatementLoadingException; |
| 16 |
use Webauthn\TrustPath\EmptyTrustPath; |
| 17 |
|
| 18 |
final class NoneAttestationStatementSupport implements AttestationStatementSupport, CanDispatchEvents |
| 19 |
{ |
| 20 |
private EventDispatcherInterface $dispatcher; |
| 21 |
|
| 22 |
public function __construct() |
| 23 |
{ |
| 24 |
$this->dispatcher = new NullEventDispatcher(); |
| 25 |
} |
| 26 |
|
| 27 |
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void |
| 28 |
{ |
| 29 |
$this->dispatcher = $eventDispatcher; |
| 30 |
} |
| 31 |
|
| 32 |
public static function create(): self |
| 33 |
{ |
| 34 |
return new self(); |
| 35 |
} |
| 36 |
|
| 37 |
public function name(): string |
| 38 |
{ |
| 39 |
return 'none'; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public function load(array $attestation): AttestationStatement |
| 46 |
{ |
| 47 |
$format = $attestation['fmt'] ?? null; |
| 48 |
$attestationStatement = $attestation['attStmt'] ?? []; |
| 49 |
|
| 50 |
(is_string($format) && $format !== '') || throw AttestationStatementLoadingException::create( |
| 51 |
$attestation, |
| 52 |
'Invalid attestation object' |
| 53 |
); |
| 54 |
(is_array( |
| 55 |
$attestationStatement |
| 56 |
) && $attestationStatement === []) || throw AttestationStatementLoadingException::create( |
| 57 |
$attestation, |
| 58 |
'Invalid attestation object' |
| 59 |
); |
| 60 |
|
| 61 |
$attestationStatement = AttestationStatement::createNone( |
| 62 |
$format, |
| 63 |
$attestationStatement, |
| 64 |
EmptyTrustPath::create() |
| 65 |
); |
| 66 |
$this->dispatcher->dispatch(AttestationStatementLoaded::create($attestationStatement)); |
| 67 |
|
| 68 |
return $attestationStatement; |
| 69 |
} |
| 70 |
|
| 71 |
public function isValid( |
| 72 |
string $clientDataJSONHash, |
| 73 |
AttestationStatement $attestationStatement, |
| 74 |
AuthenticatorData $authenticatorData |
| 75 |
): bool { |
| 76 |
return count($attestationStatement->attStmt) === 0; |
| 77 |
} |
| 78 |
} |