summaryrefslogtreecommitdiff
path: root/tests/tests/keystore/src/android/keystore/cts/util/TestUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tests/keystore/src/android/keystore/cts/util/TestUtils.java')
-rw-r--r--tests/tests/keystore/src/android/keystore/cts/util/TestUtils.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/tests/keystore/src/android/keystore/cts/util/TestUtils.java b/tests/tests/keystore/src/android/keystore/cts/util/TestUtils.java
index 22045526055..2e1707782be 100644
--- a/tests/tests/keystore/src/android/keystore/cts/util/TestUtils.java
+++ b/tests/tests/keystore/src/android/keystore/cts/util/TestUtils.java
@@ -16,6 +16,10 @@
package android.keystore.cts.util;
+import static android.security.keystore.KeyProperties.DIGEST_NONE;
+import static android.security.keystore.KeyProperties.DIGEST_SHA256;
+import static android.security.keystore.KeyProperties.DIGEST_SHA512;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -121,6 +125,20 @@ public class TestUtils {
return getFeatureVersionKeystore(appContext);
}
+ /**
+ * This function returns the valid digest algorithms supported for a Strongbox or default
+ * KeyMint implementation. The isStrongbox parameter specifies the underlying KeyMint
+ * implementation. If true, it indicates Strongbox KeyMint, otherwise TEE/Software KeyMint
+ * is assumed.
+ */
+ public static @KeyProperties.DigestEnum String[] getDigestsForKeyMintImplementation(
+ boolean isStrongbox) {
+ if (isStrongbox) {
+ return new String[]{DIGEST_NONE, DIGEST_SHA256};
+ }
+ return new String[]{DIGEST_NONE, DIGEST_SHA256, DIGEST_SHA512};
+ }
+
// Returns 0 if not implemented. Otherwise returns the feature version.
//
public static int getFeatureVersionKeystore(Context appContext) {
@@ -1263,4 +1281,18 @@ public class TestUtils {
return ((Build.VERSION.SDK_INT == 34 && Build.VERSION.PREVIEW_SDK_INT >= 1)
|| Build.VERSION.SDK_INT >= 35);
}
+
+ /**
+ * Returns whether the device has a StrongBox backed KeyStore or Hardware based Keystore
+ * with provided version and newer.
+ */
+ public static boolean hasKeystoreVersion(boolean isStrongBoxBased, int version) {
+ Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ if (isStrongBoxBased) {
+ return context.getPackageManager()
+ .hasSystemFeature(PackageManager.FEATURE_STRONGBOX_KEYSTORE, version);
+ }
+ return context.getPackageManager()
+ .hasSystemFeature(PackageManager.FEATURE_HARDWARE_KEYSTORE, version);
+ }
}