From feee500cfa16976565db74b8e8263f54a2ae3842 Mon Sep 17 00:00:00 2001 From: Li Li Date: Fri, 16 Oct 2020 21:30:59 -0700 Subject: [PATCH] Perf: optimize getCertHash SHA-1 was the only option in the GP SEAC standard GPD_SPE_013 since 2014. GPD_SPE_068 said SHA-256 shall be used in 2017, which also became the de factor standard in the industry. In the most cases (if not all), it's not necessary to check SHA-1 at all. The SHA-1 code should be removed in the near future as long as it's confirmed not necessary. Bug: 168624720 Test: Confirmed only SHA-256 is calculated. The dogfood phone works with master local build. Change-Id: Id9f09cf200f02d72daf230b2dbf789c9f985e2b0 Signed-off-by: Li Li --- .../java/android/telephony/UiccAccessRule.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/telephony/java/android/telephony/UiccAccessRule.java b/telephony/java/android/telephony/UiccAccessRule.java index 12bb36647f8f7..7773c0aef2529 100644 --- a/telephony/java/android/telephony/UiccAccessRule.java +++ b/telephony/java/android/telephony/UiccAccessRule.java @@ -204,13 +204,21 @@ public final class UiccAccessRule implements Parcelable { * {@link TelephonyManager#CARRIER_PRIVILEGE_STATUS_NO_ACCESS}. */ public int getCarrierPrivilegeStatus(Signature signature, String packageName) { - // SHA-1 is for backward compatible support only, strongly discouraged for new use. - byte[] certHash = getCertHash(signature, "SHA-1"); byte[] certHash256 = getCertHash(signature, "SHA-256"); - if (matches(certHash, packageName) || matches(certHash256, packageName)) { + // Check SHA-256 first as it's the new standard. + if (matches(certHash256, packageName)) { return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; } + // Then check SHA-1 for backward compatibility. This should be removed + // in the near future when GPD_SPE_068 fully replaces GPD_SPE_013. + if (this.mCertificateHash.length == 20) { + byte[] certHash = getCertHash(signature, "SHA-1"); + if (matches(certHash, packageName)) { + return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; + } + } + return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; }