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.JsonProperty; | |
29 | import com.yubico.internal.util.CollectionUtil; | |
30 | import com.yubico.internal.util.ComparableUtil; | |
31 | import com.yubico.webauthn.RegistrationResult; | |
32 | import java.util.Optional; | |
33 | import java.util.Set; | |
34 | import java.util.SortedSet; | |
35 | import java.util.TreeSet; | |
36 | import lombok.Builder; | |
37 | import lombok.NonNull; | |
38 | import lombok.Value; | |
39 | ||
40 | /** | |
41 | * The attributes that are specified by a caller when referring to a public key credential as an | |
42 | * input parameter to the <code>navigator.credentials.create()</code> or <code> | |
43 | * navigator.credentials.get()</code> methods. It mirrors the fields of the {@link | |
44 | * PublicKeyCredential} object returned by the latter methods. | |
45 | * | |
46 | * @see <a | |
47 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#dictdef-publickeycredentialdescriptor">§5.10.3. | |
48 | * Credential Descriptor (dictionary PublicKeyCredentialDescriptor)</a> | |
49 | */ | |
50 | @Value | |
51 | @Builder(toBuilder = true) | |
52 | public class PublicKeyCredentialDescriptor implements Comparable<PublicKeyCredentialDescriptor> { | |
53 | ||
54 | /** The type of the credential the caller is referring to. */ | |
55 | @NonNull @Builder.Default | |
56 | private final PublicKeyCredentialType type = PublicKeyCredentialType.PUBLIC_KEY; | |
57 | ||
58 | /** The credential ID of the public key credential the caller is referring to. */ | |
59 | @NonNull private final ByteArray id; | |
60 | ||
61 | /** | |
62 | * An OPTIONAL hint as to how the client might communicate with the managing authenticator of the | |
63 | * public key credential the caller is referring to. | |
64 | * | |
65 | * <p>This SHOULD be stored along with the {@link #getId() id} and used unmodified whenever | |
66 | * creating a {@link PublicKeyCredentialDescriptor} for this credential. | |
67 | */ | |
68 | private final SortedSet<AuthenticatorTransport> transports; | |
69 | ||
70 | @JsonCreator | |
71 | private PublicKeyCredentialDescriptor( | |
72 |
1
1. <init> : negated conditional → KILLED |
@NonNull @JsonProperty("type") PublicKeyCredentialType type, |
73 |
1
1. <init> : negated conditional → KILLED |
@NonNull @JsonProperty("id") ByteArray id, |
74 | @JsonProperty("transports") Set<AuthenticatorTransport> transports) { | |
75 | this.type = type; | |
76 | this.id = id; | |
77 | this.transports = | |
78 |
1
1. <init> : negated conditional → KILLED |
transports == null ? null : CollectionUtil.immutableSortedSet(new TreeSet<>(transports)); |
79 | } | |
80 | ||
81 | @Override | |
82 | public int compareTo(PublicKeyCredentialDescriptor other) { | |
83 | int idComparison = id.compareTo(other.id); | |
84 |
1
1. compareTo : negated conditional → KILLED |
if (idComparison != 0) { |
85 |
1
1. compareTo : replaced int return with 0 for com/yubico/webauthn/data/PublicKeyCredentialDescriptor::compareTo → KILLED |
return idComparison; |
86 | } | |
87 | ||
88 |
1
1. compareTo : negated conditional → KILLED |
if (type.compareTo(other.type) != 0) { |
89 |
1
1. compareTo : replaced int return with 0 for com/yubico/webauthn/data/PublicKeyCredentialDescriptor::compareTo → NO_COVERAGE |
return type.compareTo(other.type); |
90 | } | |
91 | ||
92 |
2
1. compareTo : negated conditional → KILLED 2. compareTo : negated conditional → KILLED |
if (!getTransports().isPresent() && other.getTransports().isPresent()) { |
93 |
1
1. compareTo : replaced int return with 0 for com/yubico/webauthn/data/PublicKeyCredentialDescriptor::compareTo → SURVIVED |
return -1; |
94 |
2
1. compareTo : negated conditional → KILLED 2. compareTo : negated conditional → KILLED |
} else if (getTransports().isPresent() && !other.getTransports().isPresent()) { |
95 |
1
1. compareTo : replaced int return with 0 for com/yubico/webauthn/data/PublicKeyCredentialDescriptor::compareTo → KILLED |
return 1; |
96 |
2
1. compareTo : negated conditional → KILLED 2. compareTo : negated conditional → KILLED |
} else if (getTransports().isPresent() && other.getTransports().isPresent()) { |
97 | int transportsComparison = | |
98 | ComparableUtil.compareComparableSets(getTransports().get(), other.getTransports().get()); | |
99 |
1
1. compareTo : negated conditional → KILLED |
if (transportsComparison != 0) { |
100 |
1
1. compareTo : replaced int return with 0 for com/yubico/webauthn/data/PublicKeyCredentialDescriptor::compareTo → KILLED |
return transportsComparison; |
101 | } | |
102 | } | |
103 | ||
104 | return 0; | |
105 | } | |
106 | ||
107 | public static PublicKeyCredentialDescriptorBuilder.MandatoryStages builder() { | |
108 |
1
1. builder : replaced return value with null for com/yubico/webauthn/data/PublicKeyCredentialDescriptor::builder → KILLED |
return new PublicKeyCredentialDescriptorBuilder.MandatoryStages(); |
109 | } | |
110 | ||
111 | public static class PublicKeyCredentialDescriptorBuilder { | |
112 | private Set<AuthenticatorTransport> transports = null; | |
113 | ||
114 | public static class MandatoryStages { | |
115 | private final PublicKeyCredentialDescriptorBuilder builder = | |
116 | new PublicKeyCredentialDescriptorBuilder(); | |
117 | ||
118 | /** | |
119 | * {@link PublicKeyCredentialDescriptorBuilder#id(ByteArray) id} is a required parameter. | |
120 | * | |
121 | * @see PublicKeyCredentialDescriptorBuilder#id(ByteArray) | |
122 | */ | |
123 | public PublicKeyCredentialDescriptorBuilder id(ByteArray id) { | |
124 |
1
1. id : replaced return value with null for com/yubico/webauthn/data/PublicKeyCredentialDescriptor$PublicKeyCredentialDescriptorBuilder$MandatoryStages::id → KILLED |
return builder.id(id); |
125 | } | |
126 | } | |
127 | ||
128 | /** | |
129 | * An OPTIONAL hint as to how the client might communicate with the managing authenticator of | |
130 | * the public key credential the caller is referring to. | |
131 | * | |
132 | * <p>This SHOULD be set to the unmodified value returned from {@link | |
133 | * RegistrationResult#getKeyId()}.{@link #getTransports()} when the credential was registered. | |
134 | */ | |
135 | public PublicKeyCredentialDescriptorBuilder transports( | |
136 |
1
1. transports : negated conditional → KILLED |
@NonNull Optional<Set<AuthenticatorTransport>> transports) { |
137 |
1
1. transports : replaced return value with null for com/yubico/webauthn/data/PublicKeyCredentialDescriptor$PublicKeyCredentialDescriptorBuilder::transports → KILLED |
return this.transports(transports.orElse(null)); |
138 | } | |
139 | ||
140 | /** | |
141 | * An OPTIONAL hint as to how the client might communicate with the managing authenticator of | |
142 | * the public key credential the caller is referring to. | |
143 | * | |
144 | * <p>This SHOULD be set to the unmodified value returned from {@link | |
145 | * RegistrationResult#getKeyId()}.{@link #getTransports()} when the credential was registered. | |
146 | */ | |
147 | public PublicKeyCredentialDescriptorBuilder transports(Set<AuthenticatorTransport> transports) { | |
148 | this.transports = transports; | |
149 |
1
1. transports : replaced return value with null for com/yubico/webauthn/data/PublicKeyCredentialDescriptor$PublicKeyCredentialDescriptorBuilder::transports → KILLED |
return this; |
150 | } | |
151 | } | |
152 | ||
153 | public Optional<SortedSet<AuthenticatorTransport>> getTransports() { | |
154 |
1
1. getTransports : replaced return value with Optional.empty for com/yubico/webauthn/data/PublicKeyCredentialDescriptor::getTransports → KILLED |
return Optional.ofNullable(transports); |
155 | } | |
156 | } | |
Mutations | ||
72 |
1.1 |
|
73 |
1.1 |
|
78 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
88 |
1.1 |
|
89 |
1.1 |
|
92 |
1.1 2.2 |
|
93 |
1.1 |
|
94 |
1.1 2.2 |
|
95 |
1.1 |
|
96 |
1.1 2.2 |
|
99 |
1.1 |
|
100 |
1.1 |
|
108 |
1.1 |
|
124 |
1.1 |
|
136 |
1.1 |
|
137 |
1.1 |
|
149 |
1.1 |
|
154 |
1.1 |