Inline Webauthn\Server::loadAndCheckAttestationResponse()

The Webauthn\Server was removed in web-auth/webauthn-lib v4.

Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
Maurício Meneghini Fauth 2024-08-25 21:03:53 -03:00
parent cb97cd152d
commit 4f9cd29be0
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8

View File

@ -17,6 +17,8 @@ use Webauthn\AuthenticationExtensions\AuthenticationExtensionsClientInputs;
use Webauthn\AuthenticationExtensions\ExtensionOutputCheckerHandler;
use Webauthn\AuthenticatorAssertionResponse;
use Webauthn\AuthenticatorAssertionResponseValidator;
use Webauthn\AuthenticatorAttestationResponse;
use Webauthn\AuthenticatorAttestationResponseValidator;
use Webauthn\AuthenticatorSelectionCriteria;
use Webauthn\PublicKeyCredentialCreationOptions;
use Webauthn\PublicKeyCredentialDescriptor;
@ -27,7 +29,6 @@ use Webauthn\PublicKeyCredentialRpEntity;
use Webauthn\PublicKeyCredentialSource;
use Webauthn\PublicKeyCredentialSourceRepository;
use Webauthn\PublicKeyCredentialUserEntity;
use Webauthn\Server as WebauthnServer;
use Webauthn\TokenBinding\IgnoreTokenBindingHandler;
use Webauthn\TrustPath\EmptyTrustPath;
use Webmozart\Assert\Assert;
@ -237,9 +238,7 @@ final class WebauthnLibServer implements Server
Assert::isArray($creationOptions['user']);
Assert::keyExists($creationOptions['user'], 'id');
$host = $request->getUri()->getHost();
$relyingPartyEntity = new PublicKeyCredentialRpEntity('phpMyAdmin (' . $host . ')', $host);
$publicKeyCredentialSourceRepository = $this->createPublicKeyCredentialSourceRepository();
$server = new WebauthnServer($relyingPartyEntity, $publicKeyCredentialSourceRepository);
$creationOptionsArray = [
'rp' => ['name' => 'phpMyAdmin (' . $host . ')', 'id' => $host],
'pubKeyCredParams' => [
@ -266,8 +265,29 @@ final class WebauthnLibServer implements Server
];
$credentialCreationOptions = PublicKeyCredentialCreationOptions::createFromArray($creationOptionsArray);
Assert::isInstanceOf($credentialCreationOptions, PublicKeyCredentialCreationOptions::class);
$publicKeyCredentialSource = $server->loadAndCheckAttestationResponse(
$attestationResponse,
$attestationStatementSupportManager = new AttestationStatementSupportManager();
$attestationStatementSupportManager->add(new NoneAttestationStatementSupport());
$attestationObjectLoader = AttestationObjectLoader::create($attestationStatementSupportManager);
$publicKeyCredentialLoader = PublicKeyCredentialLoader::create($attestationObjectLoader);
$publicKeyCredential = $publicKeyCredentialLoader->load($attestationResponse);
$authenticatorResponse = $publicKeyCredential->getResponse();
Assert::isInstanceOf(
$authenticatorResponse,
AuthenticatorAttestationResponse::class,
'Not an authenticator attestation response',
);
$authenticatorAttestationResponseValidator = new AuthenticatorAttestationResponseValidator(
$attestationStatementSupportManager,
$publicKeyCredentialSourceRepository,
new IgnoreTokenBindingHandler(),
new ExtensionOutputCheckerHandler(),
);
$publicKeyCredentialSource = $authenticatorAttestationResponseValidator->check(
$authenticatorResponse,
$credentialCreationOptions,
$request,
);