AuthenticatorRegistrationExtensionOutputs.java

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 List<Extensions.Uvm.UvmEntry> uvm;
65
66
  @JsonCreator
67
  private AuthenticatorRegistrationExtensionOutputs(
68
      @JsonProperty("uvm") List<Extensions.Uvm.UvmEntry> uvm) {
69 1 1. <init> : negated conditional → KILLED
    this.uvm = uvm == null ? null : CollectionUtil.immutableList(uvm);
70
  }
71
72
  /**
73
   * Parse <a
74
   * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#registration-extension">registration</a>
75
   * <a
76
   * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-extension-output">authenticator
77
   * extension outputs</a> from the given authenticator data.
78
   *
79
   * <p>If the <code>authData</code> does not contain authenticator extension outputs, this returns
80
   * an empty {@link Optional}.
81
   *
82
   * <p>Otherwise, this returns a present {@link Optional} containing an {@link
83
   * AuthenticatorRegistrationExtensionOutputs} value with all validly-formatted <a
84
   * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#registration-extension">registration</a>
85
   * <a
86
   * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-extension-output">extension
87
   * outputs</a> supported by this library. This silently ignores <a
88
   * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authentication-extension">authentication</a>
89
   * extension outputs, malformed extension outputs, and unsupported extensions. The raw set of
90
   * extension outputs can instead be obtained via {@link AuthenticatorData#getExtensions()}.
91
   *
92
   * <p>Note that a present {@link AuthenticatorRegistrationExtensionOutputs} may contain zero
93
   * extension outputs.
94
   *
95
   * @param authData the <a
96
   *     href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#authenticator-data">authenticator
97
   *     data</a> to parse extension outputs from
98
   * @return an empty {@link Optional} if the <code>authData</code> does not contain authenticator
99
   *     extension outputs. Otherwise a present {@link Optional} containing parsed extension output
100
   *     values.
101
   */
102
  public static Optional<AuthenticatorRegistrationExtensionOutputs> fromAuthenticatorData(
103
      AuthenticatorData authData) {
104 1 1. fromAuthenticatorData : replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorRegistrationExtensionOutputs::fromAuthenticatorData → KILLED
    return authData.getExtensions().flatMap(AuthenticatorRegistrationExtensionOutputs::fromCbor);
105
  }
106
107
  static Optional<AuthenticatorRegistrationExtensionOutputs> fromCbor(CBORObject cbor) {
108
    AuthenticatorRegistrationExtensionOutputsBuilder b = builder();
109
110 1 1. fromCbor : removed call to java/util/Optional::ifPresent → KILLED
    Extensions.Uvm.parseAuthenticatorExtensionOutput(cbor).ifPresent(b::uvm);
111
112
    AuthenticatorRegistrationExtensionOutputs 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/AuthenticatorRegistrationExtensionOutputs::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/AuthenticatorRegistrationExtensionOutputs::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/AuthenticatorRegistrationExtensionOutputs::getUvm → KILLED
    return Optional.ofNullable(uvm);
142
  }
143
}

Mutations

69

1.1
Location : <init>
Killed by : com.yubico.webauthn.RelyingPartyV2RegistrationSpec
negated conditional → KILLED

104

1.1
Location : fromAuthenticatorData
Killed by : com.yubico.webauthn.RelyingPartyV2RegistrationSpec
replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorRegistrationExtensionOutputs::fromAuthenticatorData → KILLED

110

1.1
Location : fromCbor
Killed by : com.yubico.webauthn.RelyingPartyV2RegistrationSpec
removed call to java/util/Optional::ifPresent → KILLED

114

1.1
Location : fromCbor
Killed by : com.yubico.webauthn.RelyingPartyV2RegistrationSpec
negated conditional → KILLED

117

1.1
Location : fromCbor
Killed by : com.yubico.webauthn.RelyingPartyV2RegistrationSpec
replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorRegistrationExtensionOutputs::fromCbor → KILLED

125

1.1
Location : getExtensionIds
Killed by : com.yubico.webauthn.RelyingPartyV2RegistrationSpec
negated conditional → KILLED

128

1.1
Location : getExtensionIds
Killed by : com.yubico.webauthn.RelyingPartyV2RegistrationSpec
replaced return value with Collections.emptySet for com/yubico/webauthn/data/AuthenticatorRegistrationExtensionOutputs::getExtensionIds → KILLED

141

1.1
Location : getUvm
Killed by : com.yubico.webauthn.RelyingPartyV2RegistrationSpec
replaced return value with Optional.empty for com/yubico/webauthn/data/AuthenticatorRegistrationExtensionOutputs::getUvm → KILLED

Active mutators

Tests examined


Report generated by PIT 1.15.0