Remove HardwareAuthToken support from FakeStorageManager

There is no longer any need for FakeStorageManager to keep track of
hardware auth tokens, since they aren't used for real anymore.

Test: atest com.android.server.locksettings
Bug: 184723544
Change-Id: Ida3a989ecea974fe79568e381cf0e6ff3fe1f1eb
(cherry picked from commit 2e10d6394a)
Merged-In: Ida3a989ecea974fe79568e381cf0e6ff3fe1f1eb
This commit is contained in:
Eric Biggers
2022-01-26 01:59:14 +00:00
parent dc2f8bfaee
commit 401e447e10
2 changed files with 19 additions and 22 deletions

View File

@@ -221,7 +221,6 @@ public abstract class BaseLockSettingsServiceTests {
Object[] args = invocation.getArguments(); Object[] args = invocation.getArguments();
mStorageManager.addUserKeyAuth((int) args[0] /* userId */, mStorageManager.addUserKeyAuth((int) args[0] /* userId */,
(int) args[1] /* serialNumber */, (int) args[1] /* serialNumber */,
(byte[]) args[2] /* token */,
(byte[]) args[3] /* secret */); (byte[]) args[3] /* secret */);
return null; return null;
} }
@@ -233,7 +232,6 @@ public abstract class BaseLockSettingsServiceTests {
Object[] args = invocation.getArguments(); Object[] args = invocation.getArguments();
mStorageManager.clearUserKeyAuth((int) args[0] /* userId */, mStorageManager.clearUserKeyAuth((int) args[0] /* userId */,
(int) args[1] /* serialNumber */, (int) args[1] /* serialNumber */,
(byte[]) args[2] /* token */,
(byte[]) args[3] /* secret */); (byte[]) args[3] /* secret */);
return null; return null;
} }

View File

@@ -19,7 +19,6 @@ package com.android.server.locksettings;
import android.os.IProgressListener; import android.os.IProgressListener;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.Pair;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
@@ -29,56 +28,56 @@ import java.util.Arrays;
public class FakeStorageManager { public class FakeStorageManager {
private ArrayMap<Integer, ArrayList<Pair<byte[], byte[]>>> mAuth = new ArrayMap<>(); private ArrayMap<Integer, ArrayList<byte[]>> mAuth = new ArrayMap<>();
private boolean mIgnoreBadUnlock; private boolean mIgnoreBadUnlock;
public void addUserKeyAuth(int userId, int serialNumber, byte[] token, byte[] secret) { public void addUserKeyAuth(int userId, int serialNumber, byte[] secret) {
getUserAuth(userId).add(new Pair<>(token, secret)); getUserAuth(userId).add(secret);
} }
public void clearUserKeyAuth(int userId, int serialNumber, byte[] token, byte[] secret) { public void clearUserKeyAuth(int userId, int serialNumber, byte[] secret) {
ArrayList<Pair<byte[], byte[]>> auths = getUserAuth(userId); ArrayList<byte[]> auths = getUserAuth(userId);
if (token == null && secret == null) { if (secret == null) {
return; return;
} }
auths.remove(new Pair<>(token, secret)); auths.remove(secret);
auths.add(new Pair<>(null, null)); auths.add(null);
} }
public void fixateNewestUserKeyAuth(int userId) { public void fixateNewestUserKeyAuth(int userId) {
ArrayList<Pair<byte[], byte[]>> auths = mAuth.get(userId); ArrayList<byte[]> auths = mAuth.get(userId);
Pair<byte[], byte[]> latest = auths.get(auths.size() - 1); byte[] latest = auths.get(auths.size() - 1);
auths.clear(); auths.clear();
auths.add(latest); auths.add(latest);
} }
private ArrayList<Pair<byte[], byte[]>> getUserAuth(int userId) { private ArrayList<byte[]> getUserAuth(int userId) {
if (!mAuth.containsKey(userId)) { if (!mAuth.containsKey(userId)) {
ArrayList<Pair<byte[], byte[]>> auths = new ArrayList<Pair<byte[], byte[]>>(); ArrayList<byte[]> auths = new ArrayList<>();
auths.add(new Pair(null, null)); auths.add(null);
mAuth.put(userId, auths); mAuth.put(userId, auths);
} }
return mAuth.get(userId); return mAuth.get(userId);
} }
public byte[] getUserUnlockToken(int userId) { public byte[] getUserUnlockToken(int userId) {
ArrayList<Pair<byte[], byte[]>> auths = getUserAuth(userId); ArrayList<byte[]> auths = getUserAuth(userId);
if (auths.size() != 1) { if (auths.size() != 1) {
throw new AssertionFailedError("More than one secret exists"); throw new AssertionFailedError("More than one secret exists");
} }
return auths.get(0).second; return auths.get(0);
} }
public void unlockUser(int userId, byte[] secret, IProgressListener listener) public void unlockUser(int userId, byte[] secret, IProgressListener listener)
throws RemoteException { throws RemoteException {
listener.onStarted(userId, null); listener.onStarted(userId, null);
listener.onFinished(userId, null); listener.onFinished(userId, null);
ArrayList<Pair<byte[], byte[]>> auths = getUserAuth(userId); ArrayList<byte[]> auths = getUserAuth(userId);
if (auths.size() > 1) { if (auths.size() > 1) {
throw new AssertionFailedError("More than one secret exists"); throw new AssertionFailedError("More than one secret exists");
} }
Pair<byte[], byte[]> auth = auths.get(0); byte[] auth = auths.get(0);
if (!Arrays.equals(secret, auth.second)) { if (!Arrays.equals(secret, auth)) {
if (!mIgnoreBadUnlock) { if (!mIgnoreBadUnlock) {
throw new AssertionFailedError("Invalid secret to unlock user " + userId); throw new AssertionFailedError("Invalid secret to unlock user " + userId);
} }