summaryrefslogtreecommitdiff
path: root/android/security/AttestedKeyPair.java
blob: c6bff5c11a5d5a2363765a78c7ebd4b3cd4410f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.security;

import java.security.KeyPair;
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * The {@code AttestedKeyPair} class contains a {@code KeyPair} instance of
 * keys generated by Keystore and owned by KeyChain, as well as an attestation
 * record for the key.
 *
 * <p>Such keys can be obtained by calling
 * {@link android.app.admin.DevicePolicyManager#generateKeyPair}.
 */

public final class AttestedKeyPair {
    private final KeyPair mKeyPair;
    private final Certificate[] mAttestationRecord;

    /**
     * @hide Only created by the platform, no need to expose as public API.
     */
    public AttestedKeyPair(KeyPair keyPair, Certificate[] attestationRecord) {
        mKeyPair = keyPair;
        mAttestationRecord = attestationRecord;
    }

    /**
     * Returns the generated key pair associated with the attestation record
     * in this instance.
     */
    public KeyPair getKeyPair() {
        return mKeyPair;
    }

    /**
     * Returns the attestation record for the key pair in this instance.
     *
     * The attestation record is a chain of certificates. The leaf certificate links to the public
     * key of this key pair and other properties of the key or the device. If the key is in secure
     * hardware, and if the secure hardware supports attestation, the leaf certificate will be
     * signed by a chain of certificates rooted at a trustworthy CA key. Otherwise the chain will be
     * rooted at an untrusted certificate.
     *
     * The attestation record could be for properties of the key, or include device identifiers.
     *
     * See {@link android.security.keystore.KeyGenParameterSpec.Builder#setAttestationChallenge}
     * and  <a href="https://developer.android.com/training/articles/security-key-attestation.html">
     * Key Attestation</a> for the format of the attestation record inside the certificate.
     */
    public List<Certificate> getAttestationRecord() {
        if (mAttestationRecord == null) {
            return new ArrayList();
        }
        return Arrays.asList(mAttestationRecord);
    }
}