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