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:
Robert Berry
2018-01-06 19:16:25 +00:00
parent c7dca1bddf
commit 5daccec818
6 changed files with 49 additions and 1 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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 {

View File

@@ -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}.
*

View File

@@ -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(

View File

@@ -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(