2021-08-08 16:23:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
|
|
|
use Webauthn\PublicKeyCredentialSource;
|
|
|
|
use Webauthn\PublicKeyCredentialDescriptor;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
2021-08-08 17:48:35 +00:00
|
|
|
class SecurityKey extends Model
|
2021-08-08 16:23:02 +00:00
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
|
2021-08-08 17:48:35 +00:00
|
|
|
public const RESOURCE_NAME = 'security_key';
|
2021-08-08 16:23:02 +00:00
|
|
|
|
2021-08-08 17:48:35 +00:00
|
|
|
protected $casts = [
|
2021-08-08 16:23:02 +00:00
|
|
|
'user_id' => 'int',
|
|
|
|
'transports' => 'array',
|
|
|
|
'trust_path' => 'array',
|
|
|
|
'other_ui' => 'array',
|
|
|
|
];
|
|
|
|
|
2021-08-08 17:48:35 +00:00
|
|
|
protected $guarded = [
|
|
|
|
'uuid',
|
|
|
|
'user_id',
|
|
|
|
];
|
|
|
|
|
2021-08-08 16:23:02 +00:00
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toCredentialsDescriptor()
|
|
|
|
{
|
|
|
|
return new PublicKeyCredentialDescriptor(
|
|
|
|
$this->type,
|
|
|
|
$this->public_key_id,
|
|
|
|
$this->transports
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toCredentialSource(): PublicKeyCredentialSource
|
|
|
|
{
|
|
|
|
return PublicKeyCredentialSource::createFromArray([
|
|
|
|
'publicKeyCredentialId' => $this->public_key_id,
|
|
|
|
'type' => $this->type,
|
|
|
|
'transports' => $this->transports,
|
|
|
|
'attestationType' => $this->attestation_type,
|
|
|
|
// 'trustPath' => $key->trustPath->jsonSerialize(),
|
|
|
|
'aaguid' => $this->aaguid,
|
|
|
|
'credentialPublicKey' => $this->public_key,
|
|
|
|
'userHandle' => $this->user_handle,
|
|
|
|
'counter' => $this->counter,
|
|
|
|
'otherUI' => $this->other_ui,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|