summaryrefslogtreecommitdiff
path: root/keystore/java
diff options
context:
space:
mode:
author Eric Biggers <ebiggers@google.com> 2023-12-01 23:55:31 +0000
committer Eric Biggers <ebiggers@google.com> 2023-12-06 02:59:54 +0000
commitc22ce02b36fab2fced9532a0ae23e465fd29d1fa (patch)
treef3884a8d6e8d03e5b36a7156910826d4d3a5ef46 /keystore/java
parentfc31e4ed5abb6fb966784b4fa104554c952cbd83 (diff)
Split Keystore's onLockScreenEvent into onDevice{Unlocked,Locked}
Currently Keystore is notified of the device being unlocked and locked for each user via onLockScreenEvent(lockScreenEvent, userId, password, unlockingSids), where lockScreenEvent is UNLOCK or LOCK. This is a bit confusing because the password parameter is only meaningful for UNLOCK, and the unlockingSids parameter is only meaningful for LOCK. This problem will get worse when we add a parameter that tells Keystore whether unlocking via a weak biometric or trust agent is possible, as that will be another parameter that is only meaningful for LOCK. Therefore, this CL splits onLockScreenEvent into two methods onDeviceUnlocked and onDeviceLocked, each with the appropriate parameters. No actual change in behavior intended. This change does make TrustManagerService no longer call getBiometricSids() for unlocks, so technically that is a slight difference; however, for UNLOCK events Keystore ignored the SID list, so this just eliminates unnecessary work. Bug: 296464083 Test: atest -p --include-subdirs system/security/keystore2 \ && atest CtsKeystoreTestCases \ && atest TrustTests \ && atest com.android.server.locksettings Flag: N/A, straightforward refactoring Change-Id: Ibfaa22ba27d13248c9c4c69a4d2efb2231792c31
Diffstat (limited to 'keystore/java')
-rw-r--r--keystore/java/android/security/Authorization.java40
1 files changed, 25 insertions, 15 deletions
diff --git a/keystore/java/android/security/Authorization.java b/keystore/java/android/security/Authorization.java
index b4b3e9275035..4ec5e1b67c5d 100644
--- a/keystore/java/android/security/Authorization.java
+++ b/keystore/java/android/security/Authorization.java
@@ -26,7 +26,6 @@ import android.os.ServiceManager;
import android.os.ServiceSpecificException;
import android.os.StrictMode;
import android.security.authorization.IKeystoreAuthorization;
-import android.security.authorization.LockScreenEvent;
import android.system.keystore2.ResponseCode;
import android.util.Log;
@@ -76,26 +75,37 @@ public class Authorization {
}
/**
- * Informs keystore2 about lock screen event.
+ * Tells Keystore that the device is now unlocked for a user.
*
- * @param locked - whether it is a lock (true) or unlock (false) event
- * @param syntheticPassword - if it is an unlock event with the password, pass the synthetic
- * password provided by the LockSettingService
- * @param unlockingSids - KeyMint secure user IDs that should be permitted to unlock
- * UNLOCKED_DEVICE_REQUIRED keys.
+ * @param userId - the user's Android user ID
+ * @param password - a secret derived from the user's synthetic password, if the unlock method
+ * is LSKF (or equivalent) and thus has made the synthetic password available
+ * @return 0 if successful or a {@code ResponseCode}.
+ */
+ public static int onDeviceUnlocked(int userId, @Nullable byte[] password) {
+ StrictMode.noteDiskWrite();
+ try {
+ getService().onDeviceUnlocked(userId, password);
+ return 0;
+ } catch (RemoteException | NullPointerException e) {
+ Log.w(TAG, "Can not connect to keystore", e);
+ return SYSTEM_ERROR;
+ } catch (ServiceSpecificException e) {
+ return e.errorCode;
+ }
+ }
+
+ /**
+ * Tells Keystore that the device is now locked for a user.
*
+ * @param userId - the user's Android user ID
+ * @param unlockingSids - list of biometric SIDs with which the device may be unlocked again
* @return 0 if successful or a {@code ResponseCode}.
*/
- public static int onLockScreenEvent(@NonNull boolean locked, @NonNull int userId,
- @Nullable byte[] syntheticPassword, @Nullable long[] unlockingSids) {
+ public static int onDeviceLocked(int userId, @NonNull long[] unlockingSids) {
StrictMode.noteDiskWrite();
try {
- if (locked) {
- getService().onLockScreenEvent(LockScreenEvent.LOCK, userId, null, unlockingSids);
- } else {
- getService().onLockScreenEvent(
- LockScreenEvent.UNLOCK, userId, syntheticPassword, unlockingSids);
- }
+ getService().onDeviceLocked(userId, unlockingSids);
return 0;
} catch (RemoteException | NullPointerException e) {
Log.w(TAG, "Can not connect to keystore", e);