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

Commit 96267dbd authored by Eric Biggers's avatar Eric Biggers
Browse files

Simplify initializeSyntheticPasswordLocked()

Originally, initializeSyntheticPasswordLocked() could be called with a
nonempty LSKF when migrating an existing user to SP.  However, now it's
only called with an empty LSKF (except from unit tests, which can use
setLockCredential() instead), as this migration support has become
obsolete and has been removed.  Therefore, simplify it by removing the
credential argument and making it assume an empty LSKF.

Also make initializeSyntheticPasswordLocked() stop explicitly clearing
the protection on the user's CE key and auth-bound Keystore keys.  This
is unnecessary, since the LSKF is known to be empty, and therefore these
protections cannot be set already.  Probably this unnecessary code was
included just for symmetry with the nonempty LSKF case.

Bug: 232452368
Change-Id: I0b9a2f8348d2a0b490cd1c637619c789f1fec582
parent 7d532c8d
Loading
Loading
Loading
Loading
+6 −21
Original line number Diff line number Diff line
@@ -1587,7 +1587,7 @@ public class LockSettingsService extends ILockSettings.Stub {
                if (!savedCredential.isNone()) {
                    throw new IllegalStateException("Saved credential given, but user has no SP");
                }
                initializeSyntheticPasswordLocked(savedCredential, userId);
                initializeSyntheticPasswordLocked(userId);
            } else if (savedCredential.isNone() && isProfileWithUnifiedLock(userId)) {
                // get credential from keystore when profile has unified lock
                try {
@@ -2513,35 +2513,21 @@ public class LockSettingsService extends ILockSettings.Stub {
    }

    /**
     * Creates the synthetic password (SP) for the given user and protects it with the user's LSKF.
     * Creates the synthetic password (SP) for the given user and protects it with an empty LSKF.
     * This is called just once in the lifetime of the user: the first time a nonempty LSKF is set,
     * or when an escrow token is activated on a device with an empty LSKF.
     *
     * Maintains the SP invariants described in {@link SyntheticPasswordManager}.
     */
    @GuardedBy("mSpManager")
    @VisibleForTesting
    SyntheticPassword initializeSyntheticPasswordLocked(LockscreenCredential credential,
            int userId) {
    SyntheticPassword initializeSyntheticPasswordLocked(int userId) {
        Slog.i(TAG, "Initialize SyntheticPassword for user: " + userId);
        Preconditions.checkState(getCurrentLskfBasedProtectorId(userId) ==
                SyntheticPasswordManager.NULL_PROTECTOR_ID,
                "Cannot reinitialize SP");

        final SyntheticPassword sp = mSpManager.newSyntheticPassword(userId);
        long protectorId = mSpManager.createLskfBasedProtector(getGateKeeperService(), credential,
                sp, userId);
        if (!credential.isNone()) {
            mSpManager.newSidForUser(getGateKeeperService(), sp, userId);
            mSpManager.verifyChallenge(getGateKeeperService(), sp, 0L, userId);
            setUserKeyProtection(userId, sp.deriveFileBasedEncryptionKey());
            setKeystorePassword(sp.deriveKeyStorePassword(), userId);
        } else {
            clearUserKeyProtection(userId, null);
            setKeystorePassword(null, userId);
            gateKeeperClearSecureUserId(userId);
        }
        fixateNewestUserKeyAuth(userId);
        final long protectorId = mSpManager.createLskfBasedProtector(getGateKeeperService(),
                LockscreenCredential.createNone(), sp, userId);
        setCurrentLskfBasedProtectorId(protectorId, userId);
        onSyntheticPasswordKnown(userId, sp);
        return sp;
@@ -2818,8 +2804,7 @@ public class LockSettingsService extends ILockSettings.Stub {
            if (!isUserSecure(userId)) {
                long protectorId = getCurrentLskfBasedProtectorId(userId);
                if (protectorId == SyntheticPasswordManager.NULL_PROTECTOR_ID) {
                    sp = initializeSyntheticPasswordLocked(LockscreenCredential.createNone(),
                            userId);
                    sp = initializeSyntheticPasswordLocked(userId);
                } else {
                    sp = mSpManager.unlockLskfBasedProtector(getGateKeeperService(), protectorId,
                            LockscreenCredential.createNone(), userId, null).syntheticPassword;
+4 −1
Original line number Diff line number Diff line
@@ -369,6 +369,8 @@ public class LockSettingsServiceTests extends BaseLockSettingsServiceTests {
                    throws Exception {
        final LockscreenCredential parentPassword = newPassword("parentPassword");
        final LockscreenCredential profilePassword = newPattern("12345");
        mService.setSeparateProfileChallengeEnabled(
                MANAGED_PROFILE_USER_ID, true, profilePassword);
        initializeStorageWithCredential(PRIMARY_USER_ID, parentPassword);
        // Create and verify separate profile credentials.
        testCreateCredential(MANAGED_PROFILE_USER_ID, profilePassword);
@@ -550,11 +552,12 @@ public class LockSettingsServiceTests extends BaseLockSettingsServiceTests {
            throws RemoteException {
        assertEquals(0, mGateKeeperService.getSecureUserId(userId));
        synchronized (mService.mSpManager) {
            mService.initializeSyntheticPasswordLocked(credential, userId);
            mService.initializeSyntheticPasswordLocked(userId);
        }
        if (credential.isNone()) {
            assertEquals(0, mGateKeeperService.getSecureUserId(userId));
        } else {
            assertTrue(mService.setLockCredential(credential, nonePassword(), userId));
            assertNotEquals(0, mGateKeeperService.getSecureUserId(userId));
        }
    }