Part-DB /
Part-DB-symfony
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
||
| 4 | * |
||
| 5 | * Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics) |
||
| 6 | * |
||
| 7 | * This program is free software: you can redistribute it and/or modify |
||
| 8 | * it under the terms of the GNU Affero General Public License as published |
||
| 9 | * by the Free Software Foundation, either version 3 of the License, or |
||
| 10 | * (at your option) any later version. |
||
| 11 | * |
||
| 12 | * This program is distributed in the hope that it will be useful, |
||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 15 | * GNU Affero General Public License for more details. |
||
| 16 | * |
||
| 17 | * You should have received a copy of the GNU Affero General Public License |
||
| 18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
| 19 | */ |
||
| 20 | |||
| 21 | declare(strict_types=1); |
||
| 22 | |||
| 23 | namespace App\Entity\UserSystem; |
||
| 24 | |||
| 25 | use App\Entity\Base\TimestampTrait; |
||
| 26 | use Doctrine\ORM\Mapping as ORM; |
||
| 27 | use Jbtronics\TFAWebauthn\Model\LegacyU2FKeyInterface; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @ORM\Entity |
||
| 31 | * @ORM\Table(name="u2f_keys", |
||
| 32 | * uniqueConstraints={ |
||
| 33 | * @ORM\UniqueConstraint(name="user_unique",columns={"user_id", |
||
| 34 | * "key_handle"}) |
||
| 35 | * }) |
||
| 36 | * @ORM\HasLifecycleCallbacks() |
||
| 37 | */ |
||
| 38 | class U2FKey implements LegacyU2FKeyInterface |
||
| 39 | { |
||
| 40 | use TimestampTrait; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * We have to restrict the length here, as InnoDB only supports key index with max. 767 Bytes. |
||
| 44 | * Max length of keyhandles should be 128. (According to U2F_MAX_KH_SIZE in FIDO example C code). |
||
| 45 | * |
||
| 46 | * @ORM\Column(type="string", length=128) |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | **/ |
||
| 50 | public string $keyHandle; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @ORM\Column(type="string") |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | **/ |
||
| 57 | public string $publicKey; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @ORM\Column(type="text") |
||
| 61 | * |
||
| 62 | * @var string |
||
| 63 | **/ |
||
| 64 | public string $certificate; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @ORM\Column(type="string") |
||
| 68 | * |
||
| 69 | * @var int |
||
| 70 | **/ |
||
| 71 | public int $counter; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @ORM\Id |
||
| 75 | * @ORM\Column(type="integer") |
||
| 76 | * @ORM\GeneratedValue(strategy="AUTO") |
||
| 77 | */ |
||
| 78 | protected int $id; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @ORM\Column(type="string") |
||
| 82 | * |
||
| 83 | * @var string |
||
| 84 | **/ |
||
| 85 | protected string $name; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="u2fKeys") |
||
| 89 | **/ |
||
| 90 | protected ?User $user = null; |
||
| 91 | |||
| 92 | public function getKeyHandle(): string |
||
| 93 | { |
||
| 94 | return $this->keyHandle; |
||
| 95 | } |
||
| 96 | |||
| 97 | |||
| 98 | public function setKeyHandle($keyHandle): self |
||
| 99 | { |
||
| 100 | $this->keyHandle = $keyHandle; |
||
| 101 | |||
| 102 | return $this; |
||
| 103 | } |
||
| 104 | |||
| 105 | public function getPublicKey(): string |
||
| 106 | { |
||
| 107 | return $this->publicKey; |
||
| 108 | } |
||
| 109 | |||
| 110 | public function setPublicKey($publicKey): self |
||
| 111 | { |
||
| 112 | $this->publicKey = $publicKey; |
||
| 113 | |||
| 114 | return $this; |
||
| 115 | } |
||
| 116 | |||
| 117 | public function getCertificate(): string |
||
| 118 | { |
||
| 119 | return $this->certificate; |
||
| 120 | } |
||
| 121 | |||
| 122 | public function setCertificate($certificate): self |
||
| 123 | { |
||
| 124 | $this->certificate = $certificate; |
||
| 125 | |||
| 126 | return $this; |
||
| 127 | } |
||
| 128 | |||
| 129 | public function getCounter(): int |
||
| 130 | { |
||
| 131 | return $this->counter; |
||
| 132 | } |
||
| 133 | |||
| 134 | public function setCounter($counter): self |
||
| 135 | { |
||
| 136 | $this->counter = $counter; |
||
| 137 | |||
| 138 | return $this; |
||
| 139 | } |
||
| 140 | |||
| 141 | public function getName(): string |
||
| 142 | { |
||
| 143 | return $this->name; |
||
| 144 | } |
||
| 145 | |||
| 146 | public function setName($name): self |
||
| 147 | { |
||
| 148 | $this->name = $name; |
||
| 149 | |||
| 150 | return $this; |
||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Gets the user, this U2F key belongs to. |
||
| 155 | */ |
||
| 156 | public function getUser(): User |
||
| 157 | { |
||
| 158 | return $this->user; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * The primary key ID of this key. |
||
| 163 | */ |
||
| 164 | public function getID(): int |
||
| 165 | { |
||
| 166 | return $this->id; |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Sets the user this U2F key belongs to. |
||
| 171 | * |
||
| 172 | * @return $this |
||
| 173 | */ |
||
| 174 | public function setUser(User $new_user): self |
||
| 175 | { |
||
| 176 | $this->user = $new_user; |
||
| 177 | |||
| 178 | return $this; |
||
| 179 | } |
||
| 180 | } |
||
| 181 |