1 | // Copyright (c) 2018, Yubico AB | |
2 | // All rights reserved. | |
3 | // | |
4 | // Redistribution and use in source and binary forms, with or without | |
5 | // modification, are permitted provided that the following conditions are met: | |
6 | // | |
7 | // 1. Redistributions of source code must retain the above copyright notice, this | |
8 | // list of conditions and the following disclaimer. | |
9 | // | |
10 | // 2. Redistributions in binary form must reproduce the above copyright notice, | |
11 | // this list of conditions and the following disclaimer in the documentation | |
12 | // and/or other materials provided with the distribution. | |
13 | // | |
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
18 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
19 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
20 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
21 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
22 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | ||
25 | package com.yubico.webauthn; | |
26 | ||
27 | import com.yubico.webauthn.data.AssertionExtensionInputs; | |
28 | import com.yubico.webauthn.data.ByteArray; | |
29 | import com.yubico.webauthn.data.PublicKeyCredentialRequestOptions; | |
30 | import com.yubico.webauthn.data.UserVerificationRequirement; | |
31 | import java.util.Optional; | |
32 | import lombok.Builder; | |
33 | import lombok.NonNull; | |
34 | import lombok.Value; | |
35 | ||
36 | /** Parameters for {@link RelyingParty#startAssertion(StartAssertionOptions)}. */ | |
37 | @Value | |
38 | @Builder(toBuilder = true) | |
39 | public class StartAssertionOptions { | |
40 | ||
41 | private final String username; | |
42 | ||
43 | private final ByteArray userHandle; | |
44 | ||
45 | /** | |
46 | * Extension inputs for this authentication operation. | |
47 | * | |
48 | * <p>If {@link RelyingParty#getAppId()} is set, {@link | |
49 | * RelyingParty#startAssertion(StartAssertionOptions)} will overwrite any {@link | |
50 | * AssertionExtensionInputs#getAppid() appId} extension input set herein. | |
51 | * | |
52 | * <p>The default specifies no extension inputs. | |
53 | */ | |
54 | @NonNull @Builder.Default | |
55 | private final AssertionExtensionInputs extensions = AssertionExtensionInputs.builder().build(); | |
56 | ||
57 | /** | |
58 | * The value for {@link PublicKeyCredentialRequestOptions#getUserVerification()} for this | |
59 | * authentication operation. | |
60 | * | |
61 | * <p>If set to {@link UserVerificationRequirement#REQUIRED}, then {@link | |
62 | * RelyingParty#finishAssertion(FinishAssertionOptions)} will enforce that <a | |
63 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408#user-verification">user | |
64 | * verification</a>was performed in this authentication ceremony. | |
65 | * | |
66 | * <p>The default is {@link UserVerificationRequirement#PREFERRED}. | |
67 | */ | |
68 | private final UserVerificationRequirement userVerification; | |
69 | ||
70 | /** | |
71 | * The value for {@link PublicKeyCredentialRequestOptions#getTimeout()} for this authentication | |
72 | * operation. | |
73 | * | |
74 | * <p>This library does not take the timeout into account in any way, other than passing it | |
75 | * through to the {@link PublicKeyCredentialRequestOptions} so it can be used as an argument to | |
76 | * <code>navigator.credentials.get()</code> on the client side. | |
77 | * | |
78 | * <p>The default is empty. | |
79 | */ | |
80 | private final Long timeout; | |
81 | ||
82 | /** | |
83 | * The username of the user to authenticate, if the user has already been identified. | |
84 | * | |
85 | * <p>Mutually exclusive with {@link #getUserHandle()}. | |
86 | * | |
87 | * <p>If this or {@link #getUserHandle()} is present, then {@link | |
88 | * RelyingParty#startAssertion(StartAssertionOptions)} will set {@link | |
89 | * PublicKeyCredentialRequestOptions#getAllowCredentials()} to the list of that user's | |
90 | * credentials. | |
91 | * | |
92 | * <p>If this and {@link #getUserHandle()} are both absent, that implies authentication with a | |
93 | * discoverable credential (passkey) - meaning identification of the user is deferred until after | |
94 | * receiving the response from the client. | |
95 | * | |
96 | * <p>The default is empty (absent). | |
97 | * | |
98 | * @see <a | |
99 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-side-discoverable-public-key-credential-source">Client-side-discoverable | |
100 | * credential</a> | |
101 | * @see <a href="https://passkeys.dev/docs/reference/terms/#passkey">Passkey</a> in <a | |
102 | * href="https://passkeys.dev">passkeys.dev</a> reference | |
103 | */ | |
104 | public Optional<String> getUsername() { | |
105 |
1
1. getUsername : replaced return value with Optional.empty for com/yubico/webauthn/StartAssertionOptions::getUsername → KILLED |
return Optional.ofNullable(username); |
106 | } | |
107 | ||
108 | /** | |
109 | * The user handle of the user to authenticate, if the user has already been identified. | |
110 | * | |
111 | * <p>Mutually exclusive with {@link #getUsername()}. | |
112 | * | |
113 | * <p>If this or {@link #getUsername()} is present, then {@link | |
114 | * RelyingParty#startAssertion(StartAssertionOptions)} will set {@link | |
115 | * PublicKeyCredentialRequestOptions#getAllowCredentials()} to the list of that user's | |
116 | * credentials. | |
117 | * | |
118 | * <p>If this and {@link #getUsername()} are both absent, that implies authentication with a | |
119 | * discoverable credential (passkey) - meaning identification of the user is deferred until after | |
120 | * receiving the response from the client. | |
121 | * | |
122 | * <p>The default is empty (absent). | |
123 | * | |
124 | * @see #getUsername() | |
125 | * @see <a href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#user-handle">User Handle</a> | |
126 | * @see <a | |
127 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-side-discoverable-public-key-credential-source">Client-side-discoverable | |
128 | * credential</a> | |
129 | * @see <a href="https://passkeys.dev/docs/reference/terms/#passkey">Passkey</a> in <a | |
130 | * href="https://passkeys.dev">passkeys.dev</a> reference | |
131 | */ | |
132 | public Optional<ByteArray> getUserHandle() { | |
133 |
1
1. getUserHandle : replaced return value with Optional.empty for com/yubico/webauthn/StartAssertionOptions::getUserHandle → KILLED |
return Optional.ofNullable(userHandle); |
134 | } | |
135 | ||
136 | /** | |
137 | * The value for {@link PublicKeyCredentialRequestOptions#getUserVerification()} for this | |
138 | * authentication operation. | |
139 | * | |
140 | * <p>If set to {@link UserVerificationRequirement#REQUIRED}, then {@link | |
141 | * RelyingParty#finishAssertion(FinishAssertionOptions)} will enforce that <a | |
142 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408#user-verification">user | |
143 | * verification</a>was performed in this authentication ceremony. | |
144 | * | |
145 | * <p>The default is {@link UserVerificationRequirement#PREFERRED}. | |
146 | */ | |
147 | public Optional<UserVerificationRequirement> getUserVerification() { | |
148 |
1
1. getUserVerification : replaced return value with Optional.empty for com/yubico/webauthn/StartAssertionOptions::getUserVerification → KILLED |
return Optional.ofNullable(userVerification); |
149 | } | |
150 | ||
151 | /** | |
152 | * The value for {@link PublicKeyCredentialRequestOptions#getTimeout()} for this authentication | |
153 | * operation. | |
154 | * | |
155 | * <p>This library does not take the timeout into account in any way, other than passing it | |
156 | * through to the {@link PublicKeyCredentialRequestOptions} so it can be used as an argument to | |
157 | * <code>navigator.credentials.get()</code> on the client side. | |
158 | * | |
159 | * <p>The default is empty. | |
160 | */ | |
161 | public Optional<Long> getTimeout() { | |
162 |
1
1. getTimeout : replaced return value with Optional.empty for com/yubico/webauthn/StartAssertionOptions::getTimeout → KILLED |
return Optional.ofNullable(timeout); |
163 | } | |
164 | ||
165 | public static class StartAssertionOptionsBuilder { | |
166 | private String username = null; | |
167 | private ByteArray userHandle = null; | |
168 | private UserVerificationRequirement userVerification = null; | |
169 | private Long timeout = null; | |
170 | ||
171 | /** | |
172 | * The username of the user to authenticate, if the user has already been identified. | |
173 | * | |
174 | * <p>Mutually exclusive with {@link #userHandle(Optional)}. Setting this to a present value | |
175 | * will set {@link #userHandle(Optional)} to empty. | |
176 | * | |
177 | * <p>If this or {@link #userHandle(Optional)} is present, then {@link | |
178 | * RelyingParty#startAssertion(StartAssertionOptions)} will set {@link | |
179 | * PublicKeyCredentialRequestOptions#getAllowCredentials()} to the list of that user's | |
180 | * credentials. | |
181 | * | |
182 | * <p>If this and {@link #getUserHandle()} are both absent, that implies authentication with a | |
183 | * discoverable credential (passkey) - meaning identification of the user is deferred until | |
184 | * after receiving the response from the client. | |
185 | * | |
186 | * <p>The default is empty (absent). | |
187 | * | |
188 | * @see #username(String) | |
189 | * @see #userHandle(Optional) | |
190 | * @see #userHandle(ByteArray) | |
191 | * @see <a | |
192 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-side-discoverable-public-key-credential-source">Client-side-discoverable | |
193 | * credential</a> | |
194 | * @see <a href="https://passkeys.dev/docs/reference/terms/#passkey">Passkey</a> in <a | |
195 | * href="https://passkeys.dev">passkeys.dev</a> reference | |
196 | */ | |
197 |
1
1. username : negated conditional → KILLED |
public StartAssertionOptionsBuilder username(@NonNull Optional<String> username) { |
198 | this.username = username.orElse(null); | |
199 |
1
1. username : negated conditional → KILLED |
if (username.isPresent()) { |
200 | this.userHandle = null; | |
201 | } | |
202 |
1
1. username : replaced return value with null for com/yubico/webauthn/StartAssertionOptions$StartAssertionOptionsBuilder::username → KILLED |
return this; |
203 | } | |
204 | ||
205 | /** | |
206 | * The username of the user to authenticate, if the user has already been identified. | |
207 | * | |
208 | * <p>Mutually exclusive with {@link #userHandle(Optional)}. Setting this to a non-null value | |
209 | * will set {@link #userHandle(Optional)} to empty. | |
210 | * | |
211 | * <p>If this or {@link #userHandle(Optional)} is present, then {@link | |
212 | * RelyingParty#startAssertion(StartAssertionOptions)} will set {@link | |
213 | * PublicKeyCredentialRequestOptions#getAllowCredentials()} to the list of that user's | |
214 | * credentials. | |
215 | * | |
216 | * <p>If this and {@link #getUserHandle()} are both absent, that implies authentication with a | |
217 | * discoverable credential (passkey) - meaning identification of the user is deferred until | |
218 | * after receiving the response from the client. | |
219 | * | |
220 | * <p>The default is empty (absent). | |
221 | * | |
222 | * @see #username(Optional) | |
223 | * @see #userHandle(Optional) | |
224 | * @see #userHandle(ByteArray) | |
225 | * @see <a | |
226 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-side-discoverable-public-key-credential-source">Client-side-discoverable | |
227 | * credential</a> | |
228 | * @see <a href="https://passkeys.dev/docs/reference/terms/#passkey">Passkey</a> in <a | |
229 | * href="https://passkeys.dev">passkeys.dev</a> reference | |
230 | */ | |
231 | public StartAssertionOptionsBuilder username(String username) { | |
232 |
1
1. username : replaced return value with null for com/yubico/webauthn/StartAssertionOptions$StartAssertionOptionsBuilder::username → KILLED |
return this.username(Optional.ofNullable(username)); |
233 | } | |
234 | ||
235 | /** | |
236 | * The user handle of the user to authenticate, if the user has already been identified. | |
237 | * | |
238 | * <p>Mutually exclusive with {@link #username(Optional)}. Setting this to a present value will | |
239 | * set {@link #username(Optional)} to empty. | |
240 | * | |
241 | * <p>If this or {@link #username(Optional)} is present, then {@link | |
242 | * RelyingParty#startAssertion(StartAssertionOptions)} will set {@link | |
243 | * PublicKeyCredentialRequestOptions#getAllowCredentials()} to the list of that user's | |
244 | * credentials. | |
245 | * | |
246 | * <p>If this and {@link #getUsername()} are both absent, that implies authentication with a | |
247 | * discoverable credential (passkey) - meaning identification of the user is deferred until | |
248 | * after receiving the response from the client. | |
249 | * | |
250 | * <p>The default is empty (absent). | |
251 | * | |
252 | * @see #username(String) | |
253 | * @see #username(Optional) | |
254 | * @see #userHandle(ByteArray) | |
255 | * @see <a href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#user-handle">User | |
256 | * Handle</a> | |
257 | * @see <a | |
258 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-side-discoverable-public-key-credential-source">Client-side-discoverable | |
259 | * credential</a> | |
260 | * @see <a href="https://passkeys.dev/docs/reference/terms/#passkey">Passkey</a> in <a | |
261 | * href="https://passkeys.dev">passkeys.dev</a> reference | |
262 | */ | |
263 |
1
1. userHandle : negated conditional → KILLED |
public StartAssertionOptionsBuilder userHandle(@NonNull Optional<ByteArray> userHandle) { |
264 | this.userHandle = userHandle.orElse(null); | |
265 |
1
1. userHandle : negated conditional → KILLED |
if (userHandle.isPresent()) { |
266 | this.username = null; | |
267 | } | |
268 |
1
1. userHandle : replaced return value with null for com/yubico/webauthn/StartAssertionOptions$StartAssertionOptionsBuilder::userHandle → KILLED |
return this; |
269 | } | |
270 | ||
271 | /** | |
272 | * The user handle of the user to authenticate, if the user has already been identified. | |
273 | * | |
274 | * <p>Mutually exclusive with {@link #username(Optional)}. Setting this to a non-null value will | |
275 | * set {@link #username(Optional)} to empty. | |
276 | * | |
277 | * <p>If this or {@link #username(Optional)} is present, then {@link | |
278 | * RelyingParty#startAssertion(StartAssertionOptions)} will set {@link | |
279 | * PublicKeyCredentialRequestOptions#getAllowCredentials()} to the list of that user's | |
280 | * credentials. | |
281 | * | |
282 | * <p>If this and {@link #getUsername()} are both absent, that implies authentication with a | |
283 | * discoverable credential (passkey) - meaning identification of the user is deferred until | |
284 | * after receiving the response from the client. | |
285 | * | |
286 | * <p>The default is empty (absent). | |
287 | * | |
288 | * @see #username(String) | |
289 | * @see #username(Optional) | |
290 | * @see #userHandle(Optional) | |
291 | * @see <a | |
292 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-side-discoverable-public-key-credential-source">Client-side-discoverable | |
293 | * credential</a> | |
294 | * @see <a href="https://passkeys.dev/docs/reference/terms/#passkey">Passkey</a> in <a | |
295 | * href="https://passkeys.dev">passkeys.dev</a> reference | |
296 | */ | |
297 | public StartAssertionOptionsBuilder userHandle(ByteArray userHandle) { | |
298 |
1
1. userHandle : replaced return value with null for com/yubico/webauthn/StartAssertionOptions$StartAssertionOptionsBuilder::userHandle → KILLED |
return this.userHandle(Optional.ofNullable(userHandle)); |
299 | } | |
300 | ||
301 | /** | |
302 | * The value for {@link PublicKeyCredentialRequestOptions#getUserVerification()} for this | |
303 | * authentication operation. | |
304 | * | |
305 | * <p>If set to {@link UserVerificationRequirement#REQUIRED}, then {@link | |
306 | * RelyingParty#finishAssertion(FinishAssertionOptions)} will enforce that <a | |
307 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#user-verification">user | |
308 | * verification</a>was performed in this authentication ceremony. | |
309 | * | |
310 | * <p>The default is {@link UserVerificationRequirement#PREFERRED}. | |
311 | */ | |
312 | public StartAssertionOptionsBuilder userVerification( | |
313 |
1
1. userVerification : negated conditional → KILLED |
@NonNull Optional<UserVerificationRequirement> userVerification) { |
314 | this.userVerification = userVerification.orElse(null); | |
315 |
1
1. userVerification : replaced return value with null for com/yubico/webauthn/StartAssertionOptions$StartAssertionOptionsBuilder::userVerification → KILLED |
return this; |
316 | } | |
317 | ||
318 | /** | |
319 | * The value for {@link PublicKeyCredentialRequestOptions#getUserVerification()} for this | |
320 | * authentication operation. | |
321 | * | |
322 | * <p>If set to {@link UserVerificationRequirement#REQUIRED}, then {@link | |
323 | * RelyingParty#finishAssertion(FinishAssertionOptions)} will enforce that <a | |
324 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#user-verification">user | |
325 | * verification</a>was performed in this authentication ceremony. | |
326 | * | |
327 | * <p>The default is {@link UserVerificationRequirement#PREFERRED}. | |
328 | */ | |
329 | public StartAssertionOptionsBuilder userVerification( | |
330 | UserVerificationRequirement userVerification) { | |
331 |
1
1. userVerification : replaced return value with null for com/yubico/webauthn/StartAssertionOptions$StartAssertionOptionsBuilder::userVerification → KILLED |
return this.userVerification(Optional.ofNullable(userVerification)); |
332 | } | |
333 | ||
334 | /** | |
335 | * The value for {@link PublicKeyCredentialRequestOptions#getTimeout()} for this authentication | |
336 | * operation. | |
337 | * | |
338 | * <p>This library does not take the timeout into account in any way, other than passing it | |
339 | * through to the {@link PublicKeyCredentialRequestOptions} so it can be used as an argument to | |
340 | * <code>navigator.credentials.get()</code> on the client side. | |
341 | * | |
342 | * <p>The default is empty. | |
343 | */ | |
344 |
1
1. timeout : negated conditional → KILLED |
public StartAssertionOptionsBuilder timeout(@NonNull Optional<Long> timeout) { |
345 |
3
1. timeout : negated conditional → KILLED 2. timeout : changed conditional boundary → KILLED 3. timeout : negated conditional → KILLED |
if (timeout.isPresent() && timeout.get() <= 0) { |
346 | throw new IllegalArgumentException("timeout must be positive, was: " + timeout.get()); | |
347 | } | |
348 | this.timeout = timeout.orElse(null); | |
349 |
1
1. timeout : replaced return value with null for com/yubico/webauthn/StartAssertionOptions$StartAssertionOptionsBuilder::timeout → KILLED |
return this; |
350 | } | |
351 | ||
352 | /** | |
353 | * The value for {@link PublicKeyCredentialRequestOptions#getTimeout()} for this authentication | |
354 | * operation. | |
355 | * | |
356 | * <p>This library does not take the timeout into account in any way, other than passing it | |
357 | * through to the {@link PublicKeyCredentialRequestOptions} so it can be used as an argument to | |
358 | * <code>navigator.credentials.get()</code> on the client side. | |
359 | * | |
360 | * <p>The default is empty. | |
361 | */ | |
362 | public StartAssertionOptionsBuilder timeout(long timeout) { | |
363 |
1
1. timeout : replaced return value with null for com/yubico/webauthn/StartAssertionOptions$StartAssertionOptionsBuilder::timeout → KILLED |
return this.timeout(Optional.of(timeout)); |
364 | } | |
365 | ||
366 | /* | |
367 | * Workaround, see: https://github.com/rzwitserloot/lombok/issues/2623#issuecomment-714816001 | |
368 | * Consider reverting this workaround if Lombok fixes that issue. | |
369 | */ | |
370 | private StartAssertionOptionsBuilder timeout(Long timeout) { | |
371 |
1
1. timeout : replaced return value with null for com/yubico/webauthn/StartAssertionOptions$StartAssertionOptionsBuilder::timeout → KILLED |
return this.timeout(Optional.ofNullable(timeout)); |
372 | } | |
373 | } | |
374 | } | |
Mutations | ||
105 |
1.1 |
|
133 |
1.1 |
|
148 |
1.1 |
|
162 |
1.1 |
|
197 |
1.1 |
|
199 |
1.1 |
|
202 |
1.1 |
|
232 |
1.1 |
|
263 |
1.1 |
|
265 |
1.1 |
|
268 |
1.1 |
|
298 |
1.1 |
|
313 |
1.1 |
|
315 |
1.1 |
|
331 |
1.1 |
|
344 |
1.1 |
|
345 |
1.1 2.2 3.3 |
|
349 |
1.1 |
|
363 |
1.1 |
|
371 |
1.1 |