PublicKey::setUserVerificationType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * Platine Webauth
5
 *
6
 * Platine Webauthn is the implementation of webauthn specifications
7
 *
8
 * This content is released under the MIT License (MIT)
9
 *
10
 * Copyright (c) 2020 Platine Webauth
11
 * Copyright (c) Jakob Bennemann <[email protected]>
12
 *
13
 * Permission is hereby granted, free of charge, to any person obtaining a copy
14
 * of this software and associated documentation files (the "Software"), to deal
15
 * in the Software without restriction, including without limitation the rights
16
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
 * copies of the Software, and to permit persons to whom the Software is
18
 * furnished to do so, subject to the following conditions:
19
 *
20
 * The above copyright notice and this permission notice shall be included in all
21
 * copies or substantial portions of the Software.
22
 *
23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
 * SOFTWARE.
30
 */
31
32
declare(strict_types=1);
33
34
namespace Platine\Webauthn\Entity;
35
36
use JsonSerializable;
37
use Platine\Webauthn\Helper\ByteBuffer;
38
39
/**
40
 * @class PublicKey
41
 * @package Platine\Webauthn\Entity
42
 */
43
class PublicKey implements JsonSerializable
44
{
45
    /**
46
     * Default timeout
47
     * @var int
48
     */
49
    protected int $timeout = 60 * 1000;
50
51
    /**
52
     * The public key credential parameters
53
     * @var PublicKeyCredentialParam[]
54
     */
55
    protected array $publicKeyCredentialParams = [];
56
57
    /**
58
     * The AuthenticatorSelection
59
     * @var AuthenticatorSelection
60
     */
61
    protected AuthenticatorSelection $authenticatorSelection;
62
63
    /**
64
     * The RelyingParty
65
     * @var RelyingParty
66
     */
67
    protected RelyingParty $relyingParty;
68
69
    /**
70
     * The UserInfo
71
     * @var UserInfo
72
     */
73
    protected UserInfo $userInfo;
74
75
    /**
76
     * The challenge to use
77
     * @var ByteBuffer
78
     */
79
    protected ByteBuffer $challenge;
80
81
    /**
82
     * The credentials to exclude
83
     * @var UserCredential[]
84
     */
85
    protected array $excludeCredentials = [];
86
87
    /**
88
     * The credentials to allow
89
     * @var PublicKeyAuthParam[]
90
     */
91
    protected array $allowCredentials = [];
92
93
    /**
94
     * The extensions
95
     * @var array<string, mixed>
96
     */
97
    protected array $extensions = ['exts' => true];
98
99
    /**
100
     * The attestation to use
101
     * @var string
102
     */
103
    protected string $attestation = '';
104
105
    /**
106
     * The relying party id. This is used only for login
107
     * @var string
108
     */
109
    protected string $relyingPartyId = '';
110
111
    /**
112
     * The user verification type. This is used only for login
113
     * @var string
114
     */
115
    protected string $userVerificationType = '';
116
117
118
    /**
119
     * Add default public keys
120
     * @return $this
121
     */
122
    public function addPublicKeys(): self
123
    {
124
        $this->publicKeyCredentialParams = [
125
            new PublicKeyCredentialParam(-7),
126
            new PublicKeyCredentialParam(-257),
127
        ];
128
129
        return $this;
130
    }
131
132
    /**
133
     * Return the timeout in milliseconds
134
     * @return int
135
     */
136
    public function getTimeout(): int
137
    {
138
        return $this->timeout;
139
    }
140
141
    /**
142
     *
143
     * @return PublicKeyCredentialParam[]
144
     */
145
    public function getPublicKeyCredentialParams(): array
146
    {
147
        return $this->publicKeyCredentialParams;
148
    }
149
150
    /**
151
     *
152
     * @return AuthenticatorSelection
153
     */
154
    public function getAuthenticatorSelection(): AuthenticatorSelection
155
    {
156
        return $this->authenticatorSelection;
157
    }
158
159
    /**
160
     *
161
     * @return RelyingParty
162
     */
163
    public function getRelyingParty(): RelyingParty
164
    {
165
        return $this->relyingParty;
166
    }
167
168
    /**
169
     *
170
     * @return UserInfo
171
     */
172
    public function getUserInfo(): UserInfo
173
    {
174
        return $this->userInfo;
175
    }
176
177
    /**
178
     *
179
     * @return ByteBuffer
180
     */
181
    public function getChallenge(): ByteBuffer
182
    {
183
        return $this->challenge;
184
    }
185
186
    /**
187
     *
188
     * @return UserCredential[]
189
     */
190
    public function getExcludeCredentials(): array
191
    {
192
        return $this->excludeCredentials;
193
    }
194
195
    /**
196
     *
197
     * @return PublicKeyAuthParam[]
198
     */
199
    public function getAllowCredentials(): array
200
    {
201
        return $this->allowCredentials;
202
    }
203
204
    /**
205
     *
206
     * @return array<string, mixed>
207
     */
208
    public function getExtensions(): array
209
    {
210
        return $this->extensions;
211
    }
212
213
    /**
214
     *
215
     * @return string
216
     */
217
    public function getAttestation(): string
218
    {
219
        return $this->attestation;
220
    }
221
222
    /**
223
     *
224
     * @return string
225
     */
226
    public function getRelyingPartyId(): string
227
    {
228
        return $this->relyingPartyId;
229
    }
230
231
    /**
232
     *
233
     * @return string
234
     */
235
    public function getUserVerificationType(): string
236
    {
237
        return $this->userVerificationType;
238
    }
239
240
    /**
241
     * Set the timeout (in second)
242
     * @param int $timeout
243
     * @return $this
244
     */
245
    public function setTimeout(int $timeout): self
246
    {
247
        $this->timeout = $timeout * 1000;
248
        return $this;
249
    }
250
251
    /**
252
     *
253
     * @param PublicKeyCredentialParam[] $publicKeyCredentialParams
254
     * @return $this
255
     */
256
    public function setPublicKeyCredentialParams(array $publicKeyCredentialParams): self
257
    {
258
        $this->publicKeyCredentialParams = $publicKeyCredentialParams;
259
        return $this;
260
    }
261
262
    /**
263
     *
264
     * @param AuthenticatorSelection $authenticatorSelection
265
     * @return $this
266
     */
267
    public function setAuthenticatorSelection(AuthenticatorSelection $authenticatorSelection): self
268
    {
269
        $this->authenticatorSelection = $authenticatorSelection;
270
        return $this;
271
    }
272
273
    /**
274
     *
275
     * @param RelyingParty $relyingParty
276
     * @return $this
277
     */
278
    public function setRelyingParty(RelyingParty $relyingParty): self
279
    {
280
        $this->relyingParty = $relyingParty;
281
        return $this;
282
    }
283
284
    /**
285
     *
286
     * @param UserInfo $userInfo
287
     * @return $this
288
     */
289
    public function setUserInfo(UserInfo $userInfo): self
290
    {
291
        $this->userInfo = $userInfo;
292
        return $this;
293
    }
294
295
    /**
296
     *
297
     * @param ByteBuffer|string $challenge
298
     * @return $this
299
     */
300
    public function setChallenge(ByteBuffer|string $challenge): self
301
    {
302
        if (is_string($challenge)) {
303
            $challenge = new ByteBuffer($challenge);
304
        }
305
306
        $this->challenge = $challenge;
307
        return $this;
308
    }
309
310
    /**
311
     *
312
     * @param UserCredential[] $excludeCredentials
313
     * @return $this
314
     */
315
    public function setExcludeCredentials(array $excludeCredentials): self
316
    {
317
        $this->excludeCredentials = $excludeCredentials;
318
        return $this;
319
    }
320
321
    /**
322
     *
323
     * @param PublicKeyAuthParam[] $allowCredentials
324
     * @return $this
325
     */
326
    public function setAllowCredentials(array $allowCredentials): self
327
    {
328
        $this->allowCredentials = $allowCredentials;
329
        return $this;
330
    }
331
332
    /**
333
     * TODO: This is currently not used
334
     * @return $this
335
     */
336
    public function setExtensions(): self
337
    {
338
        $this->extensions['exts'] = true;
339
340
        return $this;
341
    }
342
343
    /**
344
     *
345
     * @param string $attestation
346
     * @return $this
347
     */
348
    public function setAttestation(string $attestation): self
349
    {
350
        $this->attestation = $attestation;
351
        return $this;
352
    }
353
354
    /**
355
     *
356
     * @param string $relyingPartyId
357
     * @return $this
358
     */
359
    public function setRelyingPartyId(string $relyingPartyId): self
360
    {
361
        $this->relyingPartyId = $relyingPartyId;
362
        return $this;
363
    }
364
365
    /**
366
     *
367
     * @param string $userVerificationType
368
     * @return $this
369
     */
370
    public function setUserVerificationType(string $userVerificationType): self
371
    {
372
        $this->userVerificationType = $userVerificationType;
373
        return $this;
374
    }
375
376
    /**
377
    * {@inheritdoc}
378
    * @return mixed
379
    */
380
    public function jsonSerialize(): mixed
381
    {
382
        return get_object_vars($this);
383
    }
384
}
385