Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1e35401 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Big RecoverableKeyStoreLoader refactoring."

parents cd55f807 ed89ea04
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package android.security.recoverablekeystore;
package android.security.keystore;

/* @hide */
parcelable KeyEntryRecoveryData;
parcelable EntryRecoveryData;
+144 −0
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package android.security.recoverablekeystore;
package android.security.keystore;

import android.annotation.NonNull;
import android.os.Parcel;
@@ -35,12 +35,62 @@ import com.android.internal.util.Preconditions;
 *
 * @hide
 */
public final class KeyEntryRecoveryData implements Parcelable {
    private final String mAlias;
public final class EntryRecoveryData implements Parcelable {
    private String mAlias;
    // The only supported format is AES-256 symmetric key.
    private final byte[] mEncryptedKeyMaterial;
    private byte[] mEncryptedKeyMaterial;

    public KeyEntryRecoveryData(@NonNull String alias, @NonNull byte[] encryptedKeyMaterial) {
    /**
     * Builder for creating {@link EntryRecoveryData}.
     */
    public static class Builder {
        private EntryRecoveryData mInstance = new EntryRecoveryData();

        /**
         * Sets Application-specific alias of the key.
         *
         * @param alias The alias.
         * @return This builder.
         */
        public Builder setAlias(@NonNull String alias) {
            mInstance.mAlias = alias;
            return this;
        }

        /**
         * Sets key material encrypted by recovery key.
         *
         * @param encryptedKeyMaterial The key material
         * @return This builder
         */

        public Builder setEncryptedKeyMaterial(@NonNull byte[] encryptedKeyMaterial) {
            mInstance.mEncryptedKeyMaterial = encryptedKeyMaterial;
            return this;
        }

        /**
         * Creates a new {@link EntryRecoveryData} instance.
         *
         * @return new instance
         * @throws NullPointerException if some required fields were not set.
         */
        public @NonNull EntryRecoveryData build() {
            Preconditions.checkNotNull(mInstance.mAlias);
            Preconditions.checkNotNull(mInstance.mEncryptedKeyMaterial);
            return mInstance;
        }
    }

    private EntryRecoveryData() {

    }

    /**
     * Deprecated - consider using Builder.
     * @hide
     */
    public EntryRecoveryData(@NonNull String alias, @NonNull byte[] encryptedKeyMaterial) {
        mAlias = Preconditions.checkNotNull(alias);
        mEncryptedKeyMaterial = Preconditions.checkNotNull(encryptedKeyMaterial);
    }
@@ -54,29 +104,35 @@ public final class KeyEntryRecoveryData implements Parcelable {
        return mAlias;
    }

    /** Encrypted key material encrypted by recovery key. */
    /** Key material encrypted by recovery key. */
    public @NonNull byte[] getEncryptedKeyMaterial() {
        return mEncryptedKeyMaterial;
    }

    public static final Parcelable.Creator<KeyEntryRecoveryData> CREATOR =
            new Parcelable.Creator<KeyEntryRecoveryData>() {
                public KeyEntryRecoveryData createFromParcel(Parcel in) {
                    return new KeyEntryRecoveryData(in);
    public static final Parcelable.Creator<EntryRecoveryData> CREATOR =
            new Parcelable.Creator<EntryRecoveryData>() {
                public EntryRecoveryData createFromParcel(Parcel in) {
                    return new EntryRecoveryData(in);
                }

                public KeyEntryRecoveryData[] newArray(int length) {
                    return new KeyEntryRecoveryData[length];
                public EntryRecoveryData[] newArray(int length) {
                    return new EntryRecoveryData[length];
                }
            };

    /**
     * @hide
     */
    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeString(mAlias);
        out.writeByteArray(mEncryptedKeyMaterial);
    }

    protected KeyEntryRecoveryData(Parcel in) {
    /**
     * @hide
     */
    protected EntryRecoveryData(Parcel in) {
        mAlias = in.readString();
        mEncryptedKeyMaterial = in.createByteArray();
    }
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package android.security.recoverablekeystore;
package android.security.keystore;

/* @hide */
parcelable KeyDerivationParameters;
+9 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package android.security.recoverablekeystore;
package android.security.keystore;

import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -48,11 +48,13 @@ public final class KeyDerivationParameters implements Parcelable {

    /**
     * Salted SHA256
     * @hide
     */
    public static final int ALGORITHM_SHA256 = 1;

    /**
     * Argon2ID
     * @hide
     */
    // TODO: add Argon2ID support.
    public static final int ALGORITHM_ARGON2ID = 2;
@@ -94,12 +96,18 @@ public final class KeyDerivationParameters implements Parcelable {
        }
    };

    /**
     * @hide
     */
    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mAlgorithm);
        out.writeByteArray(mSalt);
    }

    /**
     * @hide
     */
    protected KeyDerivationParameters(Parcel in) {
        mAlgorithm = in.readInt();
        mSalt = in.createByteArray();
+2 −2
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package android.security.recoverablekeystore;
package android.security.keystore;

/* @hide */
parcelable KeyStoreRecoveryData;
parcelable RecoveryData;
Loading