Debian Codegraph @

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

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Webauthn\CeremonyStep;
6
7 use function count;
8 use function trigger_deprecation;
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 class CheckAllowedCredentialList implements CeremonyStep
18 {
19 public function process(
20 CredentialRecord $credentialRecord,
21 AuthenticatorAssertionResponse|AuthenticatorAttestationResponse $authenticatorResponse,
22 PublicKeyCredentialRequestOptions|PublicKeyCredentialCreationOptions $publicKeyCredentialOptions,
23 ?string $userHandle,
24 string $host
25 ): void {
26 if ($credentialRecord instanceof PublicKeyCredentialSource) {
27 trigger_deprecation(
28 'web-auth/webauthn-lib',
29 '5.3',
30 'Passing a PublicKeyCredentialSource to "%s::process()" is deprecated, pass a CredentialRecord instead.',
31 self::class
32 );
33 }
34 if (! $publicKeyCredentialOptions instanceof PublicKeyCredentialRequestOptions) {
35 return;
36 }
37 if (count($publicKeyCredentialOptions->allowCredentials) === 0) {
38 return;
39 }
40
41 foreach ($publicKeyCredentialOptions->allowCredentials as $allowedCredential) {
42 if (hash_equals($allowedCredential->id, $credentialRecord->publicKeyCredentialId)) {
43 return;
44 }
45 }
46 throw AuthenticatorResponseVerificationException::create('The credential ID is not allowed.');
47 }
48 }