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

Commit 5197fd2f authored by Eric Biggers's avatar Eric Biggers Committed by Gerrit Code Review
Browse files

Merge "Avoid NPE when trying to unlock user with wrong token handle" into main

parents 0cdab078 6c23a593
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -1541,8 +1541,14 @@ class SyntheticPasswordManager {
     */
    public @NonNull AuthenticationResult unlockTokenBasedProtector(
            IGateKeeperService gatekeeper, long protectorId, byte[] token, int userId) {
        SyntheticPasswordBlob blob = SyntheticPasswordBlob.fromBytes(loadState(SP_BLOB_NAME,
                    protectorId, userId));
        byte[] data = loadState(SP_BLOB_NAME, protectorId, userId);
        if (data == null) {
            AuthenticationResult result = new AuthenticationResult();
            result.gkResponse = VerifyCredentialResponse.ERROR;
            Slogf.w(TAG, "spblob not found for protector %016x, user %d", protectorId, userId);
            return result;
        }
        SyntheticPasswordBlob blob = SyntheticPasswordBlob.fromBytes(data);
        return unlockTokenBasedProtectorInternal(gatekeeper, protectorId, blob.mProtectorType,
                token, userId);
    }
+8 −0
Original line number Diff line number Diff line
@@ -505,6 +505,14 @@ public class SyntheticPasswordTests extends BaseLockSettingsServiceTests {
        assertEquals(CREDENTIAL_TYPE_NONE, mService.getCredentialType(PRIMARY_USER_ID));
    }

    @Test
    public void testUnlockUserWithTokenWithBadHandleReturnsFalse() {
        final long badTokenHandle = 123456789;
        final byte[] token = "some-high-entropy-secure-token".getBytes();
        mService.initializeSyntheticPassword(PRIMARY_USER_ID);
        assertFalse(mLocalService.unlockUserWithToken(badTokenHandle, token, PRIMARY_USER_ID));
    }

    @Test
    public void testGetHashFactorPrimaryUser() throws RemoteException {
        LockscreenCredential password = newPassword("password");