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 static com.yubico.internal.util.ExceptionUtil.assertTrue; | |
28 | import static com.yubico.internal.util.ExceptionUtil.wrapAndLog; | |
29 | ||
30 | import com.upokecenter.cbor.CBORObject; | |
31 | import com.yubico.internal.util.CertificateParser; | |
32 | import com.yubico.internal.util.OptionalUtil; | |
33 | import com.yubico.webauthn.attestation.AttestationTrustSource; | |
34 | import com.yubico.webauthn.attestation.AttestationTrustSource.TrustRootsResult; | |
35 | import com.yubico.webauthn.data.AttestationObject; | |
36 | import com.yubico.webauthn.data.AttestationType; | |
37 | import com.yubico.webauthn.data.AuthenticatorAttestationResponse; | |
38 | import com.yubico.webauthn.data.AuthenticatorSelectionCriteria; | |
39 | import com.yubico.webauthn.data.ByteArray; | |
40 | import com.yubico.webauthn.data.ClientRegistrationExtensionOutputs; | |
41 | import com.yubico.webauthn.data.CollectedClientData; | |
42 | import com.yubico.webauthn.data.PublicKeyCredential; | |
43 | import com.yubico.webauthn.data.PublicKeyCredentialCreationOptions; | |
44 | import com.yubico.webauthn.data.PublicKeyCredentialParameters; | |
45 | import com.yubico.webauthn.data.UserVerificationRequirement; | |
46 | import java.io.IOException; | |
47 | import java.security.InvalidAlgorithmParameterException; | |
48 | import java.security.NoSuchAlgorithmException; | |
49 | import java.security.cert.CertPath; | |
50 | import java.security.cert.CertPathValidator; | |
51 | import java.security.cert.CertPathValidatorException; | |
52 | import java.security.cert.CertificateException; | |
53 | import java.security.cert.CertificateFactory; | |
54 | import java.security.cert.PKIXCertPathValidatorResult; | |
55 | import java.security.cert.PKIXParameters; | |
56 | import java.security.cert.PKIXReason; | |
57 | import java.security.cert.TrustAnchor; | |
58 | import java.security.cert.X509Certificate; | |
59 | import java.security.spec.InvalidKeySpecException; | |
60 | import java.sql.Date; | |
61 | import java.time.Clock; | |
62 | import java.util.List; | |
63 | import java.util.Optional; | |
64 | import java.util.Set; | |
65 | import java.util.stream.Collectors; | |
66 | import lombok.AllArgsConstructor; | |
67 | import lombok.Value; | |
68 | import lombok.extern.slf4j.Slf4j; | |
69 | ||
70 | @Slf4j | |
71 | @AllArgsConstructor | |
72 | final class FinishRegistrationSteps { | |
73 | ||
74 | private static final String CLIENT_DATA_TYPE = "webauthn.create"; | |
75 | private static final ByteArray ZERO_AAGUID = | |
76 | new ByteArray(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); | |
77 | ||
78 | private final PublicKeyCredentialCreationOptions request; | |
79 | private final PublicKeyCredential< | |
80 | AuthenticatorAttestationResponse, ClientRegistrationExtensionOutputs> | |
81 | response; | |
82 | private final Optional<ByteArray> callerTokenBindingId; | |
83 | private final Set<String> origins; | |
84 | private final String rpId; | |
85 | private final boolean allowUntrustedAttestation; | |
86 | private final Optional<AttestationTrustSource> attestationTrustSource; | |
87 | private final CredentialRepository credentialRepository; | |
88 | private final Clock clock; | |
89 | private final boolean allowOriginPort; | |
90 | private final boolean allowOriginSubdomain; | |
91 | ||
92 | FinishRegistrationSteps(RelyingParty rp, FinishRegistrationOptions options) { | |
93 | this( | |
94 | options.getRequest(), | |
95 | options.getResponse(), | |
96 | options.getCallerTokenBindingId(), | |
97 | rp.getOrigins(), | |
98 | rp.getIdentity().getId(), | |
99 | rp.isAllowUntrustedAttestation(), | |
100 | rp.getAttestationTrustSource(), | |
101 | rp.getCredentialRepository(), | |
102 | rp.getClock(), | |
103 | rp.isAllowOriginPort(), | |
104 | rp.isAllowOriginSubdomain()); | |
105 | } | |
106 | ||
107 | public Step6 begin() { | |
108 |
1
1. begin : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps::begin → KILLED |
return new Step6(); |
109 | } | |
110 | ||
111 | public RegistrationResult run() { | |
112 |
1
1. run : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps::run → KILLED |
return begin().run(); |
113 | } | |
114 | ||
115 | interface Step<Next extends Step<?>> { | |
116 | Next nextStep(); | |
117 | ||
118 | void validate(); | |
119 | ||
120 | default Optional<RegistrationResult> result() { | |
121 | return Optional.empty(); | |
122 | } | |
123 | ||
124 | default Next next() { | |
125 |
1
1. next : removed call to com/yubico/webauthn/FinishRegistrationSteps$Step::validate → KILLED |
validate(); |
126 |
1
1. next : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step::next → KILLED |
return nextStep(); |
127 | } | |
128 | ||
129 | default RegistrationResult run() { | |
130 |
1
1. run : negated conditional → KILLED |
if (result().isPresent()) { |
131 |
1
1. run : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step::run → KILLED |
return result().get(); |
132 | } else { | |
133 |
1
1. run : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step::run → KILLED |
return next().run(); |
134 | } | |
135 | } | |
136 | } | |
137 | ||
138 | // Steps 1 through 4 are to create the request and run the client-side part | |
139 | ||
140 | // Step 5 is integrated into step 6 here | |
141 | ||
142 | @Value | |
143 | class Step6 implements Step<Step7> { | |
144 | @Override | |
145 | public void validate() { | |
146 |
2
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → SURVIVED 2. validate : negated conditional → KILLED |
assertTrue(clientData() != null, "Client data must not be null."); |
147 | } | |
148 | ||
149 | @Override | |
150 | public Step7 nextStep() { | |
151 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step6::nextStep → KILLED |
return new Step7(clientData()); |
152 | } | |
153 | ||
154 | public CollectedClientData clientData() { | |
155 |
1
1. clientData : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step6::clientData → KILLED |
return response.getResponse().getClientData(); |
156 | } | |
157 | } | |
158 | ||
159 | @Value | |
160 | class Step7 implements Step<Step8> { | |
161 | private final CollectedClientData clientData; | |
162 | ||
163 | @Override | |
164 | public void validate() { | |
165 |
1
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → KILLED |
assertTrue( |
166 | CLIENT_DATA_TYPE.equals(clientData.getType()), | |
167 | "The \"type\" in the client data must be exactly \"%s\", was: %s", | |
168 | CLIENT_DATA_TYPE, | |
169 | clientData.getType()); | |
170 | } | |
171 | ||
172 | @Override | |
173 | public Step8 nextStep() { | |
174 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step7::nextStep → KILLED |
return new Step8(clientData); |
175 | } | |
176 | } | |
177 | ||
178 | @Value | |
179 | class Step8 implements Step<Step9> { | |
180 | private final CollectedClientData clientData; | |
181 | ||
182 | @Override | |
183 | public void validate() { | |
184 |
1
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → KILLED |
assertTrue(request.getChallenge().equals(clientData.getChallenge()), "Incorrect challenge."); |
185 | } | |
186 | ||
187 | @Override | |
188 | public Step9 nextStep() { | |
189 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step8::nextStep → KILLED |
return new Step9(clientData); |
190 | } | |
191 | } | |
192 | ||
193 | @Value | |
194 | class Step9 implements Step<Step10> { | |
195 | private final CollectedClientData clientData; | |
196 | ||
197 | @Override | |
198 | public void validate() { | |
199 | final String responseOrigin = clientData.getOrigin(); | |
200 |
1
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → KILLED |
assertTrue( |
201 | OriginMatcher.isAllowed(responseOrigin, origins, allowOriginPort, allowOriginSubdomain), | |
202 | "Incorrect origin, please see the RelyingParty.origins setting: %s", | |
203 | responseOrigin); | |
204 | } | |
205 | ||
206 | @Override | |
207 | public Step10 nextStep() { | |
208 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step9::nextStep → KILLED |
return new Step10(clientData); |
209 | } | |
210 | } | |
211 | ||
212 | @Value | |
213 | class Step10 implements Step<Step11> { | |
214 | private final CollectedClientData clientData; | |
215 | ||
216 | @Override | |
217 | public void validate() { | |
218 | TokenBindingValidator.validate(clientData.getTokenBinding(), callerTokenBindingId); | |
219 | } | |
220 | ||
221 | @Override | |
222 | public Step11 nextStep() { | |
223 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step10::nextStep → KILLED |
return new Step11(); |
224 | } | |
225 | } | |
226 | ||
227 | @Value | |
228 | class Step11 implements Step<Step12> { | |
229 | @Override | |
230 | public void validate() { | |
231 |
2
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → SURVIVED 2. validate : negated conditional → KILLED |
assertTrue(clientDataJsonHash().size() == 32, "Failed to compute hash of client data"); |
232 | } | |
233 | ||
234 | @Override | |
235 | public Step12 nextStep() { | |
236 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step11::nextStep → KILLED |
return new Step12(clientDataJsonHash()); |
237 | } | |
238 | ||
239 | public ByteArray clientDataJsonHash() { | |
240 |
1
1. clientDataJsonHash : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step11::clientDataJsonHash → KILLED |
return Crypto.sha256(response.getResponse().getClientDataJSON()); |
241 | } | |
242 | } | |
243 | ||
244 | @Value | |
245 | class Step12 implements Step<Step13> { | |
246 | private final ByteArray clientDataJsonHash; | |
247 | ||
248 | @Override | |
249 | public void validate() { | |
250 |
2
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → SURVIVED 2. validate : negated conditional → KILLED |
assertTrue(attestation() != null, "Malformed attestation object."); |
251 | } | |
252 | ||
253 | @Override | |
254 | public Step13 nextStep() { | |
255 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step12::nextStep → KILLED |
return new Step13(clientDataJsonHash, attestation()); |
256 | } | |
257 | ||
258 | public AttestationObject attestation() { | |
259 |
1
1. attestation : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step12::attestation → KILLED |
return response.getResponse().getAttestation(); |
260 | } | |
261 | } | |
262 | ||
263 | @Value | |
264 | class Step13 implements Step<Step14> { | |
265 | private final ByteArray clientDataJsonHash; | |
266 | private final AttestationObject attestation; | |
267 | ||
268 | @Override | |
269 | public void validate() { | |
270 |
1
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → KILLED |
assertTrue( |
271 | Crypto.sha256(rpId) | |
272 | .equals(response.getResponse().getAttestation().getAuthenticatorData().getRpIdHash()), | |
273 | "Wrong RP ID hash."); | |
274 | } | |
275 | ||
276 | @Override | |
277 | public Step14 nextStep() { | |
278 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step13::nextStep → KILLED |
return new Step14(clientDataJsonHash, attestation); |
279 | } | |
280 | } | |
281 | ||
282 | @Value | |
283 | class Step14 implements Step<Step15> { | |
284 | private final ByteArray clientDataJsonHash; | |
285 | private final AttestationObject attestation; | |
286 | ||
287 | @Override | |
288 | public void validate() { | |
289 |
1
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → KILLED |
assertTrue( |
290 | response.getResponse().getParsedAuthenticatorData().getFlags().UP, | |
291 | "User Presence is required."); | |
292 | } | |
293 | ||
294 | @Override | |
295 | public Step15 nextStep() { | |
296 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step14::nextStep → KILLED |
return new Step15(clientDataJsonHash, attestation); |
297 | } | |
298 | } | |
299 | ||
300 | @Value | |
301 | class Step15 implements Step<Step16> { | |
302 | private final ByteArray clientDataJsonHash; | |
303 | private final AttestationObject attestation; | |
304 | ||
305 | @Override | |
306 | public void validate() { | |
307 | if (request | |
308 | .getAuthenticatorSelection() | |
309 | .flatMap(AuthenticatorSelectionCriteria::getUserVerification) | |
310 |
1
1. validate : negated conditional → KILLED |
.orElse(UserVerificationRequirement.PREFERRED) |
311 | == UserVerificationRequirement.REQUIRED) { | |
312 |
1
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → KILLED |
assertTrue( |
313 | response.getResponse().getParsedAuthenticatorData().getFlags().UV, | |
314 | "User Verification is required."); | |
315 | } | |
316 | } | |
317 | ||
318 | @Override | |
319 | public Step16 nextStep() { | |
320 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step15::nextStep → KILLED |
return new Step16(clientDataJsonHash, attestation); |
321 | } | |
322 | } | |
323 | ||
324 | @Value | |
325 | class Step16 implements Step<Step18> { | |
326 | private final ByteArray clientDataJsonHash; | |
327 | private final AttestationObject attestation; | |
328 | ||
329 | @Override | |
330 | public void validate() { | |
331 | final ByteArray publicKeyCose = | |
332 | response | |
333 | .getResponse() | |
334 | .getAttestation() | |
335 | .getAuthenticatorData() | |
336 | .getAttestedCredentialData() | |
337 | .get() | |
338 | .getCredentialPublicKey(); | |
339 | CBORObject publicKeyCbor = CBORObject.DecodeFromBytes(publicKeyCose.getBytes()); | |
340 | final int alg = publicKeyCbor.get(CBORObject.FromObject(3)).AsInt32(); | |
341 |
1
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → KILLED |
assertTrue( |
342 | request.getPubKeyCredParams().stream() | |
343 |
2
1. lambda$validate$0 : replaced boolean return with true for com/yubico/webauthn/FinishRegistrationSteps$Step16::lambda$validate$0 → KILLED 2. lambda$validate$0 : negated conditional → KILLED |
.anyMatch(pkcparam -> pkcparam.getAlg().getId() == alg), |
344 | "Unrequested credential key algorithm: got %d, expected one of: %s", | |
345 | alg, | |
346 | request.getPubKeyCredParams().stream() | |
347 | .map(PublicKeyCredentialParameters::getAlg) | |
348 | .collect(Collectors.toList())); | |
349 | try { | |
350 | WebAuthnCodecs.importCosePublicKey(publicKeyCose); | |
351 | } catch (IOException | InvalidKeySpecException | NoSuchAlgorithmException e) { | |
352 | throw wrapAndLog(log, "Failed to parse credential public key", e); | |
353 | } | |
354 | } | |
355 | ||
356 | @Override | |
357 | public Step18 nextStep() { | |
358 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step16::nextStep → KILLED |
return new Step18(clientDataJsonHash, attestation); |
359 | } | |
360 | } | |
361 | ||
362 | // Nothing to do for step 17 | |
363 | ||
364 | @Value | |
365 | class Step18 implements Step<Step19> { | |
366 | private final ByteArray clientDataJsonHash; | |
367 | private final AttestationObject attestation; | |
368 | ||
369 | @Override | |
370 | public void validate() {} | |
371 | ||
372 | @Override | |
373 | public Step19 nextStep() { | |
374 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step18::nextStep → KILLED |
return new Step19(clientDataJsonHash, attestation, attestationStatementVerifier()); |
375 | } | |
376 | ||
377 | public String format() { | |
378 |
1
1. format : replaced return value with "" for com/yubico/webauthn/FinishRegistrationSteps$Step18::format → KILLED |
return attestation.getFormat(); |
379 | } | |
380 | ||
381 | public Optional<AttestationStatementVerifier> attestationStatementVerifier() { | |
382 | switch (format()) { | |
383 | case "fido-u2f": | |
384 |
1
1. attestationStatementVerifier : replaced return value with Optional.empty for com/yubico/webauthn/FinishRegistrationSteps$Step18::attestationStatementVerifier → KILLED |
return Optional.of(new FidoU2fAttestationStatementVerifier()); |
385 | case "none": | |
386 |
1
1. attestationStatementVerifier : replaced return value with Optional.empty for com/yubico/webauthn/FinishRegistrationSteps$Step18::attestationStatementVerifier → KILLED |
return Optional.of(new NoneAttestationStatementVerifier()); |
387 | case "packed": | |
388 |
1
1. attestationStatementVerifier : replaced return value with Optional.empty for com/yubico/webauthn/FinishRegistrationSteps$Step18::attestationStatementVerifier → KILLED |
return Optional.of(new PackedAttestationStatementVerifier()); |
389 | case "android-safetynet": | |
390 |
1
1. attestationStatementVerifier : replaced return value with Optional.empty for com/yubico/webauthn/FinishRegistrationSteps$Step18::attestationStatementVerifier → KILLED |
return Optional.of(new AndroidSafetynetAttestationStatementVerifier()); |
391 | case "apple": | |
392 |
1
1. attestationStatementVerifier : replaced return value with Optional.empty for com/yubico/webauthn/FinishRegistrationSteps$Step18::attestationStatementVerifier → KILLED |
return Optional.of(new AppleAttestationStatementVerifier()); |
393 | case "tpm": | |
394 |
1
1. attestationStatementVerifier : replaced return value with Optional.empty for com/yubico/webauthn/FinishRegistrationSteps$Step18::attestationStatementVerifier → KILLED |
return Optional.of(new TpmAttestationStatementVerifier()); |
395 | default: | |
396 | return Optional.empty(); | |
397 | } | |
398 | } | |
399 | } | |
400 | ||
401 | @Value | |
402 | class Step19 implements Step<Step20> { | |
403 | private final ByteArray clientDataJsonHash; | |
404 | private final AttestationObject attestation; | |
405 | private final Optional<AttestationStatementVerifier> attestationStatementVerifier; | |
406 | ||
407 | @Override | |
408 | public void validate() { | |
409 |
1
1. validate : removed call to java/util/Optional::ifPresent → KILLED |
attestationStatementVerifier.ifPresent( |
410 | verifier -> { | |
411 |
1
1. lambda$validate$0 : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → KILLED |
assertTrue( |
412 | verifier.verifyAttestationSignature(attestation, clientDataJsonHash), | |
413 | "Invalid attestation signature."); | |
414 | }); | |
415 | ||
416 |
2
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → SURVIVED 2. validate : negated conditional → KILLED |
assertTrue(attestationType() != null, "Failed to determine attestation type"); |
417 | } | |
418 | ||
419 | @Override | |
420 | public Step20 nextStep() { | |
421 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step19::nextStep → KILLED |
return new Step20(attestation, attestationType(), attestationTrustPath()); |
422 | } | |
423 | ||
424 | public AttestationType attestationType() { | |
425 | try { | |
426 |
1
1. attestationType : negated conditional → KILLED |
if (attestationStatementVerifier.isPresent()) { |
427 |
1
1. attestationType : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step19::attestationType → KILLED |
return attestationStatementVerifier.get().getAttestationType(attestation); |
428 | } else { | |
429 |
1
1. attestationType : negated conditional → SURVIVED |
switch (attestation.getFormat()) { |
430 | case "android-key": | |
431 | // TODO delete this once android-key attestation verification is implemented | |
432 |
1
1. attestationType : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step19::attestationType → KILLED |
return AttestationType.BASIC; |
433 | default: | |
434 |
1
1. attestationType : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step19::attestationType → KILLED |
return AttestationType.UNKNOWN; |
435 | } | |
436 | } | |
437 | } catch (IOException | CertificateException e) { | |
438 | throw new IllegalArgumentException("Failed to resolve attestation type.", e); | |
439 | } | |
440 | } | |
441 | ||
442 | public Optional<List<X509Certificate>> attestationTrustPath() { | |
443 |
1
1. attestationTrustPath : negated conditional → KILLED |
if (attestationStatementVerifier.isPresent()) { |
444 | AttestationStatementVerifier verifier = attestationStatementVerifier.get(); | |
445 |
1
1. attestationTrustPath : negated conditional → KILLED |
if (verifier instanceof X5cAttestationStatementVerifier) { |
446 | try { | |
447 |
1
1. attestationTrustPath : replaced return value with Optional.empty for com/yubico/webauthn/FinishRegistrationSteps$Step19::attestationTrustPath → KILLED |
return ((X5cAttestationStatementVerifier) verifier) |
448 | .getAttestationTrustPath(attestation); | |
449 | } catch (CertificateException e) { | |
450 | throw new IllegalArgumentException("Failed to resolve attestation trust path.", e); | |
451 | } | |
452 | } else { | |
453 | return Optional.empty(); | |
454 | } | |
455 | } else { | |
456 | return Optional.empty(); | |
457 | } | |
458 | } | |
459 | } | |
460 | ||
461 | @Value | |
462 | class Step20 implements Step<Step21> { | |
463 | private final AttestationObject attestation; | |
464 | private final AttestationType attestationType; | |
465 | private final Optional<List<X509Certificate>> attestationTrustPath; | |
466 | ||
467 | private final Optional<AttestationTrustSource.TrustRootsResult> trustRoots; | |
468 | ||
469 | public Step20( | |
470 | AttestationObject attestation, | |
471 | AttestationType attestationType, | |
472 | Optional<List<X509Certificate>> attestationTrustPath) { | |
473 | this.attestation = attestation; | |
474 | this.attestationType = attestationType; | |
475 | this.attestationTrustPath = attestationTrustPath; | |
476 | this.trustRoots = findTrustRoots(); | |
477 | } | |
478 | ||
479 | @Override | |
480 | public void validate() {} | |
481 | ||
482 | @Override | |
483 | public Step21 nextStep() { | |
484 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step20::nextStep → KILLED |
return new Step21(attestation, attestationType, attestationTrustPath, trustRoots); |
485 | } | |
486 | ||
487 | private Optional<AttestationTrustSource.TrustRootsResult> findTrustRoots() { | |
488 |
1
1. findTrustRoots : replaced return value with Optional.empty for com/yubico/webauthn/FinishRegistrationSteps$Step20::findTrustRoots → KILLED |
return attestationTrustSource.flatMap( |
489 | attestationTrustSource -> | |
490 |
1
1. lambda$findTrustRoots$3 : replaced return value with Optional.empty for com/yubico/webauthn/FinishRegistrationSteps$Step20::lambda$findTrustRoots$3 → KILLED |
attestationTrustPath.map( |
491 | atp -> | |
492 |
1
1. lambda$findTrustRoots$2 : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step20::lambda$findTrustRoots$2 → KILLED |
attestationTrustSource.findTrustRoots( |
493 | atp, | |
494 | OptionalUtil.orElseOptional( | |
495 | Optional.of( | |
496 | attestation | |
497 | .getAuthenticatorData() | |
498 | .getAttestedCredentialData() | |
499 | .get() | |
500 | .getAaguid()) | |
501 |
2
1. lambda$findTrustRoots$0 : negated conditional → KILLED 2. lambda$findTrustRoots$0 : replaced boolean return with true for com/yubico/webauthn/FinishRegistrationSteps$Step20::lambda$findTrustRoots$0 → KILLED |
.filter(aaguid -> !aaguid.equals(ZERO_AAGUID)), |
502 | () -> { | |
503 |
1
1. lambda$findTrustRoots$1 : negated conditional → KILLED |
if (!atp.isEmpty()) { |
504 |
1
1. lambda$findTrustRoots$1 : replaced return value with Optional.empty for com/yubico/webauthn/FinishRegistrationSteps$Step20::lambda$findTrustRoots$1 → KILLED |
return CertificateParser.parseFidoAaguidExtension(atp.get(0)) |
505 | .map(ByteArray::new); | |
506 | } else { | |
507 | return Optional.empty(); | |
508 | } | |
509 | })))); | |
510 | } | |
511 | } | |
512 | ||
513 | @Value | |
514 | class Step21 implements Step<Step22> { | |
515 | private final AttestationObject attestation; | |
516 | private final AttestationType attestationType; | |
517 | private final Optional<List<X509Certificate>> attestationTrustPath; | |
518 | private final Optional<AttestationTrustSource.TrustRootsResult> trustRoots; | |
519 | ||
520 | private final boolean attestationTrusted; | |
521 | ||
522 | public Step21( | |
523 | AttestationObject attestation, | |
524 | AttestationType attestationType, | |
525 | Optional<List<X509Certificate>> attestationTrustPath, | |
526 | Optional<AttestationTrustSource.TrustRootsResult> trustRoots) { | |
527 | this.attestation = attestation; | |
528 | this.attestationType = attestationType; | |
529 | this.attestationTrustPath = attestationTrustPath; | |
530 | this.trustRoots = trustRoots; | |
531 | ||
532 | this.attestationTrusted = attestationTrusted(); | |
533 | } | |
534 | ||
535 | @Override | |
536 | public void validate() { | |
537 |
1
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → KILLED |
assertTrue( |
538 |
2
1. validate : negated conditional → KILLED 2. validate : negated conditional → KILLED |
allowUntrustedAttestation || attestationTrusted, |
539 | "Failed to derive trust for attestation key."); | |
540 | } | |
541 | ||
542 | @Override | |
543 | public Step22 nextStep() { | |
544 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step21::nextStep → KILLED |
return new Step22(attestationType, attestationTrusted, attestationTrustPath); |
545 | } | |
546 | ||
547 | public boolean attestationTrusted() { | |
548 |
2
1. attestationTrusted : negated conditional → KILLED 2. attestationTrusted : negated conditional → KILLED |
if (attestationTrustPath.isPresent() && attestationTrustSource.isPresent()) { |
549 | try { | |
550 |
2
1. attestationTrusted : negated conditional → KILLED 2. attestationTrusted : negated conditional → KILLED |
if (!trustRoots.isPresent() || trustRoots.get().getTrustRoots().isEmpty()) { |
551 |
1
1. attestationTrusted : replaced boolean return with true for com/yubico/webauthn/FinishRegistrationSteps$Step21::attestationTrusted → KILLED |
return false; |
552 | ||
553 | } else { | |
554 | final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); | |
555 | final CertPathValidator cpv = CertPathValidator.getInstance("PKIX"); | |
556 | final CertPath certPath = certFactory.generateCertPath(attestationTrustPath.get()); | |
557 | final PKIXParameters pathParams = | |
558 | new PKIXParameters( | |
559 | trustRoots.get().getTrustRoots().stream() | |
560 |
1
1. lambda$attestationTrusted$0 : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step21::lambda$attestationTrusted$0 → KILLED |
.map(rootCert -> new TrustAnchor(rootCert, null)) |
561 | .collect(Collectors.toSet())); | |
562 |
1
1. attestationTrusted : removed call to java/security/cert/PKIXParameters::setDate → KILLED |
pathParams.setDate(Date.from(clock.instant())); |
563 |
1
1. attestationTrusted : removed call to java/security/cert/PKIXParameters::setRevocationEnabled → KILLED |
pathParams.setRevocationEnabled(trustRoots.get().isEnableRevocationChecking()); |
564 |
1
1. attestationTrusted : removed call to java/security/cert/PKIXParameters::setPolicyQualifiersRejected → SURVIVED |
pathParams.setPolicyQualifiersRejected( |
565 |
1
1. attestationTrusted : negated conditional → SURVIVED |
!trustRoots.get().getPolicyTreeValidator().isPresent()); |
566 |
1
1. attestationTrusted : removed call to java/util/Optional::ifPresent → KILLED |
trustRoots.get().getCertStore().ifPresent(pathParams::addCertStore); |
567 | final PKIXCertPathValidatorResult result = | |
568 | (PKIXCertPathValidatorResult) cpv.validate(certPath, pathParams); | |
569 |
2
1. attestationTrusted : replaced boolean return with true for com/yubico/webauthn/FinishRegistrationSteps$Step21::attestationTrusted → KILLED 2. attestationTrusted : replaced boolean return with false for com/yubico/webauthn/FinishRegistrationSteps$Step21::attestationTrusted → KILLED |
return trustRoots |
570 | .get() | |
571 | .getPolicyTreeValidator() | |
572 | .map( | |
573 | policyNodePredicate -> { | |
574 |
1
1. lambda$attestationTrusted$1 : negated conditional → KILLED |
if (policyNodePredicate.test(result.getPolicyTree())) { |
575 |
1
1. lambda$attestationTrusted$1 : replaced Boolean return with False for com/yubico/webauthn/FinishRegistrationSteps$Step21::lambda$attestationTrusted$1 → KILLED |
return true; |
576 | } else { | |
577 | log.info( | |
578 | "Failed to derive trust in attestation statement: Certificate path policy tree does not satisfy policy tree validator. Attestation object: {}", | |
579 | response.getResponse().getAttestationObject()); | |
580 |
1
1. lambda$attestationTrusted$1 : replaced Boolean return with True for com/yubico/webauthn/FinishRegistrationSteps$Step21::lambda$attestationTrusted$1 → KILLED |
return false; |
581 | } | |
582 | }) | |
583 | .orElse(true); | |
584 | } | |
585 | ||
586 | } catch (CertPathValidatorException e) { | |
587 | log.info( | |
588 | "Failed to derive trust in attestation statement: {} at cert index {}: {}. Attestation object: {}", | |
589 | e.getReason(), | |
590 | e.getIndex(), | |
591 | e.getMessage(), | |
592 | response.getResponse().getAttestationObject()); | |
593 |
1
1. attestationTrusted : negated conditional → SURVIVED |
if (PKIXReason.INVALID_POLICY.equals(e.getReason())) { |
594 | log.info( | |
595 | "You may need to set the policyTreeValidator property on the {} returned by your {}.", | |
596 | TrustRootsResult.class.getSimpleName(), | |
597 | AttestationTrustSource.class.getSimpleName()); | |
598 | } | |
599 |
1
1. attestationTrusted : replaced boolean return with true for com/yubico/webauthn/FinishRegistrationSteps$Step21::attestationTrusted → SURVIVED |
return false; |
600 | ||
601 | } catch (CertificateException e) { | |
602 | log.warn( | |
603 | "Failed to build attestation certificate path. Attestation object: {}", | |
604 | response.getResponse().getAttestationObject(), | |
605 | e); | |
606 |
1
1. attestationTrusted : replaced boolean return with true for com/yubico/webauthn/FinishRegistrationSteps$Step21::attestationTrusted → NO_COVERAGE |
return false; |
607 | ||
608 | } catch (NoSuchAlgorithmException e) { | |
609 | throw new RuntimeException( | |
610 | "Failed to check attestation trust path. A JCA provider is likely missing in the runtime environment.", | |
611 | e); | |
612 | ||
613 | } catch (InvalidAlgorithmParameterException e) { | |
614 | throw new RuntimeException( | |
615 | "Failed to initialize attestation trust path validator. This is likely a bug, please file a bug report.", | |
616 | e); | |
617 | } | |
618 | } else { | |
619 |
1
1. attestationTrusted : replaced boolean return with true for com/yubico/webauthn/FinishRegistrationSteps$Step21::attestationTrusted → KILLED |
return false; |
620 | } | |
621 | } | |
622 | } | |
623 | ||
624 | @Value | |
625 | class Step22 implements Step<Finished> { | |
626 | private final AttestationType attestationType; | |
627 | private final boolean attestationTrusted; | |
628 | private final Optional<List<X509Certificate>> attestationTrustPath; | |
629 | ||
630 | @Override | |
631 | public void validate() { | |
632 |
1
1. validate : removed call to com/yubico/internal/util/ExceptionUtil::assertTrue → KILLED |
assertTrue( |
633 | credentialRepository.lookupAll(response.getId()).isEmpty(), | |
634 | "Credential ID is already registered: %s", | |
635 | response.getId()); | |
636 | } | |
637 | ||
638 | @Override | |
639 | public Finished nextStep() { | |
640 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Step22::nextStep → KILLED |
return new Finished(attestationType, attestationTrusted, attestationTrustPath); |
641 | } | |
642 | } | |
643 | ||
644 | // Step 23 will be performed externally by library user | |
645 | // Nothing to do for step 24 | |
646 | ||
647 | @Value | |
648 | class Finished implements Step<Finished> { | |
649 | private final AttestationType attestationType; | |
650 | private final boolean attestationTrusted; | |
651 | private final Optional<List<X509Certificate>> attestationTrustPath; | |
652 | ||
653 | @Override | |
654 | public void validate() { | |
655 | /* No-op */ | |
656 | } | |
657 | ||
658 | @Override | |
659 | public Finished nextStep() { | |
660 |
1
1. nextStep : replaced return value with null for com/yubico/webauthn/FinishRegistrationSteps$Finished::nextStep → NO_COVERAGE |
return this; |
661 | } | |
662 | ||
663 | @Override | |
664 | public Optional<RegistrationResult> result() { | |
665 |
1
1. result : replaced return value with Optional.empty for com/yubico/webauthn/FinishRegistrationSteps$Finished::result → KILLED |
return Optional.of( |
666 | new RegistrationResult( | |
667 | response, attestationTrusted, attestationType, attestationTrustPath)); | |
668 | } | |
669 | } | |
670 | } | |
Mutations | ||
108 |
1.1 |
|
112 |
1.1 |
|
125 |
1.1 |
|
126 |
1.1 |
|
130 |
1.1 |
|
131 |
1.1 |
|
133 |
1.1 |
|
146 |
1.1 2.2 |
|
151 |
1.1 |
|
155 |
1.1 |
|
165 |
1.1 |
|
174 |
1.1 |
|
184 |
1.1 |
|
189 |
1.1 |
|
200 |
1.1 |
|
208 |
1.1 |
|
223 |
1.1 |
|
231 |
1.1 2.2 |
|
236 |
1.1 |
|
240 |
1.1 |
|
250 |
1.1 2.2 |
|
255 |
1.1 |
|
259 |
1.1 |
|
270 |
1.1 |
|
278 |
1.1 |
|
289 |
1.1 |
|
296 |
1.1 |
|
310 |
1.1 |
|
312 |
1.1 |
|
320 |
1.1 |
|
341 |
1.1 |
|
343 |
1.1 2.2 |
|
358 |
1.1 |
|
374 |
1.1 |
|
378 |
1.1 |
|
384 |
1.1 |
|
386 |
1.1 |
|
388 |
1.1 |
|
390 |
1.1 |
|
392 |
1.1 |
|
394 |
1.1 |
|
409 |
1.1 |
|
411 |
1.1 |
|
416 |
1.1 2.2 |
|
421 |
1.1 |
|
426 |
1.1 |
|
427 |
1.1 |
|
429 |
1.1 |
|
432 |
1.1 |
|
434 |
1.1 |
|
443 |
1.1 |
|
445 |
1.1 |
|
447 |
1.1 |
|
484 |
1.1 |
|
488 |
1.1 |
|
490 |
1.1 |
|
492 |
1.1 |
|
501 |
1.1 2.2 |
|
503 |
1.1 |
|
504 |
1.1 |
|
537 |
1.1 |
|
538 |
1.1 2.2 |
|
544 |
1.1 |
|
548 |
1.1 2.2 |
|
550 |
1.1 2.2 |
|
551 |
1.1 |
|
560 |
1.1 |
|
562 |
1.1 |
|
563 |
1.1 |
|
564 |
1.1 |
|
565 |
1.1 |
|
566 |
1.1 |
|
569 |
1.1 2.2 |
|
574 |
1.1 |
|
575 |
1.1 |
|
580 |
1.1 |
|
593 |
1.1 |
|
599 |
1.1 |
|
606 |
1.1 |
|
619 |
1.1 |
|
632 |
1.1 |
|
640 |
1.1 |
|
660 |
1.1 |
|
665 |
1.1 |