| 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 AuthenticatorRegistrationExtensionOutputs | |
| 62 | implements AuthenticatorExtensionOutputs { | |
| 63 | ||
| 64 | private final Extensions.CredentialProtection.CredentialProtectionPolicy credProtect; | |
| 65 | private final List<Extensions.Uvm.UvmEntry> uvm; | |
| 66 | ||
| 67 | @JsonCreator | |
| 68 | private AuthenticatorRegistrationExtensionOutputs( | |
| 69 | @JsonProperty("credProtect") | |
| 70 | Extensions.CredentialProtection.CredentialProtectionPolicy credProtect, | |
| 71 | @JsonProperty("uvm") List<Extensions.Uvm.UvmEntry> uvm) { | |
| 72 | this.credProtect = credProtect; | |
| 73 |
1
1. <init> : negated conditional → KILLED |
this.uvm = uvm == null ? null : CollectionUtil.immutableList(uvm); |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * Parse <a | |
| 78 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#registration-extension">registration</a> | |
| 79 | * <a | |
| 80 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-extension-output">authenticator | |
| 81 | * extension outputs</a> from the given authenticator data. | |
| 82 | * | |
| 83 | * <p>If the <code>authData</code> does not contain authenticator extension outputs, this returns | |
| 84 | * an empty {@link Optional}. | |
| 85 | * | |
| 86 | * <p>Otherwise, this returns a present {@link Optional} containing an {@link | |
| 87 | * AuthenticatorRegistrationExtensionOutputs} value with all validly-formatted <a | |
| 88 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#registration-extension">registration</a> | |
| 89 | * <a | |
| 90 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-extension-output">extension | |
| 91 | * outputs</a> supported by this library. This silently ignores <a | |
| 92 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authentication-extension">authentication</a> | |
| 93 | * extension outputs, malformed extension outputs, and unsupported extensions. The raw set of | |
| 94 | * extension outputs can instead be obtained via {@link AuthenticatorData#getExtensions()}. | |
| 95 | * | |
| 96 | * <p>Note that a present {@link AuthenticatorRegistrationExtensionOutputs} may contain zero | |
| 97 | * extension outputs. | |
| 98 | * | |
| 99 | * @param authData the <a | |
| 100 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-data">authenticator | |
| 101 | * data</a> to parse extension outputs from | |
| 102 | * @return an empty {@link Optional} if the <code>authData</code> does not contain authenticator | |
| 103 | * extension outputs. Otherwise a present {@link Optional} containing parsed extension output | |
| 104 | * values. | |
| 105 | */ | |
| 106 | public static Optional<AuthenticatorRegistrationExtensionOutputs> fromAuthenticatorData( | |
| 107 | AuthenticatorData authData) { | |
| 108 |
1
1. fromAuthenticatorData : replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorRegistrationExtensionOutputs::fromAuthenticatorData → KILLED |
return authData.getExtensions().flatMap(AuthenticatorRegistrationExtensionOutputs::fromCbor); |
| 109 | } | |
| 110 | ||
| 111 | static Optional<AuthenticatorRegistrationExtensionOutputs> fromCbor(CBORObject cbor) { | |
| 112 | AuthenticatorRegistrationExtensionOutputsBuilder b = builder(); | |
| 113 | ||
| 114 | Extensions.CredentialProtection.parseAuthenticatorExtensionOutput(cbor) | |
| 115 |
1
1. fromCbor : removed call to java/util/Optional::ifPresent → KILLED |
.ifPresent(b::credProtect); |
| 116 |
1
1. fromCbor : removed call to java/util/Optional::ifPresent → KILLED |
Extensions.Uvm.parseAuthenticatorExtensionOutput(cbor).ifPresent(b::uvm); |
| 117 | ||
| 118 | AuthenticatorRegistrationExtensionOutputs result = b.build(); | |
| 119 | ||
| 120 |
1
1. fromCbor : negated conditional → KILLED |
if (result.getExtensionIds().isEmpty()) { |
| 121 | return Optional.empty(); | |
| 122 | } else { | |
| 123 |
1
1. fromCbor : replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorRegistrationExtensionOutputs::fromCbor → KILLED |
return Optional.of(result); |
| 124 | } | |
| 125 | } | |
| 126 | ||
| 127 | @Override | |
| 128 | @EqualsAndHashCode.Include | |
| 129 | public Set<String> getExtensionIds() { | |
| 130 | HashSet<String> ids = new HashSet<>(); | |
| 131 |
1
1. getExtensionIds : negated conditional → KILLED |
if (credProtect != null) { |
| 132 | ids.add(Extensions.CredentialProtection.EXTENSION_ID); | |
| 133 | } | |
| 134 |
1
1. getExtensionIds : negated conditional → KILLED |
if (uvm != null) { |
| 135 | ids.add(Extensions.Uvm.EXTENSION_ID); | |
| 136 | } | |
| 137 |
1
1. getExtensionIds : replaced return value with Collections.emptySet for com/yubico/webauthn/data/AuthenticatorRegistrationExtensionOutputs::getExtensionIds → KILLED |
return ids; |
| 138 | } | |
| 139 | ||
| 140 | /** | |
| 141 | * @return The <a | |
| 142 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-extension-output">authenticator | |
| 143 | * extension output</a> for the <a | |
| 144 | * href="https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#sctn-credProtect-extension">Credential | |
| 145 | * Protection (credProtect) extension</a>, if any. This indicates the credential protection | |
| 146 | * policy that was set for the credential. | |
| 147 | * @since 2.7.0 | |
| 148 | * @see <a | |
| 149 | * href="https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#sctn-credProtect-extension">CTAP2 | |
| 150 | * §12.1. Credential Protection (credProtect)</a> | |
| 151 | */ | |
| 152 | public Optional<Extensions.CredentialProtection.CredentialProtectionPolicy> getCredProtect() { | |
| 153 |
1
1. getCredProtect : replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorRegistrationExtensionOutputs::getCredProtect → KILLED |
return Optional.ofNullable(credProtect); |
| 154 | } | |
| 155 | ||
| 156 | /** | |
| 157 | * @return The <a | |
| 158 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-extension-output">authenticator | |
| 159 | * extension output</a> for the <a | |
| 160 | * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#sctn-uvm-extension">User | |
| 161 | * Verification Method (<code>uvm</code>) extension</a>, if any. | |
| 162 | * @see <a href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#sctn-uvm-extension">§10.3. | |
| 163 | * User Verification Method extension (uvm)</a> | |
| 164 | */ | |
| 165 | public Optional<List<Extensions.Uvm.UvmEntry>> getUvm() { | |
| 166 |
1
1. getUvm : replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorRegistrationExtensionOutputs::getUvm → KILLED |
return Optional.ofNullable(uvm); |
| 167 | } | |
| 168 | } | |
Mutations | ||
| 73 |
1.1 |
|
| 108 |
1.1 |
|
| 115 |
1.1 |
|
| 116 |
1.1 |
|
| 120 |
1.1 |
|
| 123 |
1.1 |
|
| 131 |
1.1 |
|
| 134 |
1.1 |
|
| 137 |
1.1 |
|
| 153 |
1.1 |
|
| 166 |
1.1 |