Skip to content

Commit

Permalink
Merge changes from topic "fbe-wipe-no-reboot" into main am: fd9335c
Browse files Browse the repository at this point in the history
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3008298

Change-Id: I6f7a5fc0c7ef974abfe9d16fe7f96ba7d97430d1
Signed-off-by: Automerger Merge Worker <[email protected]>
  • Loading branch information
nelenkov authored and android-build-merge-worker-robot committed Apr 9, 2024
2 parents 082f59b + fd9335c commit 4073ee2
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
20 changes: 20 additions & 0 deletions keystore/java/android/security/AndroidKeyStoreMaintenance.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,24 @@ public static long[] getAllAppUidsAffectedBySid(int userId, long userSecureId)
"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.");
}
}
}
2 changes: 2 additions & 0 deletions services/core/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ java_library_static {
"android.hardware.health-V3-java", // AIDL
"android.hardware.health-translate-java",
"android.hardware.light-V1-java",
"android.hardware.security.authgraph-V1-java",
"android.hardware.security.rkp-V3-java",
"android.hardware.security.secretkeeper-V1-java",
"android.hardware.tv.cec-V1.1-java",
"android.hardware.tv.hdmi.cec-V1-java",
"android.hardware.tv.hdmi.connection-V1-java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
import static com.android.internal.widget.LockSettingsInternal.ARM_REBOOT_ERROR_NO_PROVIDER;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.apex.CompressedApexInfo;
import android.apex.CompressedApexInfoList;
import android.content.Context;
import android.content.IntentSender;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.hardware.boot.IBootControl;
import android.hardware.security.secretkeeper.ISecretkeeper;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
import android.os.Binder;
Expand All @@ -52,6 +54,7 @@
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;
Expand All @@ -67,6 +70,7 @@
import com.android.server.SystemService;
import com.android.server.pm.ApexManager;
import com.android.server.recoverysystem.hal.BootControlHIDL;
import com.android.server.utils.Slogf;

import libcore.io.IoUtils;

Expand Down Expand Up @@ -118,6 +122,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;

Expand Down Expand Up @@ -521,18 +527,57 @@ public boolean setupBcb(String command) {
@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);
}

try {
ISecretkeeper secretKeeper = getSecretKeeper();
if (secretKeeper != null) {
Slogf.i(TAG, "ISecretkeeper.deleteAll();");
secretKeeper.deleteAll();
}
} catch (RemoteException e) {
Log.wtf(TAG, "Failed to delete all secrets from secretkeeper.", e);
}
}

private static @Nullable ISecretkeeper getSecretKeeper() {
ISecretkeeper result = null;
try {
result = ISecretkeeper.Stub.asInterface(
ServiceManager.waitForDeclaredService(ISecretkeeper.DESCRIPTOR + "/default"));
} catch (SecurityException e) {
Slog.w(TAG, "Does not have permissions to get AIDL secretkeeper service");
}

return result;
}

private void enforcePermissionForResumeOnReboot() {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.RECOVERY)
!= PackageManager.PERMISSION_GRANTED
Expand Down

0 comments on commit 4073ee2

Please sign in to comment.