From bd03d7606d1feebca9498d4e807c5af043cf8f58 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 26 Jan 2022 04:53:29 +0000 Subject: [PATCH 1/3] Remove checks for FDE in 'adb backup' The deviceIsEncrypted() methods in BackupRestoreConfirmation.java and UserBackupManagerService.java only return true if the device is using FDE (Full Disk Encryption), for which support has been removed in favor of FBE (File Based Encryption). Therefore, the logic to require a backup password no longer applies to any device. Remove this logic to simplify the code. It is possible that this was actually a bug, and this logic should have applied to FBE devices too. But given that the code has worked this way for years, and there isn't necessarily a logical connection between whether the device is encrypted and whether a backup *must* be encrypted, I decided not to change the current behavior. Bug: 208476087 Test: 'adb backup' and 'adb restore' still work. Change-Id: Idc72d2a4c3e8bfa10a32cdc57884159b37635e81 (cherry picked from commit d5b040ed643948dd892f4ad8e2d0f3cfa8d4613d) Merged-In: Idc72d2a4c3e8bfa10a32cdc57884159b37635e81 --- .../res/values/strings.xml | 2 -- .../BackupRestoreConfirmation.java | 30 ++----------------- .../backup/UserBackupManagerService.java | 25 ---------------- .../fullbackup/PerformAdbBackupTask.java | 6 ---- 4 files changed, 2 insertions(+), 61 deletions(-) diff --git a/packages/BackupRestoreConfirmation/res/values/strings.xml b/packages/BackupRestoreConfirmation/res/values/strings.xml index 3fb3fd475ab36..5c90fd019cd8d 100644 --- a/packages/BackupRestoreConfirmation/res/values/strings.xml +++ b/packages/BackupRestoreConfirmation/res/values/strings.xml @@ -44,8 +44,6 @@ Please enter a password to use for encrypting the full backup data. If this is left blank, your current backup password will be used: If you wish to encrypt the full backup data, enter a password below: - - Since your device is encrypted, you are required to encrypt your backup. Please enter a password below: If the restore data is encrypted, please enter the password below: diff --git a/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java b/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java index d6b6bf8d1e56e..3c790f0e24eea 100644 --- a/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java +++ b/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java @@ -27,8 +27,6 @@ import android.os.Handler; import android.os.Message; import android.os.RemoteException; import android.os.ServiceManager; -import android.os.storage.IStorageManager; -import android.os.storage.StorageManager; import android.text.Editable; import android.text.TextWatcher; import android.util.Slog; @@ -66,10 +64,8 @@ public class BackupRestoreConfirmation extends Activity { Handler mHandler; IBackupManager mBackupManager; - IStorageManager mStorageManager; FullObserver mObserver; int mToken; - boolean mIsEncrypted; boolean mDidAcknowledge; String mAction; @@ -144,7 +140,6 @@ public class BackupRestoreConfirmation extends Activity { } mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService(Context.BACKUP_SERVICE)); - mStorageManager = IStorageManager.Stub.asInterface(ServiceManager.getService("mount")); mHandler = new ObserverHandler(getApplicationContext()); final Object oldObserver = getLastNonConfigurationInstance(); @@ -248,20 +243,13 @@ public class BackupRestoreConfirmation extends Activity { mDenyButton.setEnabled(!mDidAcknowledge); } - // We vary the password prompt depending on whether one is predefined, and whether - // the device is encrypted. - mIsEncrypted = deviceIsEncrypted(); + // We vary the password prompt depending on whether one is predefined. if (!haveBackupPassword()) { curPwDesc.setVisibility(View.GONE); mCurPassword.setVisibility(View.GONE); if (layoutId == R.layout.confirm_backup) { TextView encPwDesc = findViewById(R.id.enc_password_desc); - if (mIsEncrypted) { - encPwDesc.setText(R.string.backup_enc_password_required); - monitorEncryptionPassword(); - } else { - encPwDesc.setText(R.string.backup_enc_password_optional); - } + encPwDesc.setText(R.string.backup_enc_password_optional); } } } @@ -312,20 +300,6 @@ public class BackupRestoreConfirmation extends Activity { } } - boolean deviceIsEncrypted() { - try { - return mStorageManager.getEncryptionState() - != StorageManager.ENCRYPTION_STATE_NONE - && mStorageManager.getPasswordType() - != StorageManager.CRYPT_TYPE_DEFAULT; - } catch (Exception e) { - // If we can't talk to the storagemanager service we have a serious problem; fail - // "secure" i.e. assuming that the device is encrypted. - Slog.e(TAG, "Unable to communicate with storagemanager service: " + e.getMessage()); - return true; - } - } - boolean haveBackupPassword() { try { return mBackupManager.hasBackupPassword(); diff --git a/services/backup/java/com/android/server/backup/UserBackupManagerService.java b/services/backup/java/com/android/server/backup/UserBackupManagerService.java index 0b95fefec1038..65b17768c39ce 100644 --- a/services/backup/java/com/android/server/backup/UserBackupManagerService.java +++ b/services/backup/java/com/android/server/backup/UserBackupManagerService.java @@ -89,8 +89,6 @@ import android.os.ServiceManager; import android.os.SystemClock; import android.os.UserHandle; import android.os.WorkSource; -import android.os.storage.IStorageManager; -import android.os.storage.StorageManager; import android.provider.Settings; import android.text.TextUtils; import android.util.ArraySet; @@ -336,7 +334,6 @@ public class UserBackupManagerService { private final ActivityManagerInternal mActivityManagerInternal; private PowerManager mPowerManager; private final AlarmManager mAlarmManager; - private final IStorageManager mStorageManager; private final BackupManagerConstants mConstants; private final BackupWakeLock mWakelock; private final BackupHandler mBackupHandler; @@ -567,7 +564,6 @@ public class UserBackupManagerService { mBackupPasswordManager = null; mPackageManagerBinder = null; mActivityManager = null; - mStorageManager = null; mBackupManagerBinder = null; mScheduledBackupEligibility = null; } @@ -591,7 +587,6 @@ public class UserBackupManagerService { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - mStorageManager = IStorageManager.Stub.asInterface(ServiceManager.getService("mount")); Objects.requireNonNull(parent, "parent cannot be null"); mBackupManagerBinder = BackupManagerService.asInterface(parent.asBinder()); @@ -2252,26 +2247,6 @@ public class UserBackupManagerService { } } - /** For adb backup/restore. */ - public boolean deviceIsEncrypted() { - try { - return mStorageManager.getEncryptionState() - != StorageManager.ENCRYPTION_STATE_NONE - && mStorageManager.getPasswordType() - != StorageManager.CRYPT_TYPE_DEFAULT; - } catch (Exception e) { - // If we can't talk to the storagemanager service we have a serious problem; fail - // "secure" i.e. assuming that the device is encrypted. - Slog.e( - TAG, - addUserIdToLogMessage( - mUserId, - "Unable to communicate with storagemanager service: " - + e.getMessage())); - return true; - } - } - // ----- Full-data backup scheduling ----- /** diff --git a/services/backup/java/com/android/server/backup/fullbackup/PerformAdbBackupTask.java b/services/backup/java/com/android/server/backup/fullbackup/PerformAdbBackupTask.java index 448e0860b88da..01d90f691a709 100644 --- a/services/backup/java/com/android/server/backup/fullbackup/PerformAdbBackupTask.java +++ b/services/backup/java/com/android/server/backup/fullbackup/PerformAdbBackupTask.java @@ -316,12 +316,6 @@ public class PerformAdbBackupTask extends FullBackupTask implements BackupRestor try { boolean encrypting = (mEncryptPassword != null && mEncryptPassword.length() > 0); - // Only allow encrypted backups of encrypted devices - if (mUserBackupManagerService.deviceIsEncrypted() && !encrypting) { - Slog.e(TAG, "Unencrypted backup of encrypted device; aborting"); - return; - } - OutputStream finalOutput = ofstream; // Verify that the given password matches the currently-active From f33dbe0540a2000917b63856c179684ad3dfea6a Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 26 Jan 2022 05:13:46 +0000 Subject: [PATCH 2/3] Stop checking FDE password cache Now that FDE is no longer supported, checking the FDE password cache will never accomplish anything. Remove this check from Keyguard, and remove the supporting code from LockSettingsService. Bug: 208476087 Change-Id: If1bb80dfcc015aeea19916a88c89a4067e6ada32 (cherry picked from commit e9b69111b203bec8266f096a0fec942b570da97a) Merged-In: If1bb80dfcc015aeea19916a88c89a4067e6ada32 --- .../internal/widget/ILockSettings.aidl | 1 - .../internal/widget/LockPatternUtils.java | 14 ---- .../keyguard/KeyguardViewMediator.java | 8 -- .../locksettings/LockSettingsService.java | 75 ------------------- 4 files changed, 98 deletions(-) diff --git a/core/java/com/android/internal/widget/ILockSettings.aidl b/core/java/com/android/internal/widget/ILockSettings.aidl index 654b46164dcf9..0f964fc82473d 100644 --- a/core/java/com/android/internal/widget/ILockSettings.aidl +++ b/core/java/com/android/internal/widget/ILockSettings.aidl @@ -51,7 +51,6 @@ interface ILockSettings { VerifyCredentialResponse verifyTiedProfileChallenge(in LockscreenCredential credential, int userId, int flags); VerifyCredentialResponse verifyGatekeeperPasswordHandle(long gatekeeperPasswordHandle, long challenge, int userId); void removeGatekeeperPasswordHandle(long gatekeeperPasswordHandle); - boolean checkVoldPassword(int userId); int getCredentialType(int userId); byte[] getHashFactor(in LockscreenCredential currentCredential, int userId); void setSeparateProfileChallengeEnabled(int userId, boolean enabled, in LockscreenCredential managedUserPassword); diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java index 408decc9ca569..e9159697a99b1 100644 --- a/core/java/com/android/internal/widget/LockPatternUtils.java +++ b/core/java/com/android/internal/widget/LockPatternUtils.java @@ -504,20 +504,6 @@ public class LockPatternUtils { } } - /** - * Check to see if vold already has the password. - * Note that this also clears vold's copy of the password. - * @return Whether the vold password matches or not. - */ - public boolean checkVoldPassword(int userId) { - try { - return getLockSettings().checkVoldPassword(userId); - } catch (RemoteException re) { - Log.e(TAG, "failed to check vold password", re); - return false; - } - } - /** * Returns the password history hash factor, needed to check new password against password * history with {@link #checkPasswordHistory(byte[], byte[], int)} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index e9f288d51317b..896f01a12c049 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -1573,14 +1573,6 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off"); return; } - - if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) { - if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted"); - // Without this, settings is not enabled until the lock screen first appears - setShowingLocked(false); - hideLocked(); - return; - } } if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen"); diff --git a/services/core/java/com/android/server/locksettings/LockSettingsService.java b/services/core/java/com/android/server/locksettings/LockSettingsService.java index 45f85edeff7e6..82d06246eb986 100644 --- a/services/core/java/com/android/server/locksettings/LockSettingsService.java +++ b/services/core/java/com/android/server/locksettings/LockSettingsService.java @@ -237,8 +237,6 @@ public class LockSettingsService extends ILockSettings.Stub { private final RebootEscrowManager mRebootEscrowManager; - private boolean mFirstCallToVold; - // Current password metric for all users on the device. Updated when user unlocks // the device or changes password. Removed when user is stopped. @GuardedBy("this") @@ -573,8 +571,6 @@ public class LockSettingsService extends ILockSettings.Stub { mStrongAuth = injector.getStrongAuth(); mActivityManager = injector.getActivityManager(); - mFirstCallToVold = true; - IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_USER_ADDED); filter.addAction(Intent.ACTION_USER_STARTING); @@ -2367,77 +2363,6 @@ public class LockSettingsService extends ILockSettings.Stub { }); } - private LockscreenCredential createPattern(String patternString) { - final byte[] patternBytes = patternString.getBytes(); - LockscreenCredential pattern = LockscreenCredential.createPattern( - LockPatternUtils.byteArrayToPattern(patternBytes)); - Arrays.fill(patternBytes, (byte) 0); - return pattern; - } - - @Override - public boolean checkVoldPassword(int userId) { - if (!mFirstCallToVold) { - return false; - } - mFirstCallToVold = false; - - checkPasswordReadPermission(); - - // There's no guarantee that this will safely connect, but if it fails - // we will simply show the lock screen when we shouldn't, so relatively - // benign. There is an outside chance something nasty would happen if - // this service restarted before vold stales out the password in this - // case. The nastiness is limited to not showing the lock screen when - // we should, within the first minute of decrypting the phone if this - // service can't connect to vold, it restarts, and then the new instance - // does successfully connect. - final IStorageManager service = mInjector.getStorageManager(); - // TODO(b/120484642): Update vold to return a password as a byte array - String password; - final long identity = Binder.clearCallingIdentity(); - try { - password = service.getPassword(); - service.clearPassword(); - } catch (RemoteException e) { - Slog.w(TAG, "vold getPassword() failed", e); - return false; - } finally { - Binder.restoreCallingIdentity(identity); - } - if (TextUtils.isEmpty(password)) { - return false; - } - - try { - final LockscreenCredential credential; - switch (getCredentialTypeInternal(userId)) { - case CREDENTIAL_TYPE_PATTERN: - credential = createPattern(password); - break; - case CREDENTIAL_TYPE_PIN: - credential = LockscreenCredential.createPin(password); - break; - case CREDENTIAL_TYPE_PASSWORD: - credential = LockscreenCredential.createPassword(password); - break; - default: - credential = null; - Slog.e(TAG, "Unknown credential type"); - } - - if (credential != null - && checkCredential(credential, userId, null /* progressCallback */) - .getResponseCode() == GateKeeperResponse.RESPONSE_OK) { - return true; - } - } catch (Exception e) { - Slog.e(TAG, "checkVoldPassword failed: ", e); - } - - return false; - } - private void removeUser(int userId, boolean unknownUser) { Slog.i(TAG, "RemoveUser: " + userId); removeBiometricsForUser(userId); From 0bc49e6fc3122731a66df1c8d48e2dd47c0a2187 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 26 Jan 2022 05:14:09 +0000 Subject: [PATCH 3/3] Remove unused FDE methods from StorageManager Now that FDE is no longer supported, remove the FDE-related methods from StorageManager that are no longer called. Bug: 208476087 Change-Id: Ic24a5b029bdf51dec622d1b70cef9ef26c3d54c5 (cherry picked from commit 41fa601601ecb094fd813ac4c01356045c34cf88) Merged-In: Ic24a5b029bdf51dec622d1b70cef9ef26c3d54c5 --- .../android/os/storage/IStorageManager.aidl | 53 ----- .../android/os/storage/StorageManager.java | 10 - libs/storage/IMountService.cpp | 36 --- libs/storage/include/storage/IMountService.h | 2 - .../android/server/StorageManagerService.java | 224 ------------------ 5 files changed, 325 deletions(-) diff --git a/core/java/android/os/storage/IStorageManager.aidl b/core/java/android/os/storage/IStorageManager.aidl index 6c0a1f99e112f..b7b6c3002e70f 100644 --- a/core/java/android/os/storage/IStorageManager.aidl +++ b/core/java/android/os/storage/IStorageManager.aidl @@ -77,37 +77,10 @@ interface IStorageManager { * Gets the path to the mounted Opaque Binary Blob (OBB). */ String getMountedObbPath(in String rawPath) = 24; - /** - * Decrypts any encrypted volumes. - */ - int decryptStorage(in String password) = 26; - /** - * Encrypts storage. - */ - int encryptStorage(int type, in String password) = 27; - /** - * Changes the encryption password. - */ - int changeEncryptionPassword(int type, in String password) = 28; /** * Returns list of all mountable volumes. */ StorageVolume[] getVolumeList(int uid, in String packageName, int flags) = 29; - /** - * Determines the encryption state of the volume. - * @return a numerical value. See {@code ENCRYPTION_STATE_*} for possible - * values. - * Note that this has been replaced in most cases by the APIs in - * StorageManager (see isEncryptable and below) - * This is still useful to get the error state when encryption has failed - * and CryptKeeper needs to throw up a screen advising the user what to do - */ - int getEncryptionState() = 31; - /** - * Verify the encryption password against the stored volume. This method - * may only be called by the system process. - */ - int verifyEncryptionPassword(in String password) = 32; /** * Ensure that all directories along given path exist, creating parent * directories as needed. Validates that given path is absolute and that it @@ -116,32 +89,6 @@ interface IStorageManager { * external storage data or OBB directory belonging to calling app. */ void mkdirs(in String callingPkg, in String path) = 34; - /** - * Determines the type of the encryption password - * @return PasswordType - */ - int getPasswordType() = 35; - /** - * Get password from vold - * @return password or empty string - */ - String getPassword() = 36; - /** - * Securely clear password from vold - */ - oneway void clearPassword() = 37; - /** - * Set a field in the crypto header. - * @param field field to set - * @param contents contents to set in field - */ - oneway void setField(in String field, in String contents) = 38; - /** - * Gets a field from the crypto header. - * @param field field to get - * @return contents of field - */ - String getField(in String field) = 39; /** * Report the time of the last maintenance operation such as fstrim. * @return Timestamp of the last maintenance operation, in the diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java index db724d2de30bd..4540574f342ac 100644 --- a/core/java/android/os/storage/StorageManager.java +++ b/core/java/android/os/storage/StorageManager.java @@ -2904,14 +2904,4 @@ public class StorageManager { public static final int CRYPT_TYPE_PATTERN = IVold.PASSWORD_TYPE_PATTERN; /** @hide */ public static final int CRYPT_TYPE_PIN = IVold.PASSWORD_TYPE_PIN; - - // Constants for the data available via StorageManagerService.getField. - /** @hide */ - public static final String SYSTEM_LOCALE_KEY = "SystemLocale"; - /** @hide */ - public static final String OWNER_INFO_KEY = "OwnerInfo"; - /** @hide */ - public static final String PATTERN_VISIBLE_KEY = "PatternVisible"; - /** @hide */ - public static final String PASSWORD_VISIBLE_KEY = "PasswordVisible"; } diff --git a/libs/storage/IMountService.cpp b/libs/storage/IMountService.cpp index 055dbb2b5c5ea..99508a2943ff3 100644 --- a/libs/storage/IMountService.cpp +++ b/libs/storage/IMountService.cpp @@ -48,8 +48,6 @@ enum { TRANSACTION_isObbMounted, TRANSACTION_getMountedObbPath, TRANSACTION_isExternalStorageEmulated, - TRANSACTION_decryptStorage, - TRANSACTION_encryptStorage, }; class BpMountService: public BpInterface @@ -517,40 +515,6 @@ public: path = reply.readString16(); return true; } - - int32_t decryptStorage(const String16& password) - { - Parcel data, reply; - data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); - data.writeString16(password); - if (remote()->transact(TRANSACTION_decryptStorage, data, &reply) != NO_ERROR) { - ALOGD("decryptStorage could not contact remote\n"); - return -1; - } - int32_t err = reply.readExceptionCode(); - if (err < 0) { - ALOGD("decryptStorage caught exception %d\n", err); - return err; - } - return reply.readInt32(); - } - - int32_t encryptStorage(const String16& password) - { - Parcel data, reply; - data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); - data.writeString16(password); - if (remote()->transact(TRANSACTION_encryptStorage, data, &reply) != NO_ERROR) { - ALOGD("encryptStorage could not contact remote\n"); - return -1; - } - int32_t err = reply.readExceptionCode(); - if (err < 0) { - ALOGD("encryptStorage caught exception %d\n", err); - return err; - } - return reply.readInt32(); - } }; IMPLEMENT_META_INTERFACE(MountService, "android.os.storage.IStorageManager") diff --git a/libs/storage/include/storage/IMountService.h b/libs/storage/include/storage/IMountService.h index 5b07318f44320..5a9c39bc021be 100644 --- a/libs/storage/include/storage/IMountService.h +++ b/libs/storage/include/storage/IMountService.h @@ -70,8 +70,6 @@ public: const sp& token, const int32_t nonce) = 0; virtual bool isObbMounted(const String16& filename) = 0; virtual bool getMountedObbPath(const String16& filename, String16& path) = 0; - virtual int32_t decryptStorage(const String16& password) = 0; - virtual int32_t encryptStorage(const String16& password) = 0; }; // ---------------------------------------------------------------------------- diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index 8a83130f50fa1..6e4a1ea134c61 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -3072,203 +3072,6 @@ class StorageManagerService extends IStorageManager.Stub } } - @Override - public int getEncryptionState() { - mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, - "no permission to access the crypt keeper"); - - try { - return mVold.fdeComplete(); - } catch (Exception e) { - Slog.wtf(TAG, e); - return StorageManager.ENCRYPTION_STATE_ERROR_UNKNOWN; - } - } - - @Override - public int decryptStorage(String password) { - mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, - "no permission to access the crypt keeper"); - - if (TextUtils.isEmpty(password)) { - throw new IllegalArgumentException("password cannot be empty"); - } - - if (DEBUG_EVENTS) { - Slog.i(TAG, "decrypting storage..."); - } - - try { - mVold.fdeCheckPassword(password); - mHandler.postDelayed(() -> { - try { - mVold.fdeRestart(); - } catch (Exception e) { - Slog.wtf(TAG, e); - } - }, DateUtils.SECOND_IN_MILLIS); - return 0; - } catch (ServiceSpecificException e) { - Slog.e(TAG, "fdeCheckPassword failed", e); - return e.errorCode; - } catch (Exception e) { - Slog.wtf(TAG, e); - return StorageManager.ENCRYPTION_STATE_ERROR_UNKNOWN; - } - } - - @Override - public int encryptStorage(int type, String password) { - mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, - "no permission to access the crypt keeper"); - - if (type == StorageManager.CRYPT_TYPE_DEFAULT) { - password = ""; - } else if (TextUtils.isEmpty(password)) { - throw new IllegalArgumentException("password cannot be empty"); - } - - if (DEBUG_EVENTS) { - Slog.i(TAG, "encrypting storage..."); - } - - try { - mVold.fdeEnable(type, password, 0); - } catch (Exception e) { - Slog.wtf(TAG, e); - return -1; - } - - return 0; - } - - /** Set the password for encrypting the main key. - * @param type One of the CRYPTO_TYPE_XXX consts defined in StorageManager. - * @param password The password to set. - */ - @Override - public int changeEncryptionPassword(int type, String password) { - mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, - "no permission to access the crypt keeper"); - - if (StorageManager.isFileEncryptedNativeOnly()) { - // Not supported on FBE devices - return -1; - } - - if (type == StorageManager.CRYPT_TYPE_DEFAULT) { - password = ""; - } else if (TextUtils.isEmpty(password)) { - throw new IllegalArgumentException("password cannot be empty"); - } - - if (DEBUG_EVENTS) { - Slog.i(TAG, "changing encryption password..."); - } - - try { - mVold.fdeChangePassword(type, password); - return 0; - } catch (Exception e) { - Slog.wtf(TAG, e); - return -1; - } - } - - /** - * Validate a user-supplied password string with cryptfs - */ - @Override - public int verifyEncryptionPassword(String password) throws RemoteException { - // Only the system process is permitted to validate passwords - if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) { - throw new SecurityException("no permission to access the crypt keeper"); - } - - mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, - "no permission to access the crypt keeper"); - - if (TextUtils.isEmpty(password)) { - throw new IllegalArgumentException("password cannot be empty"); - } - - if (DEBUG_EVENTS) { - Slog.i(TAG, "validating encryption password..."); - } - - try { - mVold.fdeVerifyPassword(password); - return 0; - } catch (Exception e) { - Slog.wtf(TAG, e); - return -1; - } - } - - /** - * Get the type of encryption used to encrypt the main key. - * @return The type, one of the CRYPT_TYPE_XXX consts from StorageManager. - */ - @Override - public int getPasswordType() { - mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, - "no permission to access the crypt keeper"); - - try { - return mVold.fdeGetPasswordType(); - } catch (Exception e) { - Slog.wtf(TAG, e); - return -1; - } - } - - /** - * Set a field in the crypto header. - * @param field field to set - * @param contents contents to set in field - */ - @Override - public void setField(String field, String contents) throws RemoteException { - mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, - "no permission to access the crypt keeper"); - - if (!StorageManager.isBlockEncrypted()) { - // Only supported on FDE devices - return; - } - - try { - mVold.fdeSetField(field, contents); - return; - } catch (Exception e) { - Slog.wtf(TAG, e); - return; - } - } - - /** - * Gets a field from the crypto header. - * @param field field to get - * @return contents of field - */ - @Override - public String getField(String field) throws RemoteException { - mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, - "no permission to access the crypt keeper"); - - if (!StorageManager.isBlockEncrypted()) { - // Only supported on FDE devices - return null; - } - - try { - return mVold.fdeGetField(field); - } catch (Exception e) { - Slog.wtf(TAG, e); - return null; - } - } - /** * Is userdata convertible to file based encryption? * @return non zero for convertible @@ -3350,33 +3153,6 @@ class StorageManagerService extends IStorageManager.Stub mVold.abortChanges(message, retry); } - @Override - public String getPassword() throws RemoteException { - mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, - "only keyguard can retrieve password"); - - try { - return mVold.fdeGetPassword(); - } catch (Exception e) { - Slog.wtf(TAG, e); - return null; - } - } - - @Override - public void clearPassword() throws RemoteException { - mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, - "only keyguard can clear password"); - - try { - mVold.fdeClearPassword(); - return; - } catch (Exception e) { - Slog.wtf(TAG, e); - return; - } - } - @Override public void createUserKey(int userId, int serialNumber, boolean ephemeral) { enforcePermission(android.Manifest.permission.STORAGE_INTERNAL);