Skip to content

Commit

Permalink
More deprecations removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Nov 18, 2023
1 parent b4b2bb2 commit 62f6a48
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,9 @@ public function getFromRequest(

$excludedCredentials = $this->getCredentials($userEntity);
$optionsRequest = $this->getServerPublicKeyCredentialCreationOptionsRequest($content);
$authenticatorSelectionData = $optionsRequest->authenticatorSelection;
$authenticatorSelection = null;
if (is_array($authenticatorSelectionData)) {
$authenticatorSelection = AuthenticatorSelectionCriteria::createFromArray($authenticatorSelectionData);
} elseif ($optionsRequest->userVerification !== null || $optionsRequest->residentKey !== null || $optionsRequest->authenticatorAttachment !== null) {
if ($optionsRequest->userVerification !== null || $optionsRequest->residentKey !== null || $optionsRequest->authenticatorAttachment !== null) {
$residentKey = $optionsRequest->residentKey ?? null;
$requireResidentKey = $optionsRequest->requireResidentKey !== null ? filter_var(
$optionsRequest->requireResidentKey,
FILTER_VALIDATE_BOOLEAN
) : null;

$authenticatorSelection = AuthenticatorSelectionCriteria::create(
$optionsRequest->authenticatorAttachment,
$optionsRequest->userVerification ?? AuthenticatorSelectionCriteria::USER_VERIFICATION_REQUIREMENT_PREFERRED,
Expand Down
3 changes: 1 addition & 2 deletions src/symfony/src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Webauthn\Bundle\Repository\DummyPublicKeyCredentialSourceRepository;
use Webauthn\Bundle\Repository\DummyPublicKeyCredentialUserEntityRepository;
use Webauthn\Bundle\Repository\PublicKeyCredentialSourceRepositoryInterface;
use Webauthn\Bundle\Repository\PublicKeyCredentialUserEntityRepositoryInterface;
use Webauthn\Bundle\Routing\Loader;
use Webauthn\Bundle\Service\DefaultFailureHandler;
use Webauthn\Bundle\Service\DefaultSuccessHandler;
Expand Down Expand Up @@ -124,7 +123,7 @@
->args([
service(SerializerInterface::class),
service(AuthenticatorAssertionResponseValidator::class),
service(PublicKeyCredentialUserEntityRepositoryInterface::class),
service(PublicKeyCredentialSourceRepositoryInterface::class),
]);

$container
Expand Down
16 changes: 11 additions & 5 deletions src/webauthn/src/AuthenticatorSelectionCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ class AuthenticatorSelectionCriteria implements JsonSerializable
self::AUTHENTICATOR_ATTACHMENT_CROSS_PLATFORM,
];

final public const USER_VERIFICATION_REQUIREMENT_NO_PREFERENCE = null;

final public const USER_VERIFICATION_REQUIREMENT_REQUIRED = 'required';

final public const USER_VERIFICATION_REQUIREMENT_PREFERRED = 'preferred';

final public const USER_VERIFICATION_REQUIREMENT_DISCOURAGED = 'discouraged';

final public const USER_VERIFICATION_REQUIREMENTS = [
self::USER_VERIFICATION_REQUIREMENT_NO_PREFERENCE,
self::USER_VERIFICATION_REQUIREMENT_REQUIRED,
self::USER_VERIFICATION_REQUIREMENT_PREFERRED,
self::USER_VERIFICATION_REQUIREMENT_DISCOURAGED,
Expand All @@ -53,8 +56,8 @@ class AuthenticatorSelectionCriteria implements JsonSerializable

public function __construct(
public null|string $authenticatorAttachment = null,
public string $userVerification = self::USER_VERIFICATION_REQUIREMENT_PREFERRED,
public null|string $residentKey = self::RESIDENT_KEY_REQUIREMENT_PREFERRED,
public null|string $userVerification = self::USER_VERIFICATION_REQUIREMENT_NO_PREFERENCE,
public null|string $residentKey = self::RESIDENT_KEY_REQUIREMENT_NO_PREFERENCE,
) {
in_array($authenticatorAttachment, self::AUTHENTICATOR_ATTACHMENTS, true) || throw new InvalidArgumentException(
'Invalid authenticator attachment'
Expand All @@ -66,7 +69,7 @@ public function __construct(
'Invalid resident key'
);

$this->requireResidentKey = $residentKey === self::RESIDENT_KEY_REQUIREMENT_REQUIRED;
$this->requireResidentKey = $residentKey === null ? null : $residentKey === self::RESIDENT_KEY_REQUIREMENT_REQUIRED;
}

public static function create(
Expand All @@ -86,9 +89,12 @@ public function jsonSerialize(): array
'requireResidentKey' => $this->requireResidentKey,
'userVerification' => $this->userVerification,
'residentKey' => $this->residentKey,
'authenticatorAttachment' => $this->authenticatorAttachment,
];
if ($this->authenticatorAttachment !== null) {
$json['authenticatorAttachment'] = $this->authenticatorAttachment;
foreach ($json as $key => $value) {
if ($value === null) {
unset($json[$key]);
}
}

return $json;
Expand Down
6 changes: 3 additions & 3 deletions tests/library/Unit/AuthenticatorSelectionCriteriaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class AuthenticatorSelectionCriteriaTest extends AbstractTestCase
public function anAuthenticatorSelectionCriteriaCanBeCreatedAndValueAccessed(): void
{
// Given
$expectedJson = '{"requireResidentKey":false,"userVerification":"required","residentKey":"preferred","authenticatorAttachment":"platform"}';
$expectedJson = '{"userVerification":"required","authenticatorAttachment":"platform"}';
$authenticatorSelectionCriteria = AuthenticatorSelectionCriteria::create(
AuthenticatorSelectionCriteria::AUTHENTICATOR_ATTACHMENT_PLATFORM,
AuthenticatorSelectionCriteria::USER_VERIFICATION_REQUIREMENT_REQUIRED,
Expand All @@ -38,8 +38,8 @@ public function anAuthenticatorSelectionCriteriaCanBeCreatedAndValueAccessed():
AuthenticatorSelectionCriteria::AUTHENTICATOR_ATTACHMENT_PLATFORM,
$data->authenticatorAttachment
);
static::assertFalse($data->requireResidentKey);
static::assertSame(AuthenticatorSelectionCriteria::RESIDENT_KEY_REQUIREMENT_PREFERRED, $data->residentKey);
static::assertNull($data->requireResidentKey);
static::assertSame(AuthenticatorSelectionCriteria::RESIDENT_KEY_REQUIREMENT_NO_PREFERENCE, $data->residentKey);
static::assertSame($expectedJson, json_encode($data, JSON_THROW_ON_ERROR));
static::assertSame($expectedJson, json_encode($authenticatorSelectionCriteria, JSON_THROW_ON_ERROR));
}
Expand Down
5 changes: 2 additions & 3 deletions tests/symfony/functional/Firewall/RegistrationAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Webauthn\Tests\Bundle\Functional\Firewall;

use Cose\Algorithms;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -27,6 +28,7 @@
*/
final class RegistrationAreaTest extends WebTestCase
{

#[Test]
public function aRequestWithoutUsernameCanBeProcessed(): void
{
Expand Down Expand Up @@ -196,9 +198,6 @@ public function aValidRequestProcessedWithExtensions(): void
], $data['authenticatorSelection']);
}

/**
* Note that this use case should fail on the attestation response step
*/
#[Test]
public function aRegistrationOptionsRequestCanBeAcceptedForExistingUsers(): void
{
Expand Down

0 comments on commit 62f6a48

Please sign in to comment.