2021-08-08 17:48:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Users\SecurityKeys;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\User;
|
|
|
|
use Pterodactyl\Models\SecurityKey;
|
|
|
|
use Webauthn\PublicKeyCredentialUserEntity;
|
|
|
|
use Webauthn\PublicKeyCredentialCreationOptions;
|
|
|
|
use Pterodactyl\Repositories\SecurityKeys\WebauthnServerRepository;
|
|
|
|
|
|
|
|
class CreatePublicKeyCredentialsService
|
|
|
|
{
|
|
|
|
protected WebauthnServerRepository $webauthnServerRepository;
|
|
|
|
|
|
|
|
public function __construct(WebauthnServerRepository $webauthnServerRepository)
|
|
|
|
{
|
|
|
|
$this->webauthnServerRepository = $webauthnServerRepository;
|
|
|
|
}
|
|
|
|
|
2021-08-08 18:24:11 +00:00
|
|
|
public function handle(User $user): PublicKeyCredentialCreationOptions
|
2021-08-08 17:48:35 +00:00
|
|
|
{
|
2021-08-08 18:24:11 +00:00
|
|
|
$entity = new PublicKeyCredentialUserEntity($user->username, $user->uuid, $user->email, null);
|
2021-08-08 17:48:35 +00:00
|
|
|
|
|
|
|
$excluded = $user->securityKeys->map(function (SecurityKey $key) {
|
2021-08-08 18:24:11 +00:00
|
|
|
return $key->public_key_credentials_descriptor;
|
2021-08-08 17:48:35 +00:00
|
|
|
})->values()->toArray();
|
|
|
|
|
|
|
|
$server = $this->webauthnServerRepository->getServer($user);
|
|
|
|
|
|
|
|
return $server->generatePublicKeyCredentialCreationOptions(
|
|
|
|
$entity,
|
|
|
|
PublicKeyCredentialCreationOptions::ATTESTATION_CONVEYANCE_PREFERENCE_NONE,
|
|
|
|
$excluded
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|