Debian Codegraph @

lib/3rdParty/composer/web-auth/webauthn-lib/src/CeremonyStep/CheckAttestationFormatIsKnownAndValid.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Webauthn\CeremonyStep;
6
7 use function trigger_deprecation;
8 use Webauthn\AttestationStatement\AttestationStatementSupportManager;
9 use Webauthn\AuthenticatorAssertionResponse;
10 use Webauthn\AuthenticatorAttestationResponse;
11 use Webauthn\CredentialRecord;
12 use Webauthn\Exception\AuthenticatorResponseVerificationException;
13 use Webauthn\PublicKeyCredentialCreationOptions;
14 use Webauthn\PublicKeyCredentialRequestOptions;
15 use Webauthn\PublicKeyCredentialSource;
16
17 final readonly class CheckAttestationFormatIsKnownAndValid implements CeremonyStep
18 {
19 public function __construct(
20 private AttestationStatementSupportManager $attestationStatementSupportManager,
21 ) {
22 }
23
24 public function process(
25 CredentialRecord $credentialRecord,
26 AuthenticatorAssertionResponse|AuthenticatorAttestationResponse $authenticatorResponse,
27 PublicKeyCredentialRequestOptions|PublicKeyCredentialCreationOptions $publicKeyCredentialOptions,
28 ?string $userHandle,
29 string $host
30 ): void {
31 if ($credentialRecord instanceof PublicKeyCredentialSource) {
32 trigger_deprecation(
33 'web-auth/webauthn-lib',
34 '5.3',
35 'Passing a PublicKeyCredentialSource to "%s::process()" is deprecated, pass a CredentialRecord instead.',
36 self::class
37 );
38 }
39 $attestationObject = $authenticatorResponse->attestationObject;
40 if ($attestationObject === null) {
41 return;
42 }
43
44 $fmt = $attestationObject->attStmt
45 ->fmt;
46 $this->attestationStatementSupportManager->has(
47 $fmt
48 ) || throw AuthenticatorResponseVerificationException::create('Unsupported attestation statement format.');
49
50 $attestationStatementSupport = $this->attestationStatementSupportManager->get($fmt);
51 $clientDataJSONHash = hash('sha256', $authenticatorResponse->clientDataJSON ->rawData, true);
52 $attestationStatementSupport->isValid(
53 $clientDataJSONHash,
54 $attestationObject->attStmt,
55 $attestationObject->authData
56 ) || throw AuthenticatorResponseVerificationException::create('Invalid attestation statement.');
57 }
58 }