Skip to content

Commit

Permalink
Merge pull request #587 from web-auth/bugs/v2-compliance
Browse files Browse the repository at this point in the history
Refactor authenticator response identification logic
  • Loading branch information
Spomky authored Apr 8, 2024
2 parents 670d9e9 + c14a23d commit b9c4669
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@ final class AuthenticatorResponseDenormalizer implements DenormalizerInterface,
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
{
$realType = match (true) {
array_key_exists('attestationObject', $data) && ! array_key_exists(
'signature',
$data
) => AuthenticatorAttestationResponse::class,
array_key_exists('authenticatorData', $data) && array_key_exists(
'signature',
$data
) => AuthenticatorAssertionResponse::class,
array_key_exists('attestationObject', $data) => AuthenticatorAttestationResponse::class,
array_key_exists('signature', $data) => AuthenticatorAssertionResponse::class,
default => throw InvalidDataException::create($data, 'Unable to create the response object'),
};

Expand Down
6 changes: 3 additions & 3 deletions src/webauthn/src/PublicKeyCredentialLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ private function createResponse(array $response): AuthenticatorResponse
return $this->serializer->deserialize($response, AuthenticatorResponse::class, 'json');
}
switch (true) {
case ! array_key_exists('authenticatorData', $response) && ! array_key_exists('signature', $response):
case array_key_exists('attestationObject', $response):
$attestationObject = $this->attestationObjectLoader->load($response['attestationObject']);

return AuthenticatorAttestationResponse::create(CollectedClientData::createFormJson(
$response['clientDataJSON']
), $attestationObject, $transports);
case array_key_exists('authenticatorData', $response) && array_key_exists('signature', $response):
case array_key_exists('signature', $response):
$authDataLoader = AuthenticatorDataLoader::create();
$authData = Base64UrlSafe::decodeNoPadding($response['authenticatorData']);
$authData = Base64UrlSafe::decodeNoPadding($response['authenticatorData'] ?? '');
$authenticatorData = $authDataLoader->load($authData);

try {
Expand Down

0 comments on commit b9c4669

Please sign in to comment.