2019-12-14 16:35:19 +01:00
|
|
|
<?php
|
2020-02-22 18:14:36 +01:00
|
|
|
/**
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
*
|
2022-11-29 22:28:53 +01:00
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
2020-02-22 18:14:36 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-01-05 15:46:58 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-12-14 16:35:19 +01:00
|
|
|
namespace App\Entity\UserSystem;
|
|
|
|
|
|
|
|
use App\Entity\Base\TimestampTrait;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2022-10-03 23:09:50 +02:00
|
|
|
use Jbtronics\TFAWebauthn\Model\LegacyU2FKeyInterface;
|
2019-12-14 16:35:19 +01:00
|
|
|
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\Entity]
|
|
|
|
#[ORM\HasLifecycleCallbacks]
|
|
|
|
#[ORM\Table(name: 'u2f_keys')]
|
|
|
|
#[ORM\UniqueConstraint(name: 'user_unique', columns: ['user_id', 'key_handle'])]
|
2022-10-03 23:09:50 +02:00
|
|
|
class U2FKey implements LegacyU2FKeyInterface
|
2019-12-14 16:35:19 +01:00
|
|
|
{
|
|
|
|
use TimestampTrait;
|
|
|
|
|
|
|
|
/**
|
2020-04-09 15:17:46 +02:00
|
|
|
* We have to restrict the length here, as InnoDB only supports key index with max. 767 Bytes.
|
|
|
|
* Max length of keyhandles should be 128. (According to U2F_MAX_KH_SIZE in FIDO example C code).
|
2020-04-10 13:05:08 +02:00
|
|
|
*
|
|
|
|
*
|
2019-12-14 16:35:19 +01:00
|
|
|
* @var string
|
|
|
|
**/
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 128)]
|
2022-09-18 22:59:31 +02:00
|
|
|
public string $keyHandle;
|
2019-12-14 16:35:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
**/
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING)]
|
2022-09-18 22:59:31 +02:00
|
|
|
public string $publicKey;
|
2019-12-14 16:35:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
**/
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT)]
|
2022-09-18 22:59:31 +02:00
|
|
|
public string $certificate;
|
2019-12-14 16:35:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
**/
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING)]
|
2022-09-18 22:59:31 +02:00
|
|
|
public int $counter;
|
2019-12-14 16:35:19 +01:00
|
|
|
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\Id]
|
|
|
|
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)]
|
|
|
|
#[ORM\GeneratedValue]
|
2022-09-18 22:59:31 +02:00
|
|
|
protected int $id;
|
2020-01-05 15:46:58 +01:00
|
|
|
|
2019-12-14 16:35:19 +01:00
|
|
|
/**
|
2020-01-05 22:49:00 +01:00
|
|
|
* @var string
|
2019-12-14 16:35:19 +01:00
|
|
|
**/
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING)]
|
2022-09-18 22:59:31 +02:00
|
|
|
protected string $name;
|
2019-12-14 16:35:19 +01:00
|
|
|
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\ManyToOne(targetEntity: 'App\Entity\UserSystem\User', inversedBy: 'u2fKeys')]
|
2022-09-18 22:59:31 +02:00
|
|
|
protected ?User $user = null;
|
2019-12-14 16:35:19 +01:00
|
|
|
|
2022-08-14 19:09:07 +02:00
|
|
|
public function getKeyHandle(): string
|
2019-12-14 16:35:19 +01:00
|
|
|
{
|
|
|
|
return $this->keyHandle;
|
|
|
|
}
|
|
|
|
|
2022-08-14 19:09:07 +02:00
|
|
|
|
2020-02-01 19:42:28 +01:00
|
|
|
public function setKeyHandle($keyHandle): self
|
2019-12-14 16:35:19 +01:00
|
|
|
{
|
|
|
|
$this->keyHandle = $keyHandle;
|
2020-03-15 13:56:31 +01:00
|
|
|
|
2020-02-01 19:42:28 +01:00
|
|
|
return $this;
|
2019-12-14 16:35:19 +01:00
|
|
|
}
|
|
|
|
|
2022-08-14 19:09:07 +02:00
|
|
|
public function getPublicKey(): string
|
2019-12-14 16:35:19 +01:00
|
|
|
{
|
|
|
|
return $this->publicKey;
|
|
|
|
}
|
|
|
|
|
2020-02-01 19:42:28 +01:00
|
|
|
public function setPublicKey($publicKey): self
|
2019-12-14 16:35:19 +01:00
|
|
|
{
|
|
|
|
$this->publicKey = $publicKey;
|
2020-03-15 13:56:31 +01:00
|
|
|
|
2020-02-01 19:42:28 +01:00
|
|
|
return $this;
|
2019-12-14 16:35:19 +01:00
|
|
|
}
|
|
|
|
|
2022-08-14 19:09:07 +02:00
|
|
|
public function getCertificate(): string
|
2019-12-14 16:35:19 +01:00
|
|
|
{
|
|
|
|
return $this->certificate;
|
|
|
|
}
|
|
|
|
|
2020-02-01 19:42:28 +01:00
|
|
|
public function setCertificate($certificate): self
|
2019-12-14 16:35:19 +01:00
|
|
|
{
|
|
|
|
$this->certificate = $certificate;
|
2020-03-15 13:56:31 +01:00
|
|
|
|
2020-02-01 19:42:28 +01:00
|
|
|
return $this;
|
2019-12-14 16:35:19 +01:00
|
|
|
}
|
|
|
|
|
2022-08-14 19:09:07 +02:00
|
|
|
public function getCounter(): int
|
2019-12-14 16:35:19 +01:00
|
|
|
{
|
|
|
|
return $this->counter;
|
|
|
|
}
|
|
|
|
|
2020-02-01 19:42:28 +01:00
|
|
|
public function setCounter($counter): self
|
2019-12-14 16:35:19 +01:00
|
|
|
{
|
|
|
|
$this->counter = $counter;
|
2020-03-15 13:56:31 +01:00
|
|
|
|
2020-02-01 19:42:28 +01:00
|
|
|
return $this;
|
2019-12-14 16:35:19 +01:00
|
|
|
}
|
|
|
|
|
2022-08-14 19:09:07 +02:00
|
|
|
public function getName(): string
|
2019-12-14 16:35:19 +01:00
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
2020-02-01 19:42:28 +01:00
|
|
|
public function setName($name): self
|
2019-12-14 16:35:19 +01:00
|
|
|
{
|
|
|
|
$this->name = $name;
|
2020-03-15 13:56:31 +01:00
|
|
|
|
2020-02-01 19:42:28 +01:00
|
|
|
return $this;
|
2019-12-14 16:35:19 +01:00
|
|
|
}
|
2019-12-29 13:35:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the user, this U2F key belongs to.
|
|
|
|
*/
|
2020-01-04 20:24:09 +01:00
|
|
|
public function getUser(): User
|
2019-12-29 13:35:30 +01:00
|
|
|
{
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
2019-12-29 16:20:09 +01:00
|
|
|
/**
|
2020-01-04 20:24:09 +01:00
|
|
|
* The primary key ID of this key.
|
2019-12-29 16:20:09 +01:00
|
|
|
*/
|
2020-01-04 20:24:09 +01:00
|
|
|
public function getID(): int
|
2019-12-29 16:20:09 +01:00
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2019-12-29 13:35:30 +01:00
|
|
|
/**
|
|
|
|
* Sets the user this U2F key belongs to.
|
2020-01-04 20:24:09 +01:00
|
|
|
*
|
2019-12-29 13:35:30 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2020-02-01 19:42:28 +01:00
|
|
|
public function setUser(User $new_user): self
|
2019-12-29 13:35:30 +01:00
|
|
|
{
|
|
|
|
$this->user = $new_user;
|
2020-01-04 20:24:09 +01:00
|
|
|
|
2019-12-29 13:35:30 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2020-01-04 20:24:09 +01:00
|
|
|
}
|