Skip to content

Commit ca692c2

Browse files
Jim Millergitbuildkicker
authored andcommitted
Bind fingerprint when we start authentication - DO NOT MERGE
This fixes a bug where it was possible to authenticate the wrong user. We now bind the userId when we start authentication and confirm it when authentication completes. Fixes bug 30744668 Change-Id: I346d92c301414ed81e11fa9c171584c7ae4341c2 (cherry picked from commit b6f4b48)
1 parent a1e1881 commit ca692c2

4 files changed

Lines changed: 39 additions & 18 deletions

File tree

core/java/android/hardware/fingerprint/FingerprintManager.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ public long getOpId() {
258258
public static class AuthenticationResult {
259259
private Fingerprint mFingerprint;
260260
private CryptoObject mCryptoObject;
261+
private int mUserId;
261262

262263
/**
263264
* Authentication result
@@ -266,9 +267,10 @@ public static class AuthenticationResult {
266267
* @param fingerprint the recognized fingerprint data, if allowed.
267268
* @hide
268269
*/
269-
public AuthenticationResult(CryptoObject crypto, Fingerprint fingerprint) {
270+
public AuthenticationResult(CryptoObject crypto, Fingerprint fingerprint, int userId) {
270271
mCryptoObject = crypto;
271272
mFingerprint = fingerprint;
273+
mUserId = userId;
272274
}
273275

274276
/**
@@ -285,6 +287,12 @@ public AuthenticationResult(CryptoObject crypto, Fingerprint fingerprint) {
285287
* @hide
286288
*/
287289
public Fingerprint getFingerprint() { return mFingerprint; }
290+
291+
/**
292+
* Obtain the userId for which this fingerprint was authenticated.
293+
* @hide
294+
*/
295+
public int getUserId() { return mUserId; }
288296
};
289297

290298
/**
@@ -754,7 +762,7 @@ public void handleMessage(android.os.Message msg) {
754762
sendAcquiredResult((Long) msg.obj /* deviceId */, msg.arg1 /* acquire info */);
755763
break;
756764
case MSG_AUTHENTICATION_SUCCEEDED:
757-
sendAuthenticatedSucceeded((Fingerprint) msg.obj);
765+
sendAuthenticatedSucceeded((Fingerprint) msg.obj, msg.arg1 /* userId */);
758766
break;
759767
case MSG_AUTHENTICATION_FAILED:
760768
sendAuthenticatedFailed();
@@ -799,9 +807,10 @@ private void sendEnrollResult(Fingerprint fp, int remaining) {
799807
}
800808
}
801809

802-
private void sendAuthenticatedSucceeded(Fingerprint fp) {
810+
private void sendAuthenticatedSucceeded(Fingerprint fp, int userId) {
803811
if (mAuthenticationCallback != null) {
804-
final AuthenticationResult result = new AuthenticationResult(mCryptoObject, fp);
812+
final AuthenticationResult result =
813+
new AuthenticationResult(mCryptoObject, fp, userId);
805814
mAuthenticationCallback.onAuthenticationSucceeded(result);
806815
}
807816
}
@@ -941,8 +950,8 @@ public void onAcquired(long deviceId, int acquireInfo) {
941950
}
942951

943952
@Override // binder call
944-
public void onAuthenticationSucceeded(long deviceId, Fingerprint fp) {
945-
mHandler.obtainMessage(MSG_AUTHENTICATION_SUCCEEDED, fp).sendToTarget();
953+
public void onAuthenticationSucceeded(long deviceId, Fingerprint fp, int userId) {
954+
mHandler.obtainMessage(MSG_AUTHENTICATION_SUCCEEDED, userId, 0, fp).sendToTarget();
946955
}
947956

948957
@Override // binder call

core/java/android/hardware/fingerprint/IFingerprintServiceReceiver.aidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import android.os.UserHandle;
2626
oneway interface IFingerprintServiceReceiver {
2727
void onEnrollResult(long deviceId, int fingerId, int groupId, int remaining);
2828
void onAcquired(long deviceId, int acquiredInfo);
29-
void onAuthenticationSucceeded(long deviceId, in Fingerprint fp);
29+
void onAuthenticationSucceeded(long deviceId, in Fingerprint fp, int userId);
3030
void onAuthenticationFailed(long deviceId);
3131
void onError(long deviceId, int error);
3232
void onRemoved(long deviceId, int fingerId, int groupId);

packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ private void handleFingerprintAcquired(int acquireInfo) {
430430
}
431431
}
432432

433-
private void handleFingerprintAuthenticated() {
433+
434+
private void handleFingerprintAuthenticated(int authUserId) {
434435
try {
435436
final int userId;
436437
try {
@@ -439,6 +440,10 @@ private void handleFingerprintAuthenticated() {
439440
Log.e(TAG, "Failed to get current user id: ", e);
440441
return;
441442
}
443+
if (userId != authUserId) {
444+
Log.d(TAG, "Fingerprint authenticated for wrong user: " + authUserId);
445+
return;
446+
}
442447
if (isFingerprintDisabled(userId)) {
443448
Log.d(TAG, "Fingerprint disabled by DPM for userId: " + userId);
444449
return;
@@ -705,7 +710,7 @@ public void onAuthenticationFailed() {
705710

706711
@Override
707712
public void onAuthenticationSucceeded(AuthenticationResult result) {
708-
handleFingerprintAuthenticated();
713+
handleFingerprintAuthenticated(result.getUserId());
709714
}
710715

711716
@Override

services/core/java/com/android/server/fingerprint/FingerprintService.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public void handleMessage(android.os.Message msg) {
127127
private IFingerprintDaemon mDaemon;
128128
private final PowerManager mPowerManager;
129129
private final AlarmManager mAlarmManager;
130+
private int mCurrentUserId = UserHandle.USER_NULL;
130131

131132
private final BroadcastReceiver mLockoutReceiver = new BroadcastReceiver() {
132133
@Override
@@ -337,7 +338,8 @@ void startEnrollment(IBinder token, byte[] cryptoToken, int groupId,
337338
return;
338339
}
339340
stopPendingOperations(true);
340-
mEnrollClient = new ClientMonitor(token, receiver, groupId, restricted, token.toString());
341+
mEnrollClient = new ClientMonitor(token, receiver, mCurrentUserId, groupId, restricted,
342+
token.toString());
341343
final int timeout = (int) (ENROLLMENT_TIMEOUT_MS / MS_PER_SEC);
342344
try {
343345
final int result = daemon.enroll(cryptoToken, groupId, timeout);
@@ -425,7 +427,8 @@ void startAuthentication(IBinder token, long opId, int groupId,
425427
return;
426428
}
427429
stopPendingOperations(true);
428-
mAuthClient = new ClientMonitor(token, receiver, groupId, restricted, opPackageName);
430+
mAuthClient = new ClientMonitor(token, receiver, mCurrentUserId, groupId, restricted,
431+
opPackageName);
429432
if (inLockoutMode()) {
430433
Slog.v(TAG, "In lockout mode; disallowing authentication");
431434
if (!mAuthClient.sendError(FingerprintManager.FINGERPRINT_ERROR_LOCKOUT)) {
@@ -482,7 +485,8 @@ void startRemove(IBinder token, int fingerId, int userId,
482485
}
483486

484487
stopPendingOperations(true);
485-
mRemoveClient = new ClientMonitor(token, receiver, userId, restricted, token.toString());
488+
mRemoveClient = new ClientMonitor(token, receiver, mCurrentUserId, userId, restricted,
489+
token.toString());
486490
// The fingerprint template ids will be removed when we get confirmation from the HAL
487491
try {
488492
final int result = daemon.remove(fingerId, userId);
@@ -605,15 +609,17 @@ private void notifyLockoutResetMonitors() {
605609
private class ClientMonitor implements IBinder.DeathRecipient {
606610
IBinder token;
607611
IFingerprintServiceReceiver receiver;
608-
int userId;
612+
int userId; // userId of the caller
613+
int currentUserId; // current user id when this was created
609614
boolean restricted; // True if client does not have MANAGE_FINGERPRINT permission
610615
String owner;
611616

612-
public ClientMonitor(IBinder token, IFingerprintServiceReceiver receiver, int userId,
613-
boolean restricted, String owner) {
617+
public ClientMonitor(IBinder token, IFingerprintServiceReceiver receiver,
618+
int currentUserId, int userId, boolean restricted, String owner) {
614619
this.token = token;
615620
this.receiver = receiver;
616621
this.userId = userId;
622+
this.currentUserId = currentUserId;
617623
this.restricted = restricted;
618624
this.owner = owner; // name of the client that owns this - for debugging
619625
try {
@@ -702,9 +708,9 @@ private boolean sendAuthenticated(int fpId, int groupId) {
702708
Slog.v(TAG, "onAuthenticated(owner=" + mAuthClient.owner
703709
+ ", id=" + fpId + ", gp=" + groupId + ")");
704710
}
705-
Fingerprint fp = !restricted ?
706-
new Fingerprint("" /* TODO */, groupId, fpId, mHalDeviceId) : null;
707-
receiver.onAuthenticationSucceeded(mHalDeviceId, fp);
711+
Fingerprint fp = !restricted ? new Fingerprint("" /* TODO */, groupId, fpId,
712+
mHalDeviceId) : null;
713+
receiver.onAuthenticationSucceeded(mHalDeviceId, fp, currentUserId);
708714
}
709715
} catch (RemoteException e) {
710716
Slog.w(TAG, "Failed to notify Authenticated:", e);
@@ -1129,6 +1135,7 @@ private void updateActiveGroup(int userId) {
11291135
Slog.e(TAG, "Failed to setActiveGroup():", e);
11301136
}
11311137
}
1138+
mCurrentUserId = userId;
11321139
}
11331140

11341141
private void listenForUserSwitches() {

0 commit comments

Comments
 (0)