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.data; | |
26 | ||
27 | import com.fasterxml.jackson.annotation.JsonCreator; | |
28 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |
29 | import com.fasterxml.jackson.annotation.JsonProperty; | |
30 | import com.upokecenter.cbor.CBORObject; | |
31 | import com.yubico.internal.util.CollectionUtil; | |
32 | import java.util.HashSet; | |
33 | import java.util.List; | |
34 | import java.util.Optional; | |
35 | import java.util.Set; | |
36 | import lombok.Builder; | |
37 | import lombok.EqualsAndHashCode; | |
38 | import lombok.Value; | |
39 | import lombok.extern.slf4j.Slf4j; | |
40 | ||
41 | /** | |
42 | * Contains <a | |
43 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-extension-output">authenticator | |
44 | * extension outputs</a> from a <code>navigator.credentials.create()</code> operation. | |
45 | * | |
46 | * <p>Note that there is no guarantee that any extension input present in {@link | |
47 | * RegistrationExtensionInputs} will have a corresponding output present here. | |
48 | * | |
49 | * <p>The values contained here are parsed from the {@link AuthenticatorData} structure. | |
50 | * | |
51 | * <p>The client extension outputs are represented by the {@link ClientRegistrationExtensionOutputs} | |
52 | * type. | |
53 | * | |
54 | * @see <a href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#sctn-extensions">§9. WebAuthn | |
55 | * Extensions</a> | |
56 | */ | |
57 | @Value | |
58 | @Builder(toBuilder = true) | |
59 | @Slf4j | |
60 | @JsonIgnoreProperties(ignoreUnknown = true) | |
61 | public final class AuthenticatorAssertionExtensionOutputs implements AuthenticatorExtensionOutputs { | |
62 | ||
63 | private final List<Extensions.Uvm.UvmEntry> uvm; | |
64 | ||
65 | @JsonCreator | |
66 | private AuthenticatorAssertionExtensionOutputs( | |
67 | @JsonProperty("uvm") List<Extensions.Uvm.UvmEntry> uvm) { | |
68 |
1
1. <init> : negated conditional → KILLED |
this.uvm = uvm == null ? null : CollectionUtil.immutableList(uvm); |
69 | } | |
70 | ||
71 | /** | |
72 | * Parse <a | |
73 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authentication-extension">authentication</a> | |
74 | * <a | |
75 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-extension-output">authenticator | |
76 | * extension outputs</a> from the given authenticator data. | |
77 | * | |
78 | * <p>If the <code>authData</code> does not contain authenticator extension outputs, this returns | |
79 | * an empty {@link Optional}. | |
80 | * | |
81 | * <p>Otherwise, this returns a present {@link Optional} containing an {@link | |
82 | * AuthenticatorAssertionExtensionOutputs} value with all validly-formatted <a | |
83 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authentication-extension">authentication</a> | |
84 | * <a | |
85 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-extension-output">extension | |
86 | * outputs</a> supported by this library. This silently ignores <a | |
87 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#registration-extension">registration</a> | |
88 | * extension outputs, malformed extension outputs, and unsupported extensions. The raw set of | |
89 | * extension outputs can instead be obtained via {@link AuthenticatorData#getExtensions()}. | |
90 | * | |
91 | * <p>Note that a present {@link AuthenticatorAssertionExtensionOutputs} may contain zero | |
92 | * extension outputs. | |
93 | * | |
94 | * @param authData the <a | |
95 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-data">authenticator | |
96 | * data</a> to parse extension outputs from | |
97 | * @return an empty {@link Optional} if the <code>authData</code> does not contain authenticator | |
98 | * extension outputs. Otherwise a present {@link Optional} containing parsed extension output | |
99 | * values. | |
100 | */ | |
101 | public static Optional<AuthenticatorAssertionExtensionOutputs> fromAuthenticatorData( | |
102 | AuthenticatorData authData) { | |
103 |
1
1. fromAuthenticatorData : replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorAssertionExtensionOutputs::fromAuthenticatorData → KILLED |
return authData.getExtensions().flatMap(AuthenticatorAssertionExtensionOutputs::fromCbor); |
104 | } | |
105 | ||
106 | static Optional<AuthenticatorAssertionExtensionOutputs> fromCbor(CBORObject cbor) { | |
107 | AuthenticatorAssertionExtensionOutputs.AuthenticatorAssertionExtensionOutputsBuilder b = | |
108 | builder(); | |
109 | ||
110 |
1
1. fromCbor : removed call to java/util/Optional::ifPresent → KILLED |
Extensions.Uvm.parseAuthenticatorExtensionOutput(cbor).ifPresent(b::uvm); |
111 | ||
112 | AuthenticatorAssertionExtensionOutputs result = b.build(); | |
113 | ||
114 |
1
1. fromCbor : negated conditional → KILLED |
if (result.getExtensionIds().isEmpty()) { |
115 | return Optional.empty(); | |
116 | } else { | |
117 |
1
1. fromCbor : replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorAssertionExtensionOutputs::fromCbor → KILLED |
return Optional.of(result); |
118 | } | |
119 | } | |
120 | ||
121 | @Override | |
122 | @EqualsAndHashCode.Include | |
123 | public Set<String> getExtensionIds() { | |
124 | HashSet<String> ids = new HashSet<>(); | |
125 |
1
1. getExtensionIds : negated conditional → KILLED |
if (uvm != null) { |
126 | ids.add(Extensions.Uvm.EXTENSION_ID); | |
127 | } | |
128 |
1
1. getExtensionIds : replaced return value with Collections.emptySet for com/yubico/webauthn/data/AuthenticatorAssertionExtensionOutputs::getExtensionIds → KILLED |
return ids; |
129 | } | |
130 | ||
131 | /** | |
132 | * @return The <a | |
133 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-extension-output">authenticator | |
134 | * extension output</a> for the <a | |
135 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#sctn-uvm-extension">User | |
136 | * Verification Method (<code>uvm</code>) extension</a>, if any. | |
137 | * @see <a href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#sctn-uvm-extension">§10.3. | |
138 | * User Verification Method extension (uvm)</a> | |
139 | */ | |
140 | public Optional<List<Extensions.Uvm.UvmEntry>> getUvm() { | |
141 |
1
1. getUvm : replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorAssertionExtensionOutputs::getUvm → KILLED |
return Optional.ofNullable(uvm); |
142 | } | |
143 | } | |
Mutations | ||
68 |
1.1 |
|
103 |
1.1 |
|
110 |
1.1 |
|
114 |
1.1 |
|
117 |
1.1 |
|
125 |
1.1 |
|
128 |
1.1 |
|
141 |
1.1 |