Merge "Keystore 2.0: Remove hidden Keystore API from locksettings tests." am: 665844b1e2 am: a8781112be

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1638940

Change-Id: I1f0e2a9e01faee759a24f5ee48d43de4b373c44b
This commit is contained in:
Janis Danisevskis
2021-03-17 04:21:38 +00:00
committed by Automerger Merge Worker
5 changed files with 16 additions and 19 deletions

View File

@@ -207,7 +207,7 @@ public class KeyStore {
case UserState.LSKF_LOCKED: case UserState.LSKF_LOCKED:
return KeyStore.State.LOCKED; return KeyStore.State.LOCKED;
default: default:
throw new AssertionError(KeyStore.VALUE_CORRUPTED); throw new AssertionError(userState);
} }
} }
ret = mBinder.getState(userId); ret = mBinder.getState(userId);

View File

@@ -42,7 +42,6 @@ import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.os.FileUtils; import android.os.FileUtils;
import android.security.keystore.AndroidKeyStoreSecretKey;
import android.security.keystore.KeyGenParameterSpec; import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties; import android.security.keystore.KeyProperties;
import android.security.keystore.recovery.KeyChainSnapshot; import android.security.keystore.recovery.KeyChainSnapshot;
@@ -109,7 +108,7 @@ public class KeySyncTaskTest {
private RecoverySnapshotStorage mRecoverySnapshotStorage; private RecoverySnapshotStorage mRecoverySnapshotStorage;
private RecoverableKeyStoreDb mRecoverableKeyStoreDb; private RecoverableKeyStoreDb mRecoverableKeyStoreDb;
private File mDatabaseFile; private File mDatabaseFile;
private AndroidKeyStoreSecretKey mWrappingKey; private SecretKey mWrappingKey;
private PlatformEncryptionKey mEncryptKey; private PlatformEncryptionKey mEncryptKey;
private KeySyncTask mKeySyncTask; private KeySyncTask mKeySyncTask;
@@ -848,7 +847,7 @@ public class KeySyncTaskTest {
return keyGenerator.generateKey(); return keyGenerator.generateKey();
} }
private AndroidKeyStoreSecretKey generateAndroidKeyStoreKey() throws Exception { private SecretKey generateAndroidKeyStoreKey() throws Exception {
KeyGenerator keyGenerator = KeyGenerator.getInstance( KeyGenerator keyGenerator = KeyGenerator.getInstance(
KEY_ALGORITHM, KEY_ALGORITHM,
ANDROID_KEY_STORE_PROVIDER); ANDROID_KEY_STORE_PROVIDER);
@@ -857,7 +856,7 @@ public class KeySyncTaskTest {
.setBlockModes(KeyProperties.BLOCK_MODE_GCM) .setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE) .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.build()); .build());
return (AndroidKeyStoreSecretKey) keyGenerator.generateKey(); return keyGenerator.generateKey();
} }
private static byte[] utf8Bytes(String s) { private static byte[] utf8Bytes(String s) {

View File

@@ -23,7 +23,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import android.content.Context; import android.content.Context;
import android.security.keystore.AndroidKeyStoreSecretKey;
import android.security.keystore.KeyGenParameterSpec; import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties; import android.security.keystore.KeyProperties;
@@ -45,6 +44,7 @@ import java.util.Random;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.KeyGenerator; import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.GCMParameterSpec;
@SmallTest @SmallTest
@@ -77,7 +77,7 @@ public class RecoverableKeyGeneratorTest {
mDatabaseFile = context.getDatabasePath(DATABASE_FILE_NAME); mDatabaseFile = context.getDatabasePath(DATABASE_FILE_NAME);
mRecoverableKeyStoreDb = RecoverableKeyStoreDb.newInstance(context); mRecoverableKeyStoreDb = RecoverableKeyStoreDb.newInstance(context);
AndroidKeyStoreSecretKey platformKey = generatePlatformKey(); SecretKey platformKey = generatePlatformKey();
mPlatformKey = new PlatformEncryptionKey(TEST_GENERATION_ID, platformKey); mPlatformKey = new PlatformEncryptionKey(TEST_GENERATION_ID, platformKey);
mDecryptKey = new PlatformDecryptionKey(TEST_GENERATION_ID, platformKey); mDecryptKey = new PlatformDecryptionKey(TEST_GENERATION_ID, platformKey);
mRecoverableKeyGenerator = RecoverableKeyGenerator.newInstance(mRecoverableKeyStoreDb); mRecoverableKeyGenerator = RecoverableKeyGenerator.newInstance(mRecoverableKeyStoreDb);
@@ -168,7 +168,7 @@ public class RecoverableKeyGeneratorTest {
assertArrayEquals(rawMaterial, unwrappedMaterial); assertArrayEquals(rawMaterial, unwrappedMaterial);
} }
private AndroidKeyStoreSecretKey generatePlatformKey() throws Exception { private SecretKey generatePlatformKey() throws Exception {
KeyGenerator keyGenerator = KeyGenerator.getInstance( KeyGenerator keyGenerator = KeyGenerator.getInstance(
KEY_ALGORITHM, KEY_ALGORITHM,
ANDROID_KEY_STORE_PROVIDER); ANDROID_KEY_STORE_PROVIDER);
@@ -177,7 +177,7 @@ public class RecoverableKeyGeneratorTest {
.setBlockModes(KeyProperties.BLOCK_MODE_GCM) .setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE) .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.build()); .build());
return (AndroidKeyStoreSecretKey) keyGenerator.generateKey(); return keyGenerator.generateKey();
} }
private static byte[] randomBytes(int n) { private static byte[] randomBytes(int n) {

View File

@@ -45,7 +45,6 @@ import android.content.Intent;
import android.os.Binder; import android.os.Binder;
import android.os.ServiceSpecificException; import android.os.ServiceSpecificException;
import android.os.UserHandle; import android.os.UserHandle;
import android.security.keystore.AndroidKeyStoreSecretKey;
import android.security.keystore.KeyGenParameterSpec; import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties; import android.security.keystore.KeyProperties;
import android.security.keystore.recovery.KeyChainProtectionParams; import android.security.keystore.recovery.KeyChainProtectionParams;
@@ -1311,7 +1310,7 @@ public class RecoverableKeyStoreManagerTest {
mRecoverableKeyStoreDb.setShouldCreateSnapshot(userId, uid, false); mRecoverableKeyStoreDb.setShouldCreateSnapshot(userId, uid, false);
} }
private AndroidKeyStoreSecretKey generateAndroidKeyStoreKey() throws Exception { private SecretKey generateAndroidKeyStoreKey() throws Exception {
KeyGenerator keyGenerator = KeyGenerator.getInstance( KeyGenerator keyGenerator = KeyGenerator.getInstance(
KEY_ALGORITHM, KEY_ALGORITHM,
ANDROID_KEY_STORE_PROVIDER); ANDROID_KEY_STORE_PROVIDER);
@@ -1320,6 +1319,6 @@ public class RecoverableKeyStoreManagerTest {
.setBlockModes(KeyProperties.BLOCK_MODE_GCM) .setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE) .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.build()); .build());
return (AndroidKeyStoreSecretKey) keyGenerator.generateKey(); return keyGenerator.generateKey();
} }
} }

View File

@@ -21,7 +21,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import android.security.keystore.AndroidKeyStoreSecretKey;
import android.security.keystore.KeyGenParameterSpec; import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties; import android.security.keystore.KeyProperties;
import android.util.Pair; import android.util.Pair;
@@ -117,7 +116,7 @@ public class WrappedKeyTest {
@Test @Test
public void decryptWrappedKeys_decryptsWrappedKeys_nullMetadata() throws Exception { public void decryptWrappedKeys_decryptsWrappedKeys_nullMetadata() throws Exception {
String alias = "karlin"; String alias = "karlin";
AndroidKeyStoreSecretKey platformKey = generateAndroidKeyStoreKey(); SecretKey platformKey = generateAndroidKeyStoreKey();
SecretKey appKey = generateKey(); SecretKey appKey = generateKey();
WrappedKey wrappedKey = WrappedKey.fromSecretKey( WrappedKey wrappedKey = WrappedKey.fromSecretKey(
new PlatformEncryptionKey(GENERATION_ID, platformKey), appKey, NULL_METADATA); new PlatformEncryptionKey(GENERATION_ID, platformKey), appKey, NULL_METADATA);
@@ -136,7 +135,7 @@ public class WrappedKeyTest {
@Test @Test
public void decryptWrappedKeys_decryptsWrappedKeys_nonNullMetadata() throws Exception { public void decryptWrappedKeys_decryptsWrappedKeys_nonNullMetadata() throws Exception {
String alias = "karlin"; String alias = "karlin";
AndroidKeyStoreSecretKey platformKey = generateAndroidKeyStoreKey(); SecretKey platformKey = generateAndroidKeyStoreKey();
SecretKey appKey = generateKey(); SecretKey appKey = generateKey();
WrappedKey wrappedKey = WrappedKey.fromSecretKey( WrappedKey wrappedKey = WrappedKey.fromSecretKey(
new PlatformEncryptionKey(GENERATION_ID, platformKey), appKey, NON_NULL_METADATA); new PlatformEncryptionKey(GENERATION_ID, platformKey), appKey, NON_NULL_METADATA);
@@ -155,7 +154,7 @@ public class WrappedKeyTest {
@Test @Test
public void decryptWrappedKeys_doesNotDieIfSomeKeysAreUnwrappable() throws Exception { public void decryptWrappedKeys_doesNotDieIfSomeKeysAreUnwrappable() throws Exception {
String alias = "karlin"; String alias = "karlin";
AndroidKeyStoreSecretKey platformKey = generateAndroidKeyStoreKey(); SecretKey platformKey = generateAndroidKeyStoreKey();
SecretKey appKey = generateKey(); SecretKey appKey = generateKey();
WrappedKey wrappedKey = WrappedKey.fromSecretKey( WrappedKey wrappedKey = WrappedKey.fromSecretKey(
new PlatformEncryptionKey(GENERATION_ID, platformKey), appKey, NULL_METADATA); new PlatformEncryptionKey(GENERATION_ID, platformKey), appKey, NULL_METADATA);
@@ -171,7 +170,7 @@ public class WrappedKeyTest {
@Test @Test
public void decryptWrappedKeys_throwsIfPlatformKeyGenerationIdDoesNotMatch() throws Exception { public void decryptWrappedKeys_throwsIfPlatformKeyGenerationIdDoesNotMatch() throws Exception {
AndroidKeyStoreSecretKey platformKey = generateAndroidKeyStoreKey(); SecretKey platformKey = generateAndroidKeyStoreKey();
WrappedKey wrappedKey = WrappedKey.fromSecretKey( WrappedKey wrappedKey = WrappedKey.fromSecretKey(
new PlatformEncryptionKey(GENERATION_ID, platformKey), generateKey(), new PlatformEncryptionKey(GENERATION_ID, platformKey), generateKey(),
/*metadata=*/ null); /*metadata=*/ null);
@@ -197,7 +196,7 @@ public class WrappedKeyTest {
return keyGenerator.generateKey(); return keyGenerator.generateKey();
} }
private AndroidKeyStoreSecretKey generateAndroidKeyStoreKey() throws Exception { private SecretKey generateAndroidKeyStoreKey() throws Exception {
KeyGenerator keyGenerator = KeyGenerator.getInstance( KeyGenerator keyGenerator = KeyGenerator.getInstance(
KEY_ALGORITHM, KEY_ALGORITHM,
ANDROID_KEY_STORE_PROVIDER); ANDROID_KEY_STORE_PROVIDER);
@@ -207,6 +206,6 @@ public class WrappedKeyTest {
.setBlockModes(KeyProperties.BLOCK_MODE_GCM) .setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE) .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.build()); .build());
return (AndroidKeyStoreSecretKey) keyGenerator.generateKey(); return keyGenerator.generateKey();
} }
} }