|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MadWizard\WebAuthn\Dom; |
|
4
|
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
|
6
|
|
|
use MadWizard\WebAuthn\Format\ByteBuffer; |
|
7
|
|
|
|
|
8
|
|
|
final class PublicKeyCredentialCreationOptions extends AbstractDictionary |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var PublicKeyCredentialRpEntity |
|
12
|
|
|
*/ |
|
13
|
|
|
private $rp; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var PublicKeyCredentialUserEntity |
|
17
|
|
|
*/ |
|
18
|
|
|
private $user; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var ByteBuffer |
|
22
|
|
|
*/ |
|
23
|
|
|
private $challenge; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var PublicKeyCredentialParameters[] |
|
27
|
|
|
*/ |
|
28
|
|
|
private $pubKeyCredParams; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var int|null |
|
32
|
|
|
*/ |
|
33
|
|
|
private $timeout; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var PublicKeyCredentialDescriptor[]|null |
|
37
|
|
|
*/ |
|
38
|
|
|
private $excludeCredentials; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var AuthenticatorSelectionCriteria|null |
|
42
|
|
|
*/ |
|
43
|
|
|
private $authenticatorSelection; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var string|null |
|
47
|
|
|
*/ |
|
48
|
|
|
private $attestation; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var AuthenticationExtensionsClientInputs|null |
|
52
|
|
|
*/ |
|
53
|
|
|
private $extensions; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* PublicKeyCredentialCreationOptions constructor. |
|
57
|
|
|
* |
|
58
|
|
|
* @param PublicKeyCredentialParameters[] $pubKeyCredParams |
|
59
|
|
|
*/ |
|
60
|
4 |
|
public function __construct(PublicKeyCredentialRpEntity $rp, PublicKeyCredentialUserEntity $user, ByteBuffer $challenge, array $pubKeyCredParams) |
|
61
|
|
|
{ |
|
62
|
4 |
|
$this->rp = $rp; |
|
63
|
4 |
|
$this->user = $user; |
|
64
|
4 |
|
$this->challenge = $challenge; |
|
65
|
4 |
|
$this->pubKeyCredParams = $pubKeyCredParams; |
|
66
|
4 |
|
} |
|
67
|
|
|
|
|
68
|
3 |
|
public function getAsArray(): array |
|
69
|
|
|
{ |
|
70
|
|
|
$map = [ |
|
71
|
3 |
|
'rp' => $this->rp, |
|
72
|
3 |
|
'user' => $this->user, |
|
73
|
3 |
|
'challenge' => $this->challenge, |
|
74
|
3 |
|
'pubKeyCredParams' => $this->pubKeyCredParams, |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
3 |
|
$map = array_merge( |
|
78
|
3 |
|
$map, |
|
79
|
|
|
self::removeNullValues( |
|
80
|
|
|
[ |
|
81
|
3 |
|
'timeout' => $this->timeout, |
|
82
|
3 |
|
'excludeCredentials' => $this->excludeCredentials, |
|
83
|
3 |
|
'authenticatorSelection' => $this->authenticatorSelection, |
|
84
|
3 |
|
'attestation' => $this->attestation, |
|
85
|
3 |
|
'extensions' => $this->extensions, |
|
86
|
|
|
] |
|
87
|
|
|
) |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
3 |
|
return $map; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
3 |
|
public function getAttestation(): ?string |
|
94
|
|
|
{ |
|
95
|
3 |
|
return $this->attestation; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
2 |
|
public function setAttestation(?string $attestation): void |
|
99
|
|
|
{ |
|
100
|
2 |
|
if ($attestation !== null && !AttestationConveyancePreference::isValidValue($attestation)) { |
|
101
|
|
|
throw new InvalidArgumentException(sprintf("String '%s' is not a valid attestation preference.", $attestation)); |
|
102
|
|
|
} |
|
103
|
2 |
|
$this->attestation = $attestation; |
|
104
|
2 |
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return AuthenticatorSelectionCriteria |
|
108
|
|
|
*/ |
|
109
|
3 |
|
public function getAuthenticatorSelection(): ?AuthenticatorSelectionCriteria |
|
110
|
|
|
{ |
|
111
|
3 |
|
return $this->authenticatorSelection; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param AuthenticatorSelectionCriteria $authenticatorSelection |
|
116
|
|
|
*/ |
|
117
|
2 |
|
public function setAuthenticatorSelection(?AuthenticatorSelectionCriteria $authenticatorSelection): void |
|
118
|
|
|
{ |
|
119
|
2 |
|
$this->authenticatorSelection = $authenticatorSelection; |
|
120
|
2 |
|
} |
|
121
|
|
|
|
|
122
|
1 |
|
public function getRpEntity(): PublicKeyCredentialRpEntity |
|
123
|
|
|
{ |
|
124
|
1 |
|
return $this->rp; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
2 |
|
public function getUserEntity(): PublicKeyCredentialUserEntity |
|
128
|
|
|
{ |
|
129
|
2 |
|
return $this->user; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
1 |
|
public function getTimeout(): ?int |
|
133
|
|
|
{ |
|
134
|
1 |
|
return $this->timeout; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return PublicKeyCredentialDescriptor[] |
|
139
|
|
|
*/ |
|
140
|
1 |
|
public function getExcludeCredentials(): ?array |
|
141
|
|
|
{ |
|
142
|
1 |
|
return $this->excludeCredentials; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function addExcludeCredential(PublicKeyCredentialDescriptor $descriptor) |
|
146
|
|
|
{ |
|
147
|
|
|
if ($this->excludeCredentials === null) { |
|
148
|
|
|
$this->excludeCredentials = []; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
$this->excludeCredentials[] = $descriptor; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @return PublicKeyCredentialParameters[] |
|
156
|
|
|
*/ |
|
157
|
1 |
|
public function getCredentialParameters(): ?array |
|
158
|
|
|
{ |
|
159
|
1 |
|
return $this->pubKeyCredParams; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
2 |
|
public function getChallenge(): ByteBuffer |
|
163
|
|
|
{ |
|
164
|
2 |
|
return $this->challenge; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public function getExtensions(): ?AuthenticationExtensionsClientInputs |
|
168
|
|
|
{ |
|
169
|
|
|
return $this->extensions; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function setExtensions(?AuthenticationExtensionsClientInputs $extensions): void |
|
173
|
|
|
{ |
|
174
|
|
|
$this->extensions = $extensions; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
1 |
|
public function setTimeout(?int $timeout): void |
|
178
|
|
|
{ |
|
179
|
1 |
|
$this->timeout = $timeout; |
|
180
|
1 |
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|