blob: 5f56c91004fefc6c39dc2ba9157075de6edc674b [file] [log] [blame]
Dmitry Dementyev8eaf6072017-12-06 19:05:33 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.security.recoverablekeystore;
18
19import android.annotation.NonNull;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23import com.android.internal.util.Preconditions;
24
Dmitry Dementyev8eaf6072017-12-06 19:05:33 -080025/**
26 * Helper class with data necessary recover a single application key, given a recovery key.
27 *
28 * <ul>
Dmitry Dementyev07c765552018-01-08 17:31:59 -080029 * <li>Alias - Keystore alias of the key.
30 * <li>Encrypted key material.
Dmitry Dementyev8eaf6072017-12-06 19:05:33 -080031 * </ul>
32 *
33 * Note that Application info is not included. Recovery Agent can only make its own keys
34 * recoverable.
35 *
36 * @hide
37 */
38public final class KeyEntryRecoveryData implements Parcelable {
Dmitry Dementyev07c765552018-01-08 17:31:59 -080039 private final String mAlias;
Dmitry Dementyev8eaf6072017-12-06 19:05:33 -080040 // The only supported format is AES-256 symmetric key.
41 private final byte[] mEncryptedKeyMaterial;
42
Dmitry Dementyev07c765552018-01-08 17:31:59 -080043 public KeyEntryRecoveryData(@NonNull String alias, @NonNull byte[] encryptedKeyMaterial) {
Dmitry Dementyev8eaf6072017-12-06 19:05:33 -080044 mAlias = Preconditions.checkNotNull(alias);
45 mEncryptedKeyMaterial = Preconditions.checkNotNull(encryptedKeyMaterial);
46 }
47
48 /**
49 * Application-specific alias of the key.
Dmitry Dementyev07c765552018-01-08 17:31:59 -080050 *
Dmitry Dementyev8eaf6072017-12-06 19:05:33 -080051 * @see java.security.KeyStore.aliases
52 */
Dmitry Dementyev07c765552018-01-08 17:31:59 -080053 public @NonNull String getAlias() {
Dmitry Dementyev8eaf6072017-12-06 19:05:33 -080054 return mAlias;
55 }
56
Dmitry Dementyev07c765552018-01-08 17:31:59 -080057 /** Encrypted key material encrypted by recovery key. */
Dmitry Dementyev8eaf6072017-12-06 19:05:33 -080058 public @NonNull byte[] getEncryptedKeyMaterial() {
59 return mEncryptedKeyMaterial;
60 }
61
62 public static final Parcelable.Creator<KeyEntryRecoveryData> CREATOR =
63 new Parcelable.Creator<KeyEntryRecoveryData>() {
Dmitry Dementyev07c765552018-01-08 17:31:59 -080064 public KeyEntryRecoveryData createFromParcel(Parcel in) {
65 return new KeyEntryRecoveryData(in);
66 }
Dmitry Dementyev8eaf6072017-12-06 19:05:33 -080067
Dmitry Dementyev07c765552018-01-08 17:31:59 -080068 public KeyEntryRecoveryData[] newArray(int length) {
69 return new KeyEntryRecoveryData[length];
70 }
71 };
Dmitry Dementyev8eaf6072017-12-06 19:05:33 -080072
73 @Override
74 public void writeToParcel(Parcel out, int flags) {
Dmitry Dementyev07c765552018-01-08 17:31:59 -080075 out.writeString(mAlias);
Dmitry Dementyev8eaf6072017-12-06 19:05:33 -080076 out.writeByteArray(mEncryptedKeyMaterial);
77 }
78
79 protected KeyEntryRecoveryData(Parcel in) {
Dmitry Dementyev07c765552018-01-08 17:31:59 -080080 mAlias = in.readString();
Dmitry Dementyev8eaf6072017-12-06 19:05:33 -080081 mEncryptedKeyMaterial = in.createByteArray();
82 }
83
84 @Override
85 public int describeContents() {
86 return 0;
87 }
88}