From 5e73c0eec2bc77222a5a87fb2a135d8303836411 Mon Sep 17 00:00:00 2001 From: Chad Brubaker Date: Sat, 21 Mar 2015 22:46:43 -0700 Subject: Make application/client id an object Having it as a raw byte[] caused issues in keystore because keymaster handles a null blob differently than a blob with null contents. Make this explicit in the API. Change-Id: Ifcf550f438608b8f09fc589d00d06fffa6ee463b --- keystore/tests/src/android/security/KeyStoreTest.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'keystore/tests') diff --git a/keystore/tests/src/android/security/KeyStoreTest.java b/keystore/tests/src/android/security/KeyStoreTest.java index f0b07a6..cb77455 100644 --- a/keystore/tests/src/android/security/KeyStoreTest.java +++ b/keystore/tests/src/android/security/KeyStoreTest.java @@ -25,6 +25,7 @@ import android.security.KeyStore; import android.security.keymaster.ExportResult; import android.security.keymaster.KeyCharacteristics; import android.security.keymaster.KeymasterArguments; +import android.security.keymaster.KeymasterBlob; import android.security.keymaster.KeymasterDefs; import android.security.keymaster.OperationResult; import android.test.ActivityUnitTestCase; @@ -712,8 +713,6 @@ public class KeyStoreTest extends ActivityUnitTestCase { args.addInt(KeymasterDefs.KM_TAG_ALGORITHM, KeymasterDefs.KM_ALGORITHM_RSA); args.addInt(KeymasterDefs.KM_TAG_PADDING, KeymasterDefs.KM_PAD_NONE); args.addInt(KeymasterDefs.KM_TAG_KEY_SIZE, 2048); - args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_ID, null); - args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_DATA, null); args.addBlob(KeymasterDefs.KM_TAG_RSA_PUBLIC_EXPONENT, RSAKeyGenParameterSpec.F4.toByteArray()); @@ -744,6 +743,7 @@ public class KeyStoreTest extends ActivityUnitTestCase { public void testAppId() throws Exception { String name = "test"; + byte[] id = new byte[] {0x01, 0x02, 0x03}; KeymasterArguments args = new KeymasterArguments(); args.addInt(KeymasterDefs.KM_TAG_PURPOSE, KeymasterDefs.KM_PURPOSE_ENCRYPT); args.addInt(KeymasterDefs.KM_TAG_PURPOSE, KeymasterDefs.KM_PURPOSE_DECRYPT); @@ -751,8 +751,7 @@ public class KeyStoreTest extends ActivityUnitTestCase { args.addInt(KeymasterDefs.KM_TAG_PADDING, KeymasterDefs.KM_PAD_NONE); args.addInt(KeymasterDefs.KM_TAG_KEY_SIZE, 2048); args.addInt(KeymasterDefs.KM_TAG_BLOCK_MODE, KeymasterDefs.KM_MODE_ECB); - args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_ID, new byte[] {0x01, 0x02, 0x03}); - args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_DATA, null); + args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_ID, id); args.addBlob(KeymasterDefs.KM_TAG_RSA_PUBLIC_EXPONENT, RSAKeyGenParameterSpec.F4.toByteArray()); @@ -764,7 +763,7 @@ public class KeyStoreTest extends ActivityUnitTestCase { mKeyStore.getKeyCharacteristics(name, null, null, outCharacteristics)); assertEquals("getKeyCharacteristics should succeed with application ID", KeyStore.NO_ERROR, - mKeyStore.getKeyCharacteristics(name, new byte[] {0x01, 0x02, 0x03}, null, + mKeyStore.getKeyCharacteristics(name, new KeymasterBlob(id), null, outCharacteristics)); } @@ -789,8 +788,6 @@ public class KeyStoreTest extends ActivityUnitTestCase { args.addInt(KeymasterDefs.KM_TAG_BLOCK_MODE, KeymasterDefs.KM_MODE_OCB); args.addInt(KeymasterDefs.KM_TAG_CHUNK_LENGTH, 4096); args.addInt(KeymasterDefs.KM_TAG_MAC_LENGTH, 16); - args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_ID, null); - args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_DATA, null); KeyCharacteristics outCharacteristics = new KeyCharacteristics(); int rc = mKeyStore.generateKey(name, args, 0, outCharacteristics); @@ -798,8 +795,6 @@ public class KeyStoreTest extends ActivityUnitTestCase { KeymasterArguments out = new KeymasterArguments(); args = new KeymasterArguments(); - args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_ID, null); - args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_DATA, null); OperationResult result = mKeyStore.begin(name, KeymasterDefs.KM_PURPOSE_ENCRYPT, true, args, out); IBinder token = result.token; @@ -888,8 +883,6 @@ public class KeyStoreTest extends ActivityUnitTestCase { args.addInt(KeymasterDefs.KM_TAG_BLOCK_MODE, KeymasterDefs.KM_MODE_OCB); args.addInt(KeymasterDefs.KM_TAG_CHUNK_LENGTH, 4096); args.addInt(KeymasterDefs.KM_TAG_MAC_LENGTH, 16); - args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_ID, null); - args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_DATA, null); KeyCharacteristics outCharacteristics = new KeyCharacteristics(); int rc = mKeyStore.generateKey(name, args, 0, outCharacteristics); @@ -897,8 +890,6 @@ public class KeyStoreTest extends ActivityUnitTestCase { KeymasterArguments out = new KeymasterArguments(); args = new KeymasterArguments(); - args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_ID, null); - args.addBlob(KeymasterDefs.KM_TAG_APPLICATION_DATA, null); OperationResult result = mKeyStore.begin(name, KeymasterDefs.KM_PURPOSE_ENCRYPT, true, args, out); assertEquals("Begin should succeed", KeyStore.NO_ERROR, result.resultCode); -- cgit v1.1