Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99b5699b authored by Thomas Cedeno's avatar Thomas Cedeno
Browse files

Harden DevicePolicyManagerService

Add code to zeroize internal sensitive data.

Bug: 384030190, 320392352
Flag: EXEMPT internal refactor/hardening
Test: atest CtsDevicePolicyTestCases
Change-Id: Icfe4c22ea4c595344f49cc659e72c793078c5852
parent 54bdf029
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -2541,10 +2541,12 @@ public class LockSettingsService extends ILockSettings.Stub {
     * reporting the password changed.
     */
    private void notifyPasswordChanged(LockscreenCredential newCredential, @UserIdInt int userId) {
        // Must compute the PasswordMetrics for newCredential outside the mHandler asynchronous
        // call, as once the handler actually runs the thread the newCredential parameter may be
        // zeroized by the caller.
        PasswordMetrics newMetrics = PasswordMetrics.computeForCredential(newCredential);
        mHandler.post(() -> {
            mInjector.getDevicePolicyManager().reportPasswordChanged(
                    PasswordMetrics.computeForCredential(newCredential),
                    userId);
            mInjector.getDevicePolicyManager().reportPasswordChanged(newMetrics, userId);
            LocalServices.getService(WindowManagerInternal.class).reportPasswordChanged(userId);
        });
    }
+20 −7
Original line number Diff line number Diff line
@@ -6050,15 +6050,18 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    private boolean resetPasswordInternal(String password, long tokenHandle, byte[] token,
            int flags, CallerIdentity caller) {
        final int callingUid = caller.getUid();
        final int userHandle = UserHandle.getUserId(callingUid);
        final boolean isPin = PasswordMetrics.isNumericOnly(password);
        final LockscreenCredential newCredential;
        if (isPin) {
            newCredential = LockscreenCredential.createPin(password);
        } else {
            newCredential = LockscreenCredential.createPasswordOrNone(password);
        try (LockscreenCredential newCredential =
                isPin ? LockscreenCredential.createPin(password) :
                    LockscreenCredential.createPasswordOrNone(password)) {
            return resetPasswordInternal(newCredential, tokenHandle, token, flags, caller);
        }
    }
    private boolean resetPasswordInternal(LockscreenCredential newCredential,
            long tokenHandle, byte[] token, int flags, CallerIdentity caller) {
        final int callingUid = caller.getUid();
        final int userHandle = UserHandle.getUserId(callingUid);
        synchronized (getLockObject()) {
            final PasswordMetrics minMetrics = getPasswordMinimumMetricsUnchecked(userHandle);
            final int complexity = getAggregatedPasswordComplexityLocked(userHandle);
@@ -19439,6 +19442,16 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    @Override
    public boolean resetPasswordWithToken(ComponentName admin, String callerPackageName,
            String passwordOrNull, byte[] token, int flags) {
        try {
            return resetPasswordWithTokenInternal(admin, callerPackageName, passwordOrNull, token,
                    flags);
        } finally {
            ArrayUtils.zeroize(token);
        }
    }
    public boolean resetPasswordWithTokenInternal(ComponentName admin, String callerPackageName,
            String passwordOrNull, byte[] token,
            int flags) {
        if (!mHasFeature || !mLockPatternUtils.hasSecureLockScreen()) {