Add API to remove recoverable keys
Test: adb shell am instrument -w -e package com.android.server.locksettings.recoverablekeystore com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner Change-Id: Ib69e730467974d34ffe4a700bd6aaf4543a524ae
This commit is contained in:
@@ -66,6 +66,7 @@ interface ILockSettings {
|
||||
void initRecoveryService(in String rootCertificateAlias, in byte[] signedPublicKeyList);
|
||||
KeyStoreRecoveryData getRecoveryData(in byte[] account);
|
||||
byte[] generateAndStoreKey(String alias);
|
||||
void removeKey(String alias);
|
||||
void setSnapshotCreatedPendingIntent(in PendingIntent intent);
|
||||
Map getRecoverySnapshotVersions();
|
||||
void setServerParameters(long serverParameters);
|
||||
|
||||
@@ -2030,6 +2030,11 @@ public class LockSettingsService extends ILockSettings.Stub {
|
||||
sessionId, recoveryKeyBlob, applicationKeys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeKey(@NonNull String alias) throws RemoteException {
|
||||
mRecoverableKeyStoreManager.removeKey(alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] generateAndStoreKey(@NonNull String alias) throws RemoteException {
|
||||
return mRecoverableKeyStoreManager.generateAndStoreKey(alias);
|
||||
|
||||
@@ -411,7 +411,6 @@ public class RecoverableKeyStoreManager {
|
||||
int uid = Binder.getCallingUid();
|
||||
int userId = UserHandle.getCallingUserId();
|
||||
|
||||
|
||||
PlatformEncryptionKey encryptionKey;
|
||||
try {
|
||||
encryptionKey = mPlatformKeyManager.getEncryptKey(userId);
|
||||
@@ -433,6 +432,10 @@ public class RecoverableKeyStoreManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void removeKey(@NonNull String alias) throws RemoteException {
|
||||
mDatabase.removeKey(Binder.getCallingUid(), alias);
|
||||
}
|
||||
|
||||
private byte[] decryptRecoveryKey(
|
||||
RecoverySessionStorage.Entry sessionEntry, byte[] encryptedClaimResponse)
|
||||
throws RemoteException, ServiceSpecificException {
|
||||
|
||||
@@ -146,6 +146,19 @@ public class RecoverableKeyStoreDb {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes key with {@code alias} for app with {@code uid}.
|
||||
*
|
||||
* @return {@code true} if deleted a row.
|
||||
*/
|
||||
public boolean removeKey(int uid, String alias) {
|
||||
SQLiteDatabase db = mKeyStoreDbHelper.getWritableDatabase();
|
||||
String selection = KeysEntry.COLUMN_NAME_UID + " = ? AND " +
|
||||
KeysEntry.COLUMN_NAME_ALIAS + " = ?";
|
||||
String[] selectionArgs = { Integer.toString(uid), alias };
|
||||
return db.delete(KeysEntry.TABLE_NAME, selection, selectionArgs) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all statuses for keys {@code uid} and {@code platformKeyGenerationId}.
|
||||
*
|
||||
|
||||
@@ -192,6 +192,16 @@ public class RecoverableKeyStoreManagerTest {
|
||||
.hasLength(RECOVERABLE_KEY_SIZE_BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeKey_removesAKey() throws Exception {
|
||||
int uid = Binder.getCallingUid();
|
||||
mRecoverableKeyStoreManager.generateAndStoreKey(TEST_ALIAS);
|
||||
|
||||
mRecoverableKeyStoreManager.removeKey(TEST_ALIAS);
|
||||
|
||||
assertThat(mRecoverableKeyStoreDb.getKey(uid, TEST_ALIAS)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startRecoverySession_checksPermissionFirst() throws Exception {
|
||||
mRecoverableKeyStoreManager.startRecoverySession(
|
||||
|
||||
@@ -112,6 +112,22 @@ public class RecoverableKeyStoreDbTest {
|
||||
mRecoverableKeyStoreDb.getKey(2, alias).getNonce());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeKey_removesAKey() {
|
||||
int userId = 6;
|
||||
int uid = 60001;
|
||||
String alias = "rupertbates";
|
||||
WrappedKey key = new WrappedKey(
|
||||
getUtf8Bytes("nonce1"),
|
||||
getUtf8Bytes("key1"),
|
||||
/*platformKeyGenerationId=*/ 1);
|
||||
mRecoverableKeyStoreDb.insertKey(userId, uid, alias, key);
|
||||
|
||||
assertTrue(mRecoverableKeyStoreDb.removeKey(uid, alias));
|
||||
|
||||
assertNull(mRecoverableKeyStoreDb.getKey(uid, alias));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKey_returnsNullIfNoKey() {
|
||||
WrappedKey key = mRecoverableKeyStoreDb.getKey(
|
||||
|
||||
Reference in New Issue
Block a user