Add KeyChainTest and require certain algorithms
This test will fail if the required KeyChain algorithms are not
supported and are not backed by a hardware Keymaster HAL. This prevents
accidental shipping of a device without the Keymaster HAL included in
the system image.
(cherry picked from commit af948e2bcef610403e1bfb79f0c426c3eac51400)
Bug: 10330504
Change-Id: I5386ba559207a585f77156e7a2c0c2a4b21bfc2b
diff --git a/tests/tests/keystore/src/android/keystore/cts/KeyChainTest.java b/tests/tests/keystore/src/android/keystore/cts/KeyChainTest.java
new file mode 100644
index 0000000..aa4b855
--- /dev/null
+++ b/tests/tests/keystore/src/android/keystore/cts/KeyChainTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.keystore.cts;
+
+import android.security.KeyChain;
+import junit.framework.TestCase;
+
+public class KeyChainTest extends TestCase {
+ public void testIsKeyAlgorithmSupported_RequiredAlgorithmsSupported() throws Exception {
+ assertTrue("RSA must be supported", KeyChain.isKeyAlgorithmSupported("RSA"));
+ }
+
+ /**
+ * Tests whether the required algorithms are backed by a Keymaster HAL that
+ * binds the key material to the specific device it was created or imported
+ * to. For more information on the Keymaster HAL, look at the header file at
+ * hardware/libhardware/include/hardware/keymaster.h and the associated
+ * tests in hardware/libhardware/tests/keymaster/
+ */
+ public void testIsBoundKeyAlgorithm_RequiredAlgorithmsSupported() throws Exception {
+ assertTrue("RSA must be hardware-backed by a hardware-specific Keymaster HAL",
+ KeyChain.isBoundKeyAlgorithm("RSA"));
+ }
+}