Dmitry Dementyev | 8eaf607 | 2017-12-06 19:05:33 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.security.recoverablekeystore; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | import com.android.internal.util.Preconditions; |
| 24 | |
Dmitry Dementyev | 8eaf607 | 2017-12-06 19:05:33 -0800 | [diff] [blame] | 25 | /** |
| 26 | * Helper class with data necessary recover a single application key, given a recovery key. |
| 27 | * |
| 28 | * <ul> |
Dmitry Dementyev | 07c76555 | 2018-01-08 17:31:59 -0800 | [diff] [blame] | 29 | * <li>Alias - Keystore alias of the key. |
| 30 | * <li>Encrypted key material. |
Dmitry Dementyev | 8eaf607 | 2017-12-06 19:05:33 -0800 | [diff] [blame] | 31 | * </ul> |
| 32 | * |
| 33 | * Note that Application info is not included. Recovery Agent can only make its own keys |
| 34 | * recoverable. |
| 35 | * |
| 36 | * @hide |
| 37 | */ |
| 38 | public final class KeyEntryRecoveryData implements Parcelable { |
Dmitry Dementyev | 07c76555 | 2018-01-08 17:31:59 -0800 | [diff] [blame] | 39 | private final String mAlias; |
Dmitry Dementyev | 8eaf607 | 2017-12-06 19:05:33 -0800 | [diff] [blame] | 40 | // The only supported format is AES-256 symmetric key. |
| 41 | private final byte[] mEncryptedKeyMaterial; |
| 42 | |
Dmitry Dementyev | 07c76555 | 2018-01-08 17:31:59 -0800 | [diff] [blame] | 43 | public KeyEntryRecoveryData(@NonNull String alias, @NonNull byte[] encryptedKeyMaterial) { |
Dmitry Dementyev | 8eaf607 | 2017-12-06 19:05:33 -0800 | [diff] [blame] | 44 | mAlias = Preconditions.checkNotNull(alias); |
| 45 | mEncryptedKeyMaterial = Preconditions.checkNotNull(encryptedKeyMaterial); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Application-specific alias of the key. |
Dmitry Dementyev | 07c76555 | 2018-01-08 17:31:59 -0800 | [diff] [blame] | 50 | * |
Dmitry Dementyev | 8eaf607 | 2017-12-06 19:05:33 -0800 | [diff] [blame] | 51 | * @see java.security.KeyStore.aliases |
| 52 | */ |
Dmitry Dementyev | 07c76555 | 2018-01-08 17:31:59 -0800 | [diff] [blame] | 53 | public @NonNull String getAlias() { |
Dmitry Dementyev | 8eaf607 | 2017-12-06 19:05:33 -0800 | [diff] [blame] | 54 | return mAlias; |
| 55 | } |
| 56 | |
Dmitry Dementyev | 07c76555 | 2018-01-08 17:31:59 -0800 | [diff] [blame] | 57 | /** Encrypted key material encrypted by recovery key. */ |
Dmitry Dementyev | 8eaf607 | 2017-12-06 19:05:33 -0800 | [diff] [blame] | 58 | public @NonNull byte[] getEncryptedKeyMaterial() { |
| 59 | return mEncryptedKeyMaterial; |
| 60 | } |
| 61 | |
| 62 | public static final Parcelable.Creator<KeyEntryRecoveryData> CREATOR = |
| 63 | new Parcelable.Creator<KeyEntryRecoveryData>() { |
Dmitry Dementyev | 07c76555 | 2018-01-08 17:31:59 -0800 | [diff] [blame] | 64 | public KeyEntryRecoveryData createFromParcel(Parcel in) { |
| 65 | return new KeyEntryRecoveryData(in); |
| 66 | } |
Dmitry Dementyev | 8eaf607 | 2017-12-06 19:05:33 -0800 | [diff] [blame] | 67 | |
Dmitry Dementyev | 07c76555 | 2018-01-08 17:31:59 -0800 | [diff] [blame] | 68 | public KeyEntryRecoveryData[] newArray(int length) { |
| 69 | return new KeyEntryRecoveryData[length]; |
| 70 | } |
| 71 | }; |
Dmitry Dementyev | 8eaf607 | 2017-12-06 19:05:33 -0800 | [diff] [blame] | 72 | |
| 73 | @Override |
| 74 | public void writeToParcel(Parcel out, int flags) { |
Dmitry Dementyev | 07c76555 | 2018-01-08 17:31:59 -0800 | [diff] [blame] | 75 | out.writeString(mAlias); |
Dmitry Dementyev | 8eaf607 | 2017-12-06 19:05:33 -0800 | [diff] [blame] | 76 | out.writeByteArray(mEncryptedKeyMaterial); |
| 77 | } |
| 78 | |
| 79 | protected KeyEntryRecoveryData(Parcel in) { |
Dmitry Dementyev | 07c76555 | 2018-01-08 17:31:59 -0800 | [diff] [blame] | 80 | mAlias = in.readString(); |
Dmitry Dementyev | 8eaf607 | 2017-12-06 19:05:33 -0800 | [diff] [blame] | 81 | mEncryptedKeyMaterial = in.createByteArray(); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public int describeContents() { |
| 86 | return 0; |
| 87 | } |
| 88 | } |