Skip to content
Snippets Groups Projects
Commit aa1dc130 authored by David Lin's avatar David Lin Committed by Android (Google) Code Review
Browse files

Merge "Delete keystore keys from RecoveryService.rebootRecoveryWithCommand()" into 24D1-dev

parents 4bebf694 7392c65e
No related branches found
No related tags found
No related merge requests found
......@@ -243,4 +243,24 @@ public class AndroidKeyStoreMaintenance {
"Keystore error while trying to get apps affected by SID.");
}
}
/**
* Deletes all keys in all KeyMint devices.
* Called by RecoverySystem before rebooting to recovery in order to delete all KeyMint keys,
* including synthetic password protector keys (used by LockSettingsService), as well as keys
* protecting DE and metadata encryption keys (used by vold). This ensures that FBE-encrypted
* data is unrecoverable even if the data wipe in recovery is interrupted or skipped.
*/
public static void deleteAllKeys() throws KeyStoreException {
StrictMode.noteDiskWrite();
try {
getService().deleteAllKeys();
} catch (RemoteException | NullPointerException e) {
throw new KeyStoreException(SYSTEM_ERROR,
"Failure to connect to Keystore while trying to delete all keys.");
} catch (ServiceSpecificException e) {
throw new KeyStoreException(e.errorCode,
"Keystore error while trying to delete all keys.");
}
}
}
......@@ -52,6 +52,7 @@ import android.os.ServiceManager;
import android.os.ShellCallback;
import android.os.SystemProperties;
import android.provider.DeviceConfig;
import android.security.AndroidKeyStoreMaintenance;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.FastImmutableArraySet;
......@@ -68,6 +69,7 @@ import com.android.server.SystemService;
import com.android.server.Watchdog;
import com.android.server.pm.ApexManager;
import com.android.server.recoverysystem.hal.BootControlHIDL;
import com.android.server.utils.Slogf;
import libcore.io.IoUtils;
......@@ -122,6 +124,8 @@ public class RecoverySystemService extends IRecoverySystem.Stub implements Reboo
static final String LSKF_CAPTURED_TIMESTAMP_PREF = "lskf_captured_timestamp";
static final String LSKF_CAPTURED_COUNT_PREF = "lskf_captured_count";
static final String RECOVERY_WIPE_DATA_COMMAND = "--wipe_data";
private final Injector mInjector;
private final Context mContext;
......@@ -525,18 +529,35 @@ public class RecoverySystemService extends IRecoverySystem.Stub implements Reboo
@Override // Binder call
public void rebootRecoveryWithCommand(String command) {
if (DEBUG) Slog.d(TAG, "rebootRecoveryWithCommand: [" + command + "]");
boolean isForcedWipe = command != null && command.contains(RECOVERY_WIPE_DATA_COMMAND);
synchronized (sRequestLock) {
if (!setupOrClearBcb(true, command)) {
Slog.e(TAG, "rebootRecoveryWithCommand failed to setup BCB");
return;
}
if (isForcedWipe) {
deleteSecrets();
// TODO: consider adding a dedicated forced-wipe-reboot method to PowerManager and
// calling here.
}
// Having set up the BCB, go ahead and reboot.
PowerManager pm = mInjector.getPowerManager();
pm.reboot(PowerManager.REBOOT_RECOVERY);
}
}
private static void deleteSecrets() {
Slogf.w(TAG, "deleteSecrets");
try {
AndroidKeyStoreMaintenance.deleteAllKeys();
} catch (android.security.KeyStoreException e) {
Log.wtf(TAG, "Failed to delete all keys from keystore.", e);
}
}
private void enforcePermissionForResumeOnReboot() {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.RECOVERY)
!= PackageManager.PERMISSION_GRANTED
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment