X5cAttestationStatementVerifier.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;
26
27
import com.fasterxml.jackson.databind.JsonNode;
28
import com.yubico.internal.util.CertificateParser;
29
import com.yubico.webauthn.data.AttestationObject;
30
import java.io.IOException;
31
import java.security.cert.CertificateException;
32
import java.security.cert.X509Certificate;
33
import java.util.ArrayList;
34
import java.util.List;
35
import java.util.Optional;
36
37
interface X5cAttestationStatementVerifier {
38
39
  default Optional<X509Certificate> getX5cAttestationCertificate(
40
      AttestationObject attestationObject) throws CertificateException {
41 2 1. getX5cAttestationCertificate : replaced return value with Optional.empty for com/yubico/webauthn/X5cAttestationStatementVerifier::getX5cAttestationCertificate → KILLED
2. lambda$getX5cAttestationCertificate$0 : replaced return value with Optional.empty for com/yubico/webauthn/X5cAttestationStatementVerifier::lambda$getX5cAttestationCertificate$0 → KILLED
    return getAttestationTrustPath(attestationObject).flatMap(certs -> certs.stream().findFirst());
42
  }
43
44
  default Optional<List<X509Certificate>> getAttestationTrustPath(
45
      AttestationObject attestationObject) throws CertificateException {
46
    JsonNode x5cNode = getX5cArray(attestationObject);
47
48 2 1. getAttestationTrustPath : negated conditional → KILLED
2. getAttestationTrustPath : negated conditional → KILLED
    if (x5cNode != null && x5cNode.isArray()) {
49
      List<X509Certificate> certs = new ArrayList<>(x5cNode.size());
50
51
      for (JsonNode binary : x5cNode) {
52 1 1. getAttestationTrustPath : negated conditional → KILLED
        if (binary.isBinary()) {
53
          try {
54
            certs.add(CertificateParser.parseDer(binary.binaryValue()));
55
          } catch (IOException e) {
56
            throw new RuntimeException(
57
                "binary.isBinary() was true but binary.binaryValue() failed", e);
58
          }
59
        } else {
60
          throw new IllegalArgumentException(
61
              String.format(
62
                  "Each element of \"x5c\" property of attestation statement must be a binary value, was: %s",
63
                  binary.getNodeType()));
64
        }
65
      }
66
67 1 1. getAttestationTrustPath : replaced return value with Optional.empty for com/yubico/webauthn/X5cAttestationStatementVerifier::getAttestationTrustPath → KILLED
      return Optional.of(certs);
68
    } else {
69
      return Optional.empty();
70
    }
71
  }
72
73
  default JsonNode getX5cArray(AttestationObject attestationObject) {
74 1 1. getX5cArray : replaced return value with null for com/yubico/webauthn/X5cAttestationStatementVerifier::getX5cArray → KILLED
    return attestationObject.getAttestationStatement().get("x5c");
75
  }
76
}

Mutations

41

1.1
Location : getX5cAttestationCertificate
Killed by : com.yubico.webauthn.PackedAttestationStatementVerifierSpec
replaced return value with Optional.empty for com/yubico/webauthn/X5cAttestationStatementVerifier::getX5cAttestationCertificate → KILLED

2.2
Location : lambda$getX5cAttestationCertificate$0
Killed by : com.yubico.webauthn.PackedAttestationStatementVerifierSpec
replaced return value with Optional.empty for com/yubico/webauthn/X5cAttestationStatementVerifier::lambda$getX5cAttestationCertificate$0 → KILLED

48

1.1
Location : getAttestationTrustPath
Killed by : com.yubico.webauthn.PackedAttestationStatementVerifierSpec
negated conditional → KILLED

2.2
Location : getAttestationTrustPath
Killed by : com.yubico.webauthn.PackedAttestationStatementVerifierSpec
negated conditional → KILLED

52

1.1
Location : getAttestationTrustPath
Killed by : com.yubico.webauthn.PackedAttestationStatementVerifierSpec
negated conditional → KILLED

67

1.1
Location : getAttestationTrustPath
Killed by : com.yubico.webauthn.PackedAttestationStatementVerifierSpec
replaced return value with Optional.empty for com/yubico/webauthn/X5cAttestationStatementVerifier::getAttestationTrustPath → KILLED

74

1.1
Location : getX5cArray
Killed by : com.yubico.webauthn.PackedAttestationStatementVerifierSpec
replaced return value with null for com/yubico/webauthn/X5cAttestationStatementVerifier::getX5cArray → KILLED

Active mutators

Tests examined


Report generated by PIT 1.15.0