From ebe2674dbc34c03707e6abec69b8f64a0c5fc4da Mon Sep 17 00:00:00 2001 From: Rob Barnes Date: Tue, 13 Nov 2018 15:57:22 -0700 Subject: Changed uid output parameter from an int array to a list of strings. Why?: 1) Returning an array list is unsafe because it must be allocated in Java and C++ must not change the size. 2) List is not supported by AIDL, but List is. I decided it was simpler to pass back integers encoded as strings than to create yet another parcelable. Bug: b/119616956 Test: ./list_auth_bound_keys_test.sh Test: Temporarily modified settings app to call listUidsOfAuthBoundKeys Change-Id: I3bf7578c96e800c8d35fba897f52220136dcd657 --- keystore/java/android/security/KeyStore.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'keystore/java/android/security/KeyStore.java') diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java index 6ac52d109032..36b7e37635ca 100644 --- a/keystore/java/android/security/KeyStore.java +++ b/keystore/java/android/security/KeyStore.java @@ -54,6 +54,7 @@ import java.math.BigInteger; import java.io.ByteArrayInputStream; import java.io.IOException; import java.security.InvalidKeyException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; @@ -303,13 +304,14 @@ public class KeyStore { } /** - * List uids of all keys that are auth bound to the current user. + * List uids of all keys that are auth bound to the current user. * Only system is allowed to call this method. */ @UnsupportedAppUsage public int[] listUidsOfAuthBoundKeys() { - final int MAX_RESULT_SIZE = 100; - int[] uidsOut = new int[MAX_RESULT_SIZE]; + // uids are returned as a list of strings because list of integers + // as an output parameter is not supported by aidl-cpp. + List uidsOut = new ArrayList<>(); try { int rc = mBinder.listUidsOfAuthBoundKeys(uidsOut); if (rc != NO_ERROR) { @@ -323,8 +325,8 @@ public class KeyStore { Log.w(TAG, "KeyStore exception", e); return null; } - // Remove any 0 entries - return Arrays.stream(uidsOut).filter(x -> x > 0).toArray(); + // Turn list of strings into an array of uid integers. + return uidsOut.stream().mapToInt(Integer::parseInt).toArray(); } public String[] list(String prefix) { -- cgit v1.2.3