Passed
Push — develop ( 548a36...8ad7fd )
by nguereza
01:55
created

PublicKey::getReplyParty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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
        return $this;
129
    }
130
131
    /**
132
     * Return the timeout in milliseconds
133
     * @return int
134
     */
135
    public function getTimeout(): int
136
    {
137
        return $this->timeout;
138
    }
139
140
    /**
141
     *
142
     * @return PublicKeyCredentialParam[]
143
     */
144
    public function getPublicKeyCredentialParams(): array
145
    {
146
        return $this->publicKeyCredentialParams;
147
    }
148
149
    /**
150
     *
151
     * @return AuthenticatorSelection
152
     */
153
    public function getAuthenticatorSelection(): AuthenticatorSelection
154
    {
155
        return $this->authenticatorSelection;
156
    }
157
158
    /**
159
     *
160
     * @return RelyingParty
161
     */
162
    public function getRelyingParty(): RelyingParty
163
    {
164
        return $this->relyingParty;
165
    }
166
167
    /**
168
     *
169
     * @return UserInfo
170
     */
171
    public function getUserInfo(): UserInfo
172
    {
173
        return $this->userInfo;
174
    }
175
176
    /**
177
     *
178
     * @return ByteBuffer
179
     */
180
    public function getChallenge(): ByteBuffer
181
    {
182
        return $this->challenge;
183
    }
184
185
    /**
186
     *
187
     * @return UserCredential[]
188
     */
189
    public function getExcludeCredentials(): array
190
    {
191
        return $this->excludeCredentials;
192
    }
193
194
    /**
195
     *
196
     * @return PublicKeyAuthParam[]
197
     */
198
    public function getAllowCredentials(): array
199
    {
200
        return $this->allowCredentials;
201
    }
202
203
    /**
204
     *
205
     * @return array<string, mixed>
206
     */
207
    public function getExtensions(): array
208
    {
209
        return $this->extensions;
210
    }
211
212
    /**
213
     *
214
     * @return string
215
     */
216
    public function getAttestation(): string
217
    {
218
        return $this->attestation;
219
    }
220
221
    /**
222
     *
223
     * @return string
224
     */
225
    public function getRelyingPartyId(): string
226
    {
227
        return $this->relyingPartyId;
228
    }
229
230
    /**
231
     *
232
     * @return string
233
     */
234
    public function getUserVerificationType(): string
235
    {
236
        return $this->userVerificationType;
237
    }
238
239
    /**
240
     * Set the timeout (in second)
241
     * @param int $timeout
242
     * @return $this
243
     */
244
    public function setTimeout(int $timeout): self
245
    {
246
        $this->timeout = $timeout * 1000;
247
        return $this;
248
    }
249
250
    /**
251
     *
252
     * @param PublicKeyCredentialParam[] $publicKeyCredentialParams
253
     * @return $this
254
     */
255
    public function setPublicKeyCredentialParams(array $publicKeyCredentialParams): self
256
    {
257
        $this->publicKeyCredentialParams = $publicKeyCredentialParams;
258
        return $this;
259
    }
260
261
    /**
262
     *
263
     * @param AuthenticatorSelection $authenticatorSelection
264
     * @return $this
265
     */
266
    public function setAuthenticatorSelection(AuthenticatorSelection $authenticatorSelection): self
267
    {
268
        $this->authenticatorSelection = $authenticatorSelection;
269
        return $this;
270
    }
271
272
    /**
273
     *
274
     * @param RelyingParty $relyingParty
275
     * @return $this
276
     */
277
    public function setRelyingParty(RelyingParty $relyingParty): self
278
    {
279
        $this->relyingParty = $relyingParty;
280
        return $this;
281
    }
282
283
    /**
284
     *
285
     * @param UserInfo $userInfo
286
     * @return $this
287
     */
288
    public function setUserInfo(UserInfo $userInfo): self
289
    {
290
        $this->userInfo = $userInfo;
291
        return $this;
292
    }
293
294
    /**
295
     *
296
     * @param ByteBuffer|string $challenge
297
     * @return $this
298
     */
299
    public function setChallenge($challenge): self
300
    {
301
        if (is_string($challenge)) {
302
            $challenge = new ByteBuffer($challenge);
303
        }
304
305
        $this->challenge = $challenge;
306
        return $this;
307
    }
308
309
    /**
310
     *
311
     * @param UserCredential[] $excludeCredentials
312
     * @return $this
313
     */
314
    public function setExcludeCredentials(array $excludeCredentials): self
315
    {
316
        $this->excludeCredentials = $excludeCredentials;
317
        return $this;
318
    }
319
320
    /**
321
     *
322
     * @param PublicKeyAuthParam[] $allowCredentials
323
     * @return $this
324
     */
325
    public function setAllowCredentials(array $allowCredentials): self
326
    {
327
        $this->allowCredentials = $allowCredentials;
328
        return $this;
329
    }
330
331
    /**
332
     * TODO: This is currently not used
333
     * @return $this
334
     */
335
    public function setExtensions(): self
336
    {
337
        $this->extensions['exts'] = true;
338
339
        return $this;
340
    }
341
342
    /**
343
     *
344
     * @param string $attestation
345
     * @return $this
346
     */
347
    public function setAttestation(string $attestation): self
348
    {
349
        $this->attestation = $attestation;
350
        return $this;
351
    }
352
353
    /**
354
     *
355
     * @param string $relyingPartyId
356
     * @return $this
357
     */
358
    public function setRelyingPartyId(string $relyingPartyId): self
359
    {
360
        $this->relyingPartyId = $relyingPartyId;
361
        return $this;
362
    }
363
364
    /**
365
     *
366
     * @param string $userVerificationType
367
     * @return $this
368
     */
369
    public function setUserVerificationType(string $userVerificationType): self
370
    {
371
        $this->userVerificationType = $userVerificationType;
372
        return $this;
373
    }
374
375
    /**
376
    * {@inheritdoc}
377
    * @return mixed
378
    */
379
    public function jsonSerialize()
380
    {
381
        return get_object_vars($this);
382
    }
383
}
384