AppleAttestationStatementVerifier.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.yubico.internal.util.ExceptionUtil;
28
import com.yubico.webauthn.data.AttestationObject;
29
import com.yubico.webauthn.data.AttestationType;
30
import com.yubico.webauthn.data.ByteArray;
31
import java.security.PublicKey;
32
import java.security.cert.CertificateException;
33
import java.security.cert.X509Certificate;
34
import java.util.Optional;
35
import lombok.extern.slf4j.Slf4j;
36
37
@Slf4j
38
final class AppleAttestationStatementVerifier
39
    implements AttestationStatementVerifier, X5cAttestationStatementVerifier {
40
41
  private static final String NONCE_EXTENSION_OID = "1.2.840.113635.100.8.2";
42
43
  @Override
44
  public AttestationType getAttestationType(AttestationObject attestation) {
45 1 1. getAttestationType : replaced return value with null for com/yubico/webauthn/AppleAttestationStatementVerifier::getAttestationType → KILLED
    return AttestationType.ANONYMIZATION_CA;
46
  }
47
48
  @Override
49
  public boolean verifyAttestationSignature(
50
      AttestationObject attestationObject, ByteArray clientDataJsonHash) {
51
    final Optional<X509Certificate> attestationCert;
52
    try {
53
      attestationCert = getX5cAttestationCertificate(attestationObject);
54
    } catch (CertificateException e) {
55
      throw ExceptionUtil.wrapAndLog(
56
          log,
57
          String.format(
58
              "Failed to parse X.509 certificate from attestation object: %s", attestationObject),
59
          e);
60
    }
61
62 2 1. verifyAttestationSignature : replaced boolean return with true for com/yubico/webauthn/AppleAttestationStatementVerifier::verifyAttestationSignature → SURVIVED
2. verifyAttestationSignature : replaced boolean return with false for com/yubico/webauthn/AppleAttestationStatementVerifier::verifyAttestationSignature → KILLED
    return attestationCert
63
        .map(
64
            attestationCertificate -> {
65
              final ByteArray nonceToHash =
66
                  attestationObject.getAuthenticatorData().getBytes().concat(clientDataJsonHash);
67
68
              final ByteArray nonce = Crypto.sha256(nonceToHash);
69
70
              byte[] nonceExtension = attestationCertificate.getExtensionValue(NONCE_EXTENSION_OID);
71 1 1. lambda$verifyAttestationSignature$0 : negated conditional → KILLED
              if (nonceExtension == null) {
72
                throw new IllegalArgumentException(
73
                    "Apple anonymous attestation certificate must contain extension OID: "
74
                        + NONCE_EXTENSION_OID);
75
              }
76
77
              // X.509 extension values is a DER octet string: 0x0426
78
              // Then the extension contains a 1-element sequence: 0x3024
79
              // The element has context-specific tag "[1]": 0xa122
80
              // Then the sequence contains a 32-byte octet string: 0x0420
81
              final ByteArray expectedExtensionValue =
82
                  new ByteArray(
83
                          new byte[] {
84
                            0x04, 0x26, 0x30, 0x24, (-128) + (0xa1 - 128), 0x22, 0x04, 0x20
85
                          })
86
                      .concat(nonce);
87
88 1 1. lambda$verifyAttestationSignature$0 : negated conditional → KILLED
              if (!expectedExtensionValue.equals(new ByteArray(nonceExtension))) {
89
                throw new IllegalArgumentException(
90
                    String.format(
91
                        "Apple anonymous attestation certificate extension %s must equal nonceToHash. Expected: %s, was: %s",
92
                        NONCE_EXTENSION_OID,
93
                        expectedExtensionValue,
94
                        new ByteArray(nonceExtension)));
95
              }
96
97
              final PublicKey credentialPublicKey;
98
              try {
99
                credentialPublicKey =
100
                    WebAuthnCodecs.importCosePublicKey(
101
                        attestationObject
102
                            .getAuthenticatorData()
103
                            .getAttestedCredentialData()
104
                            .get()
105
                            .getCredentialPublicKey());
106
              } catch (Exception e) {
107
                throw ExceptionUtil.wrapAndLog(log, "Failed to import credential public key", e);
108
              }
109
110
              final PublicKey certPublicKey = attestationCertificate.getPublicKey();
111
112 1 1. lambda$verifyAttestationSignature$0 : negated conditional → KILLED
              if (!credentialPublicKey.equals(certPublicKey)) {
113
                throw new IllegalArgumentException(
114
                    String.format(
115
                        "Apple anonymous attestation certificate subject public key must equal credential public key. Expected: %s, was: %s",
116
                        credentialPublicKey, certPublicKey));
117
              }
118
119 1 1. lambda$verifyAttestationSignature$0 : replaced Boolean return with False for com/yubico/webauthn/AppleAttestationStatementVerifier::lambda$verifyAttestationSignature$0 → KILLED
              return true;
120
            })
121
        .orElseThrow(
122
            () ->
123 1 1. lambda$verifyAttestationSignature$1 : replaced return value with null for com/yubico/webauthn/AppleAttestationStatementVerifier::lambda$verifyAttestationSignature$1 → NO_COVERAGE
                new IllegalArgumentException(
124
                    "Failed to parse attestation certificate from \"apple\" attestation statement."));
125
  }
126
}

Mutations

45

1.1
Location : getAttestationType
Killed by : com.yubico.webauthn.RelyingPartyCeremoniesSpec
replaced return value with null for com/yubico/webauthn/AppleAttestationStatementVerifier::getAttestationType → KILLED

62

1.1
Location : verifyAttestationSignature
Killed by : none
replaced boolean return with true for com/yubico/webauthn/AppleAttestationStatementVerifier::verifyAttestationSignature → SURVIVED

2.2
Location : verifyAttestationSignature
Killed by : com.yubico.webauthn.RelyingPartyCeremoniesSpec
replaced boolean return with false for com/yubico/webauthn/AppleAttestationStatementVerifier::verifyAttestationSignature → KILLED

71

1.1
Location : lambda$verifyAttestationSignature$0
Killed by : com.yubico.webauthn.RelyingPartyCeremoniesSpec
negated conditional → KILLED

88

1.1
Location : lambda$verifyAttestationSignature$0
Killed by : com.yubico.webauthn.RelyingPartyCeremoniesSpec
negated conditional → KILLED

112

1.1
Location : lambda$verifyAttestationSignature$0
Killed by : com.yubico.webauthn.RelyingPartyCeremoniesSpec
negated conditional → KILLED

119

1.1
Location : lambda$verifyAttestationSignature$0
Killed by : com.yubico.webauthn.RelyingPartyCeremoniesSpec
replaced Boolean return with False for com/yubico/webauthn/AppleAttestationStatementVerifier::lambda$verifyAttestationSignature$0 → KILLED

123

1.1
Location : lambda$verifyAttestationSignature$1
Killed by : none
replaced return value with null for com/yubico/webauthn/AppleAttestationStatementVerifier::lambda$verifyAttestationSignature$1 → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.15.0