From e36fe6bf46b832178bef636fdddc98c1407ca869 Mon Sep 17 00:00:00 2001 From: Janis Danisevskis Date: Tue, 10 Aug 2021 17:47:43 -0700 Subject: [PATCH] Keystore 2.0 SPI: Fix contract between equals and hashCode 2 This fixes the contract between equals and hashCode in AndroidKeystorePublicKey. The previous fix made only a reference comparisson between certificate blobs. In this patch java.util.Arrays is used to compare and compute the hash of the array. Bug: 196118021 Test: See following CL. Change-Id: I2b8b7e740fb377de39fd21f763e15cb00024b2fc --- .../security/keystore2/AndroidKeyStorePublicKey.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java b/keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java index 4842984e8c6ab..0b3be327b521d 100644 --- a/keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java +++ b/keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java @@ -23,7 +23,7 @@ import android.system.keystore2.KeyDescriptor; import android.system.keystore2.KeyMetadata; import java.security.PublicKey; -import java.util.Objects; +import java.util.Arrays; /** * {@link PublicKey} backed by Android Keystore. @@ -62,8 +62,8 @@ public abstract class AndroidKeyStorePublicKey extends AndroidKeyStoreKey implem int result = 1; result = prime * result + super.hashCode(); - result = prime * result + ((mCertificate == null) ? 0 : mCertificate.hashCode()); - result = prime * result + ((mCertificateChain == null) ? 0 : mCertificateChain.hashCode()); + result = prime * result + Arrays.hashCode(mCertificate); + result = prime * result + Arrays.hashCode(mCertificateChain); return result; } @@ -83,7 +83,7 @@ public abstract class AndroidKeyStorePublicKey extends AndroidKeyStoreKey implem */ final AndroidKeyStorePublicKey other = (AndroidKeyStorePublicKey) obj; - return Objects.equals(mCertificate, other.mCertificate) && Objects.equals(mCertificateChain, + return Arrays.equals(mCertificate, other.mCertificate) && Arrays.equals(mCertificateChain, other.mCertificateChain); } }