Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing pieces for moving to 5.0.0 #499

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 26 additions & 66 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ parameters:

-
message: "#^Cannot access offset 'options_builder' on mixed\\.$#"
count: 4
count: 2
path: src/symfony/src/DependencyInjection/WebauthnExtension.php

-
Expand Down Expand Up @@ -981,11 +981,6 @@ parameters:
count: 2
path: src/symfony/src/DependencyInjection/WebauthnExtension.php

-
message: "#^Cannot access offset 'types' on mixed\\.$#"
count: 3
path: src/symfony/src/DependencyInjection/WebauthnExtension.php

-
message: "#^Cannot access offset 'user_entity_guesser' on mixed\\.$#"
count: 1
Expand Down Expand Up @@ -1017,6 +1012,11 @@ parameters:
count: 1
path: src/symfony/src/DependencyInjection/WebauthnExtension.php

-
message: "#^Method Webauthn\\\\Bundle\\\\DependencyInjection\\\\WebauthnExtension\\:\\:getDoctrineBundleConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/symfony/src/DependencyInjection/WebauthnExtension.php

-
message: "#^Parameter \\#1 \\$id of class Symfony\\\\Component\\\\DependencyInjection\\\\Reference constructor expects string, mixed given\\.$#"
count: 15
Expand Down Expand Up @@ -1122,6 +1122,11 @@ parameters:
count: 1
path: src/symfony/src/Repository/DoctrineCredentialSourceRepository.php

-
message: "#^Class Webauthn\\\\Bundle\\\\Repository\\\\PublicKeyCredentialSourceRepository extends generic class Webauthn\\\\Bundle\\\\Repository\\\\DoctrineCredentialSourceRepository but does not specify its types\\: T$#"
count: 1
path: src/symfony/src/Repository/PublicKeyCredentialSourceRepository.php

-
message: "#^Fetching class constant class of deprecated class Webauthn\\\\PublicKeyCredentialSourceRepository\\.$#"
count: 2
Expand Down Expand Up @@ -1462,26 +1467,6 @@ parameters:
count: 1
path: src/symfony/src/Service/AuthenticatorAttestationResponseValidator.php

-
message: "#^@readonly property Webauthn\\\\PublicKeyCredentialCreationOptions\\:\\:\\$attestation is assigned outside of its declaring class\\.$#"
count: 1
path: src/symfony/src/Service/PublicKeyCredentialCreationOptionsFactory.php

-
message: "#^@readonly property Webauthn\\\\PublicKeyCredentialCreationOptions\\:\\:\\$authenticatorSelection is assigned outside of its declaring class\\.$#"
count: 1
path: src/symfony/src/Service/PublicKeyCredentialCreationOptionsFactory.php

-
message: "#^@readonly property Webauthn\\\\PublicKeyCredentialCreationOptions\\:\\:\\$excludeCredentials is assigned outside of its declaring class\\.$#"
count: 1
path: src/symfony/src/Service/PublicKeyCredentialCreationOptionsFactory.php

-
message: "#^@readonly property Webauthn\\\\PublicKeyCredentialOptions\\:\\:\\$timeout is assigned outside of its declaring class\\.$#"
count: 1
path: src/symfony/src/Service/PublicKeyCredentialCreationOptionsFactory.php

-
message: "#^Cannot access offset 'attestation…' on mixed\\.$#"
count: 1
Expand Down Expand Up @@ -1612,21 +1597,6 @@ parameters:
count: 1
path: src/symfony/src/Service/PublicKeyCredentialCreationOptionsFactory.php

-
message: "#^Property Webauthn\\\\PublicKeyCredentialCreationOptions\\:\\:\\$attestation \\(string\\|null\\) does not accept mixed\\.$#"
count: 1
path: src/symfony/src/Service/PublicKeyCredentialCreationOptionsFactory.php

-
message: "#^Property Webauthn\\\\PublicKeyCredentialOptions\\:\\:\\$timeout \\(int\\<1, max\\>\\|null\\) does not accept mixed\\.$#"
count: 1
path: src/symfony/src/Service/PublicKeyCredentialCreationOptionsFactory.php

-
message: "#^@readonly property Webauthn\\\\PublicKeyCredentialOptions\\:\\:\\$timeout is assigned outside of its declaring class\\.$#"
count: 1
path: src/symfony/src/Service/PublicKeyCredentialRequestOptionsFactory.php

-
message: "#^Cannot access offset 'challenge_length' on mixed\\.$#"
count: 1
Expand Down Expand Up @@ -1672,21 +1642,6 @@ parameters:
count: 1
path: src/symfony/src/Service/PublicKeyCredentialRequestOptionsFactory.php

-
message: "#^Property Webauthn\\\\PublicKeyCredentialOptions\\:\\:\\$timeout \\(int\\<1, max\\>\\|null\\) does not accept mixed\\.$#"
count: 1
path: src/symfony/src/Service/PublicKeyCredentialRequestOptionsFactory.php

-
message: "#^Property Webauthn\\\\PublicKeyCredentialRequestOptions\\:\\:\\$rpId \\(string\\|null\\) does not accept mixed\\.$#"
count: 1
path: src/symfony/src/Service/PublicKeyCredentialRequestOptionsFactory.php

-
message: "#^Property Webauthn\\\\PublicKeyCredentialRequestOptions\\:\\:\\$userVerification \\(string\\|null\\) does not accept mixed\\.$#"
count: 1
path: src/symfony/src/Service/PublicKeyCredentialRequestOptionsFactory.php

-
message: "#^Cannot access offset 'x5c' on mixed\\.$#"
count: 1
Expand Down Expand Up @@ -1742,11 +1697,6 @@ parameters:
count: 1
path: src/webauthn/src/AttestationStatement/AndroidSafetyNetAttestationStatementSupport.php

-
message: "#^Cannot access offset 'response'\\|'ver' on mixed\\.$#"
count: 1
path: src/webauthn/src/AttestationStatement/AndroidSafetyNetAttestationStatementSupport.php

-
message: "#^Cannot call method createRequest\\(\\) on Psr\\\\Http\\\\Message\\\\RequestFactoryInterface\\|null\\.$#"
count: 1
Expand Down Expand Up @@ -2448,11 +2398,6 @@ parameters:
count: 1
path: src/webauthn/src/Denormalizer/PublicKeyCredentialOptionsDenormalizer.php

-
message: "#^Cannot access offset 'credentialPublicKey'\\|'publicKeyCredential…'\\|'userHandle' on mixed\\.$#"
count: 2
path: src/webauthn/src/Denormalizer/PublicKeyCredentialSourceDenormalizer.php

-
message: "#^Method Webauthn\\\\Denormalizer\\\\PublicKeyCredentialSourceDenormalizer\\:\\:denormalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -2488,6 +2433,21 @@ parameters:
count: 1
path: src/webauthn/src/Denormalizer/PublicKeyCredentialUserEntityDenormalizer.php

-
message: "#^Method Webauthn\\\\Denormalizer\\\\TrustPathDenormalizer\\:\\:denormalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/webauthn/src/Denormalizer/TrustPathDenormalizer.php

-
message: "#^Method Webauthn\\\\Denormalizer\\\\TrustPathDenormalizer\\:\\:supportsDenormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/webauthn/src/Denormalizer/TrustPathDenormalizer.php

-
message: "#^Parameter \\#2 \\$array of function array_key_exists expects array, mixed given\\.$#"
count: 1
path: src/webauthn/src/Denormalizer/TrustPathDenormalizer.php

-
message: "#^@readonly property Webauthn\\\\PublicKeyCredentialCreationOptions\\:\\:\\$attestation is assigned outside of the constructor\\.$#"
count: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

final class MetadataStatementSerializerFactory
{
private const PACKAGE_SYMFONY_SERIALIZER = 'symfony/serializer';

private const PACKAGE_PHPDOCUMENTOR_REFLECTION_DOCBLOCK = 'phpdocumentor/reflection-docblock';

public static function create(): ?SerializerInterface
{
foreach (self::getRequiredSerializerClasses() as $class => $package) {
Expand Down Expand Up @@ -45,14 +49,14 @@ public static function create(): ?SerializerInterface
private static function getRequiredSerializerClasses(): array
{
return [
UidNormalizer::class => 'symfony/serializer',
ArrayDenormalizer::class => 'symfony/serializer',
ObjectNormalizer::class => 'symfony/serializer',
PropertyInfoExtractor::class => 'symfony/serializer',
PhpDocExtractor::class => 'phpdocumentor/reflection-docblock',
ReflectionExtractor::class => 'symfony/serializer',
JsonEncoder::class => 'symfony/serializer',
Serializer::class => 'symfony/serializer',
UidNormalizer::class => self::PACKAGE_SYMFONY_SERIALIZER,
ArrayDenormalizer::class => self::PACKAGE_SYMFONY_SERIALIZER,
ObjectNormalizer::class => self::PACKAGE_SYMFONY_SERIALIZER,
PropertyInfoExtractor::class => self::PACKAGE_SYMFONY_SERIALIZER,
PhpDocExtractor::class => self::PACKAGE_PHPDOCUMENTOR_REFLECTION_DOCBLOCK,
ReflectionExtractor::class => self::PACKAGE_SYMFONY_SERIALIZER,
JsonEncoder::class => self::PACKAGE_SYMFONY_SERIALIZER,
Serializer::class => self::PACKAGE_SYMFONY_SERIALIZER,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function create(
int $compression,
int $filter,
int $interlace,
array $plte
array $plte = []
): self {
return new self($width, $height, $bitDepth, $colorType, $compression, $filter, $interlace, $plte);
}
Expand Down
27 changes: 15 additions & 12 deletions src/symfony/src/DependencyInjection/WebauthnExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,7 @@ public function getConfiguration(array $config, ContainerBuilder $container): ?C

public function prepend(ContainerBuilder $container): void
{
if (! $container->hasParameter('kernel.bundles')) {
return;
}
$bundles = $container->getParameter('kernel.bundles');
if (! is_array($bundles) || ! array_key_exists('DoctrineBundle', $bundles)) {
return;
}
$configs = $container->getExtensionConfig('doctrine');
if (count($configs) === 0) {
return;
}
$config = current($configs);
$config = $this->getDoctrineBundleConfiguration($container);
if (! is_array($config)) {
return;
}
Expand All @@ -157,6 +146,20 @@ public function prepend(ContainerBuilder $container): void
$container->prependExtensionConfig('doctrine', $config);
}

private function getDoctrineBundleConfiguration(ContainerBuilder $container): ?array
{
if (! $container->hasParameter('kernel.bundles')) {
return null;
}
$bundles = $container->getParameter('kernel.bundles');
if (! is_array($bundles) || ! array_key_exists('DoctrineBundle', $bundles)) {
return null;
}
$configs = $container->getExtensionConfig('doctrine');

return count($configs) === 0 ? null : current($configs);
}

/**
* @param mixed[] $config
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use Webauthn\PublicKeyCredentialRpEntity;
use Webauthn\PublicKeyCredentialUserEntity;
use function array_key_exists;
use function gettype;
use function is_int;
use function is_string;

final class PublicKeyCredentialCreationOptionsFactory implements CanDispatchEvents
{
Expand Down Expand Up @@ -64,20 +67,33 @@ public function create(
));
$profile = $this->profiles[$key];

$timeout = $profile['timeout'] ?? null;
$timeout === null || (is_int($timeout) && $timeout > 1) || throw new InvalidArgumentException(sprintf(
'The profile with key "%s" has an invalid timeout value. Expected a positive integer greater than 0, got "%s".',
$key,
gettype($timeout)
));
$attestation = $attestationConveyance ?? $profile['attestation_conveyance'] ?? null;
$attestation === null || is_string($attestation) || throw new InvalidArgumentException(sprintf(
'The profile with key "%s" has an invalid attestation_conveyance value. Expected a string or null, got "%s".',
$key,
gettype($attestation)
));

$options = PublicKeyCredentialCreationOptions
::create(
$this->createRpEntity($profile),
$userEntity,
random_bytes($profile['challenge_length']),
$this->createCredentialParameters($profile)
$this->createCredentialParameters($profile),
authenticatorSelection: $authenticatorSelection ?? $this->createAuthenticatorSelectionCriteria(
$profile
),
attestation: $attestation,
excludeCredentials: $excludeCredentials,
timeout: $timeout,
extensions: $authenticationExtensionsClientInputs ?? $this->createExtensions($profile)
);
$options->excludeCredentials = $excludeCredentials;
$options->authenticatorSelection = $authenticatorSelection ?? $this->createAuthenticatorSelectionCriteria(
$profile
);
$options->attestation = $attestationConveyance ?? $profile['attestation_conveyance'];
$options->extensions = $authenticationExtensionsClientInputs ?? $this->createExtensions($profile);
$options->timeout = $profile['timeout'];
$this->eventDispatcher->dispatch(PublicKeyCredentialCreationOptionsCreatedEvent::create($options));

return $options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use Webauthn\PublicKeyCredentialDescriptor;
use Webauthn\PublicKeyCredentialRequestOptions;
use function array_key_exists;
use function gettype;
use function is_int;
use function is_string;

final class PublicKeyCredentialRequestOptionsFactory implements CanDispatchEvents
{
Expand Down Expand Up @@ -52,13 +55,33 @@ public function create(
$key
));
$profile = $this->profiles[$key];
$rpId = $profile['rp_id'] ?? null;
$rpId === null || is_string($rpId) || throw new InvalidArgumentException(sprintf(
'The profile with key "%s" has an invalid rp_id value. Expected a string or null, got "%s".',
$key,
gettype($rpId)
));
$timeout = $profile['timeout'] ?? null;
$timeout === null || (is_int($timeout) && $timeout > 1) || throw new InvalidArgumentException(sprintf(
'The profile with key "%s" has an invalid timeout value. Expected a positive integer greater than 0, got "%s".',
$key,
gettype($timeout)
));
$userVerification ??= $profile['user_verification'] ?? null;
$userVerification === null || is_string($userVerification) || throw new InvalidArgumentException(sprintf(
'The profile with key "%s" has an invalid attestation_conveyance value. Expected a string or null, got "%s".',
$key,
gettype($userVerification)
));

$options = PublicKeyCredentialRequestOptions::create(random_bytes($profile['challenge_length']));
$options->rpId = $profile['rp_id'];
$options->userVerification = $userVerification ?? $profile['user_verification'];
$options->allowCredentials = $allowCredentials;
$options->timeout = $profile['timeout'];
$options->extensions = $authenticationExtensionsClientInputs ?? $this->createExtensions($profile);
$options = PublicKeyCredentialRequestOptions::create(
random_bytes($profile['challenge_length']),
rpId: $rpId,
allowCredentials: $allowCredentials,
userVerification: $userVerification,
timeout: $timeout,
extensions: $authenticationExtensionsClientInputs ?? $this->createExtensions($profile)
);
$this->eventDispatcher->dispatch(PublicKeyCredentialRequestOptionsCreatedEvent::create($options));

return $options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ public function name(): string
public function load(array $attestation): AttestationStatement
{
array_key_exists('attStmt', $attestation) || throw AttestationStatementLoadingException::create(
$attestation,
'Invalid attestation object'
$attestation
);
foreach (['ver', 'response'] as $key) {
array_key_exists($key, $attestation['attStmt']) || throw AttestationStatementLoadingException::create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(
*/
public static function create(array $attestationStatementSupports = []): self
{
return new self();
return new self($attestationStatementSupports);
}

public function add(AttestationStatementSupport $attestationStatementSupport): void
Expand Down
8 changes: 4 additions & 4 deletions src/webauthn/src/AuthenticatorData.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function __construct(
public readonly string $rpIdHash,
public readonly string $flags,
public readonly int $signCount,
public readonly ?AttestedCredentialData $attestedCredentialData,
public readonly ?AuthenticationExtensionsClientOutputs $extensions
public readonly null|AttestedCredentialData $attestedCredentialData,
public readonly null|AuthenticationExtensionsClientOutputs $extensions
) {
}

Expand All @@ -47,8 +47,8 @@ public static function create(
string $rpIdHash,
string $flags,
int $signCount,
?AttestedCredentialData $attestedCredentialData = null,
?AuthenticationExtensionsClientOutputs $extensions = null
null|AttestedCredentialData $attestedCredentialData = null,
null|AuthenticationExtensionsClientOutputs $extensions = null
): self {
return new self($authData, $rpIdHash, $flags, $signCount, $attestedCredentialData, $extensions);
}
Expand Down
Loading
Loading