1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software; you can redistribute it and/or |
8
|
|
|
* modify it under the terms of the GNU General Public License |
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
10
|
|
|
* of the License, or (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 General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program; if not, write to the Free Software |
19
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace App\Entity\UserSystem; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
use App\Entity\Base\TimestampTrait; |
26
|
|
|
use Doctrine\ORM\Mapping as ORM; |
27
|
|
|
use R\U2FTwoFactorBundle\Model\U2F\TwoFactorInterface; |
28
|
|
|
use R\U2FTwoFactorBundle\Model\U2F\TwoFactorKeyInterface; |
29
|
|
|
use u2flib_server\Registration; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @ORM\Entity |
33
|
|
|
* @ORM\Table(name="u2f_keys", |
34
|
|
|
* uniqueConstraints={@ORM\UniqueConstraint(name="user_unique",columns={"user_id", |
35
|
|
|
* "key_handle"})}) |
36
|
|
|
* @ORM\HasLifecycleCallbacks() |
37
|
|
|
*/ |
38
|
|
|
class U2FKey implements TwoFactorKeyInterface |
39
|
|
|
{ |
40
|
|
|
use TimestampTrait; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @ORM\Id |
44
|
|
|
* @ORM\Column(type="integer") |
45
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
46
|
|
|
*/ |
47
|
|
|
protected $id; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @ORM\Column(type="string") |
51
|
|
|
* @var string |
52
|
|
|
**/ |
53
|
|
|
public $keyHandle; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @ORM\Column(type="string") |
57
|
|
|
* @var string |
58
|
|
|
**/ |
59
|
|
|
public $publicKey; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @ORM\Column(type="text") |
63
|
|
|
* @var string |
64
|
|
|
**/ |
65
|
|
|
public $certificate; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @ORM\Column(type="string") |
69
|
|
|
* @var int |
70
|
|
|
**/ |
71
|
|
|
public $counter; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="u2fKeys") |
75
|
|
|
* @var User |
76
|
|
|
**/ |
77
|
|
|
protected $user; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @ORM\Column(type="string") |
81
|
|
|
* @var string |
82
|
|
|
**/ |
83
|
|
|
protected $name; |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
public function fromRegistrationData(Registration $data): void |
87
|
|
|
{ |
88
|
|
|
$this->keyHandle = $data->keyHandle; |
89
|
|
|
$this->publicKey = $data->publicKey; |
90
|
|
|
$this->certificate = $data->certificate; |
91
|
|
|
$this->counter = $data->counter; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** @inheritDoc */ |
95
|
|
|
public function getKeyHandle() |
96
|
|
|
{ |
97
|
|
|
return $this->keyHandle; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** @inheritDoc */ |
101
|
|
|
public function setKeyHandle($keyHandle) |
102
|
|
|
{ |
103
|
|
|
$this->keyHandle = $keyHandle; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** @inheritDoc */ |
107
|
|
|
public function getPublicKey() |
108
|
|
|
{ |
109
|
|
|
return $this->publicKey; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** @inheritDoc */ |
113
|
|
|
public function setPublicKey($publicKey) |
114
|
|
|
{ |
115
|
|
|
$this->publicKey = $publicKey; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** @inheritDoc */ |
119
|
|
|
public function getCertificate() |
120
|
|
|
{ |
121
|
|
|
return $this->certificate; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
/** @inheritDoc */ |
126
|
|
|
public function setCertificate($certificate) |
127
|
|
|
{ |
128
|
|
|
$this->certificate = $certificate; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** @inheritDoc */ |
132
|
|
|
public function getCounter() |
133
|
|
|
{ |
134
|
|
|
return $this->counter; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** @inheritDoc */ |
138
|
|
|
public function setCounter($counter) |
139
|
|
|
{ |
140
|
|
|
$this->counter = $counter; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** @inheritDoc */ |
144
|
|
|
public function getName() |
145
|
|
|
{ |
146
|
|
|
return $this->name; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** @inheritDoc */ |
150
|
|
|
public function setName($name) |
151
|
|
|
{ |
152
|
|
|
$this->name = $name; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Gets the user, this U2F key belongs to. |
157
|
|
|
* @return User |
158
|
|
|
*/ |
159
|
|
|
public function getUser() : User |
160
|
|
|
{ |
161
|
|
|
return $this->user; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* The primary key ID of this key |
166
|
|
|
* @return int |
167
|
|
|
*/ |
168
|
|
|
public function getID() : int |
169
|
|
|
{ |
170
|
|
|
return $this->id; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Sets the user this U2F key belongs to. |
175
|
|
|
* @param TwoFactorInterface $new_user |
176
|
|
|
* @return $this |
177
|
|
|
*/ |
178
|
|
|
public function setUser(TwoFactorInterface $new_user) : self |
179
|
|
|
{ |
180
|
|
|
$this->user = $new_user; |
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
} |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.