| 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 java.util.Optional; | |
| 30 | import lombok.Builder; | |
| 31 | import lombok.NonNull; | |
| 32 | import lombok.Value; | |
| 33 | ||
| 34 | /** | |
| 35 | * This class may be used to specify requirements regarding authenticator attributes. | |
| 36 | * | |
| 37 | * @see <a | |
| 38 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#dictdef-authenticatorselectioncriteria">§5.4.4. | |
| 39 | * Authenticator Selection Criteria (dictionary AuthenticatorSelectionCriteria) </a> | |
| 40 | */ | |
| 41 | @Value | |
| 42 | @Builder(toBuilder = true) | |
| 43 | public class AuthenticatorSelectionCriteria { | |
| 44 | ||
| 45 | /** | |
| 46 | * If present, eligible authenticators are filtered to only authenticators attached with the | |
| 47 | * specified <a href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-attachment">§5.4.5 | |
| 48 | * Authenticator Attachment Enumeration (enum AuthenticatorAttachment)</a>. | |
| 49 | */ | |
| 50 | private final AuthenticatorAttachment authenticatorAttachment; | |
| 51 | ||
| 52 | /** | |
| 53 | * Specifies the extent to which the Relying Party desires to create a client-side discoverable | |
| 54 | * credential (passkey). For historical reasons the naming retains the deprecated “resident” | |
| 55 | * terminology. | |
| 56 | * | |
| 57 | * <p>When this is set, {@link PublicKeyCredentialCreationOptions#toCredentialsCreateJson()} will | |
| 58 | * also emit a <a | |
| 59 | * href="https://www.w3.org/TR/webauthn-2/#dom-authenticatorselectioncriteria-requireresidentkey"> | |
| 60 | * <code>requireResidentKey</code></a> member for backwards compatibility with WebAuthn Level 1. | |
| 61 | * It will be set to <code>true</code> if this is set to {@link ResidentKeyRequirement#REQUIRED | |
| 62 | * REQUIRED} and <code>false</code> if this is set to anything else. When this is not set, a | |
| 63 | * <code>requireResidentKey</code> member will not be emitted. | |
| 64 | * | |
| 65 | * <p>When not set, the default in the browser is {@link ResidentKeyRequirement#DISCOURAGED}. | |
| 66 | * | |
| 67 | * <p>By default, this is not set. | |
| 68 | * | |
| 69 | * @see ResidentKeyRequirement | |
| 70 | * @see <a | |
| 71 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-residentKeyRequirement">§5.4.6. | |
| 72 | * Resident Key Requirement Enumeration (enum ResidentKeyRequirement)</a> | |
| 73 | * @see <a | |
| 74 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-side-discoverable-credential">Client-side | |
| 75 | * discoverable Credential</a> | |
| 76 | * @see <a href="https://passkeys.dev/docs/reference/terms/#passkey">Passkey</a> in <a | |
| 77 | * href="https://passkeys.dev">passkeys.dev</a> reference | |
| 78 | */ | |
| 79 | private final ResidentKeyRequirement residentKey; | |
| 80 | ||
| 81 | /** | |
| 82 | * Describes the Relying Party's requirements regarding <a | |
| 83 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#user-verification">user | |
| 84 | * verification</a> for the <code>navigator.credentials.create()</code> operation. Eligible | |
| 85 | * authenticators are filtered to only those capable of satisfying this requirement. | |
| 86 | * | |
| 87 | * <p>By default, this is not set. When not set, the default in the browser is {@link | |
| 88 | * UserVerificationRequirement#PREFERRED}. | |
| 89 | * | |
| 90 | * @see UserVerificationRequirement | |
| 91 | * @see <a | |
| 92 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-userVerificationRequirement">§5.8.6. | |
| 93 | * User Verification Requirement Enumeration (enum UserVerificationRequirement)</a> | |
| 94 | * @see <a href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#user-verification">User | |
| 95 | * Verification</a> | |
| 96 | */ | |
| 97 | private UserVerificationRequirement userVerification; | |
| 98 | ||
| 99 | /** | |
| 100 | * If present, eligible authenticators are filtered to only authenticators attached with the | |
| 101 | * specified <a href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-attachment">§5.4.5 | |
| 102 | * Authenticator Attachment Enumeration (enum AuthenticatorAttachment)</a>. | |
| 103 | */ | |
| 104 | public Optional<AuthenticatorAttachment> getAuthenticatorAttachment() { | |
| 105 |
1
1. getAuthenticatorAttachment : replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorSelectionCriteria::getAuthenticatorAttachment → KILLED |
return Optional.ofNullable(authenticatorAttachment); |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * Specifies the extent to which the Relying Party desires to create a client-side discoverable | |
| 110 | * credential (passkey). For historical reasons the naming retains the deprecated “resident” | |
| 111 | * terminology. | |
| 112 | * | |
| 113 | * <p>When this is set, {@link PublicKeyCredentialCreationOptions#toCredentialsCreateJson()} will | |
| 114 | * also emit a <a | |
| 115 | * href="https://www.w3.org/TR/webauthn-2/#dom-authenticatorselectioncriteria-requireresidentkey"> | |
| 116 | * <code>requireResidentKey</code></a> member for backwards compatibility with WebAuthn Level 1. | |
| 117 | * It will be set to <code>true</code> if this is set to {@link ResidentKeyRequirement#REQUIRED | |
| 118 | * REQUIRED} and <code>false</code> if this is set to anything else. When this is not set, a | |
| 119 | * <code>requireResidentKey</code> member will not be emitted. | |
| 120 | * | |
| 121 | * <p>When not set, the default in the browser is {@link ResidentKeyRequirement#DISCOURAGED}. | |
| 122 | * | |
| 123 | * <p>By default, this is not set. | |
| 124 | * | |
| 125 | * @see ResidentKeyRequirement | |
| 126 | * @see <a | |
| 127 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-residentKeyRequirement">§5.4.6. | |
| 128 | * Resident Key Requirement Enumeration (enum ResidentKeyRequirement)</a> | |
| 129 | * @see <a | |
| 130 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-side-discoverable-credential">Client-side | |
| 131 | * discoverable Credential</a> | |
| 132 | * @see <a href="https://passkeys.dev/docs/reference/terms/#passkey">Passkey</a> in <a | |
| 133 | * href="https://passkeys.dev">passkeys.dev</a> reference | |
| 134 | */ | |
| 135 | public Optional<ResidentKeyRequirement> getResidentKey() { | |
| 136 |
1
1. getResidentKey : replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorSelectionCriteria::getResidentKey → KILLED |
return Optional.ofNullable(residentKey); |
| 137 | } | |
| 138 | ||
| 139 | /** | |
| 140 | * For backwards compatibility with <code>requireResidentKey</code>. | |
| 141 | * | |
| 142 | * @see <a | |
| 143 | * href="https://www.w3.org/TR/webauthn-2/#dom-authenticatorselectioncriteria-requireresidentkey">5.4.4. | |
| 144 | * Authenticator Selection Criteria (dictionary AuthenticatorSelectionCriteria) member | |
| 145 | * requireResidentKey</a> | |
| 146 | */ | |
| 147 | @JsonProperty | |
| 148 | private Boolean isRequireResidentKey() { | |
| 149 |
4
1. lambda$isRequireResidentKey$0 : negated conditional → KILLED 2. isRequireResidentKey : replaced Boolean return with False for com/yubico/webauthn/data/AuthenticatorSelectionCriteria::isRequireResidentKey → KILLED 3. lambda$isRequireResidentKey$0 : replaced Boolean return with True for com/yubico/webauthn/data/AuthenticatorSelectionCriteria::lambda$isRequireResidentKey$0 → KILLED 4. isRequireResidentKey : replaced Boolean return with True for com/yubico/webauthn/data/AuthenticatorSelectionCriteria::isRequireResidentKey → KILLED |
return getResidentKey().map(rk -> rk == ResidentKeyRequirement.REQUIRED).orElse(null); |
| 150 | } | |
| 151 | ||
| 152 | /** | |
| 153 | * Describes the Relying Party's requirements regarding <a | |
| 154 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#user-verification">user | |
| 155 | * verification</a> for the <code>navigator.credentials.create()</code> operation. Eligible | |
| 156 | * authenticators are filtered to only those capable of satisfying this requirement. | |
| 157 | * | |
| 158 | * <p>By default, this is not set. When not set, the default in the browser is {@link | |
| 159 | * UserVerificationRequirement#PREFERRED}. | |
| 160 | * | |
| 161 | * @see UserVerificationRequirement | |
| 162 | * @see <a | |
| 163 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-userVerificationRequirement">§5.8.6. | |
| 164 | * User Verification Requirement Enumeration (enum UserVerificationRequirement)</a> | |
| 165 | * @see <a href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#user-verification">User | |
| 166 | * Verification</a> | |
| 167 | */ | |
| 168 | public Optional<UserVerificationRequirement> getUserVerification() { | |
| 169 |
1
1. getUserVerification : replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorSelectionCriteria::getUserVerification → KILLED |
return Optional.ofNullable(userVerification); |
| 170 | } | |
| 171 | ||
| 172 | @JsonCreator | |
| 173 | private AuthenticatorSelectionCriteria( | |
| 174 | @JsonProperty("authenticatorAttachment") AuthenticatorAttachment authenticatorAttachment, | |
| 175 | @JsonProperty("requireResidentKey") Boolean requireResidentKey, | |
| 176 | @JsonProperty("residentKey") ResidentKeyRequirement residentKey, | |
| 177 | @JsonProperty("userVerification") UserVerificationRequirement userVerification) { | |
| 178 | this.authenticatorAttachment = authenticatorAttachment; | |
| 179 | ||
| 180 |
1
1. <init> : negated conditional → KILLED |
if (residentKey != null) { |
| 181 | this.residentKey = residentKey; | |
| 182 |
1
1. <init> : negated conditional → KILLED |
} else if (requireResidentKey != null) { |
| 183 | this.residentKey = | |
| 184 |
1
1. <init> : negated conditional → KILLED |
requireResidentKey ? ResidentKeyRequirement.REQUIRED : ResidentKeyRequirement.DISCOURAGED; |
| 185 | } else { | |
| 186 | this.residentKey = null; | |
| 187 | } | |
| 188 | ||
| 189 | this.userVerification = userVerification; | |
| 190 | } | |
| 191 | ||
| 192 | /** For use by the builder. */ | |
| 193 | private AuthenticatorSelectionCriteria( | |
| 194 | AuthenticatorAttachment authenticatorAttachment, | |
| 195 | ResidentKeyRequirement residentKey, | |
| 196 | UserVerificationRequirement userVerification) { | |
| 197 | this(authenticatorAttachment, null, residentKey, userVerification); | |
| 198 | } | |
| 199 | ||
| 200 | public static class AuthenticatorSelectionCriteriaBuilder { | |
| 201 | private AuthenticatorAttachment authenticatorAttachment = null; | |
| 202 | ||
| 203 | /** | |
| 204 | * If present, eligible authenticators are filtered to only authenticators attached with the | |
| 205 | * specified <a | |
| 206 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-attachment">§5.4.5 | |
| 207 | * Authenticator Attachment Enumeration (enum AuthenticatorAttachment)</a>. | |
| 208 | */ | |
| 209 | public AuthenticatorSelectionCriteriaBuilder authenticatorAttachment( | |
| 210 |
1
1. authenticatorAttachment : negated conditional → KILLED |
@NonNull Optional<AuthenticatorAttachment> authenticatorAttachment) { |
| 211 |
1
1. authenticatorAttachment : replaced return value with null for com/yubico/webauthn/data/AuthenticatorSelectionCriteria$AuthenticatorSelectionCriteriaBuilder::authenticatorAttachment → KILLED |
return this.authenticatorAttachment(authenticatorAttachment.orElse(null)); |
| 212 | } | |
| 213 | ||
| 214 | /** | |
| 215 | * If present, eligible authenticators are filtered to only authenticators attached with the | |
| 216 | * specified <a | |
| 217 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-attachment">§5.4.5 | |
| 218 | * Authenticator Attachment Enumeration (enum AuthenticatorAttachment)</a>. | |
| 219 | */ | |
| 220 | public AuthenticatorSelectionCriteriaBuilder authenticatorAttachment( | |
| 221 | AuthenticatorAttachment authenticatorAttachment) { | |
| 222 | this.authenticatorAttachment = authenticatorAttachment; | |
| 223 |
1
1. authenticatorAttachment : replaced return value with null for com/yubico/webauthn/data/AuthenticatorSelectionCriteria$AuthenticatorSelectionCriteriaBuilder::authenticatorAttachment → KILLED |
return this; |
| 224 | } | |
| 225 | } | |
| 226 | } | |
Mutations | ||
| 105 |
1.1 |
|
| 136 |
1.1 |
|
| 149 |
1.1 2.2 3.3 4.4 |
|
| 169 |
1.1 |
|
| 180 |
1.1 |
|
| 182 |
1.1 |
|
| 184 |
1.1 |
|
| 210 |
1.1 |
|
| 211 |
1.1 |
|
| 223 |
1.1 |