Skip to content

Commit

Permalink
fix deprecation on webauthn
Browse files Browse the repository at this point in the history
  • Loading branch information
fiste788 committed Mar 27, 2024
1 parent 4cd2e9e commit 492f215
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 14 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"spomky-labs/web-push-lib": "v2.0.x-dev",
"symfony/css-selector": "^7.0",
"symfony/dom-crawler": "^7.0",
"symfony/serializer": "^7.0",
"symfony/uid": "^7.0",
"web-auth/webauthn-lib": "^4.7",
"web-token/jwt-library": "^3.3",
Expand Down Expand Up @@ -100,4 +101,4 @@
"test:typing": "@stan",
"test:unit": "@test"
}
}
}
97 changes: 96 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public function initialize(): void
}

/**
* @inheritDoc
* beforeRender callback.
*
* @param \Cake\Event\EventInterface<\Cake\Controller\Controller> $event Event.
* @return void
*/
public function beforeRender(EventInterface $event) {
$this->response = $this->response->withType('application/json');
Expand Down
40 changes: 29 additions & 11 deletions src/Service/WebauthnService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use GuzzleHttp\Psr7\HttpFactory;
use Psr\Http\Message\ServerRequestInterface;
use RuntimeException;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Uid\Uuid;
use Webauthn\AttestationStatement\AndroidKeyAttestationStatementSupport;
use Webauthn\AttestationStatement\AndroidSafetyNetAttestationStatementSupport;
Expand All @@ -37,6 +38,8 @@
use Webauthn\AuthenticatorAttestationResponse;
use Webauthn\AuthenticatorAttestationResponseValidator;
use Webauthn\AuthenticatorSelectionCriteria;
use Webauthn\Denormalizer\WebauthnSerializerFactory;
use Webauthn\PublicKeyCredential;
use Webauthn\PublicKeyCredentialCreationOptions;
use Webauthn\PublicKeyCredentialLoader;
use Webauthn\PublicKeyCredentialParameters;
Expand All @@ -57,14 +60,14 @@ class WebauthnService
use LocatorAwareTrait;
use ServiceAwareTrait;

protected PublicKeyCredentialLoader $publicKeyCredentialLoader;

protected AuthenticatorAttestationResponseValidator $authenticatorAttestationResponseValidator;

protected AuthenticatorAssertionResponseValidator $authenticatorAssertionResponseValidator;

protected PublicKeyCredentialSourceRepositoryService $PublicKeyCredentialSourceRepository;

protected SerializerInterface $serializer;

/**
* Costructor
*
Expand All @@ -77,11 +80,8 @@ public function __construct()
$this->loadService('PublicKeyCredentialSourceRepository');
$attestationStatementSupportManager = $this->createStatementSupportManager();

// Attestation Object Loader
$attestationObjectLoader = new AttestationObjectLoader($attestationStatementSupportManager);

// Public Key Credential Loader
$this->publicKeyCredentialLoader = new PublicKeyCredentialLoader($attestationObjectLoader);
$factory = new WebauthnSerializerFactory($attestationStatementSupportManager);
$this->serializer = $factory->create();

$this->authenticatorAttestationResponseValidator = new AuthenticatorAttestationResponseValidator(
$attestationStatementSupportManager,
Expand Down Expand Up @@ -291,12 +291,22 @@ public function signin(
ServerRequestInterface $request,
?string $userHandle = null
): PublicKeyCredentialSource {
$publicKeyCredentialRequestOptions = PublicKeyCredentialRequestOptions::createFromString($publicKey);
// $publicKeyCredentialRequestOptions = PublicKeyCredentialRequestOptions::createFromString();

$publicKeyCredentialRequestOptions = $this->serializer->deserialize(
$publicKey,
PublicKeyCredentialRequestOptions::class,
'json'
);

// Load the data
/** @var array<string, mixed> $body */
$body = $request->getParsedBody();
$publicKeyCredential = $this->publicKeyCredentialLoader->loadArray($body);
$publicKeyCredential = $this->serializer->deserialize(
$body,
PublicKeyCredential::class,
'json'
);
$authenticatorAssertionResponse = $publicKeyCredential->response;

// Check if the response is an Authenticator Assertion Response
Expand Down Expand Up @@ -397,12 +407,20 @@ public function registerRequest(ServerRequestInterface $request): PublicKeyCrede
public function registerResponse(ServerRequestInterface $request): ?EntityPublicKeyCredentialSource
{
$publicKey = (string)$request->getSession()->consume('User.PublicKey');
$publicKeyCredentialCreationOptions = PublicKeyCredentialCreationOptions::createFromString($publicKey);
$publicKeyCredentialCreationOptions = $this->serializer->deserialize(
$publicKey,
PublicKeyCredentialCreationOptions::class,
'json'
);

// Load the data
/** @var array<string, mixed> $body */
$body = $request->getParsedBody();
$publicKeyCredential = $this->publicKeyCredentialLoader->loadArray($body);
$publicKeyCredential = $this->serializer->deserialize(
$body,
PublicKeyCredential::class,
'json'
);
$authenticatorAttestationResponse = $publicKeyCredential->response;

// Check if the response is an Authenticator Attestation Response
Expand Down

0 comments on commit 492f215

Please sign in to comment.