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