summaryrefslogtreecommitdiffstats
path: root/keystore/java
diff options
context:
space:
mode:
authorChad Brubaker <cbrubaker@google.com>2015-05-07 10:02:22 -0700
committerChad Brubaker <cbrubaker@google.com>2015-05-08 11:11:43 -0700
commita91a8504191d91d288c55821caa5bf00c9be26a2 (patch)
treee7eece5120d2c08ca3321d58507d979eeca63e45 /keystore/java
parent1bc3c849ba5e9f23dd7e93012c4b5800b78c221b (diff)
downloadframeworks_base-a91a8504191d91d288c55821caa5bf00c9be26a2.zip
frameworks_base-a91a8504191d91d288c55821caa5bf00c9be26a2.tar.gz
frameworks_base-a91a8504191d91d288c55821caa5bf00c9be26a2.tar.bz2
Cleanup keystore password changing and unlocking
Add KeyStore.onUserPasswordChanged for the lockscreen to call when the user changes their password. Keystore will then handle the logic of deleting keys. Instead of calling Keystore.password_uid for both unlocking and password changes the behavior has been split into Keystore.unlock and onUserPasswordChanged. Change-Id: I324914c00195d762cbaa8c63084e41fa796b7df8
Diffstat (limited to 'keystore/java')
-rw-r--r--keystore/java/android/security/KeyStore.java54
1 files changed, 43 insertions, 11 deletions
diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java
index 82d328b..762be9d 100644
--- a/keystore/java/android/security/KeyStore.java
+++ b/keystore/java/android/security/KeyStore.java
@@ -24,8 +24,10 @@ import android.content.Context;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Binder;
import android.os.IBinder;
+import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.os.UserHandle;
import android.security.keymaster.ExportResult;
import android.security.keymaster.KeyCharacteristics;
import android.security.keymaster.KeymasterArguments;
@@ -212,15 +214,6 @@ public class KeyStore {
}
}
- public boolean password(String password) {
- try {
- return mBinder.password(password) == NO_ERROR;
- } catch (RemoteException e) {
- Log.w(TAG, "Cannot connect to keystore", e);
- return false;
- }
- }
-
public boolean lock() {
try {
return mBinder.lock() == NO_ERROR;
@@ -230,9 +223,20 @@ public class KeyStore {
}
}
- public boolean unlock(String password) {
+ /**
+ * Attempt to unlock the keystore for {@code user} with the password {@code password}.
+ * This is required before keystore entries created with FLAG_ENCRYPTED can be accessed or
+ * created.
+ *
+ * @param user Android user ID to operate on
+ * @param password user's keystore password. Should be the most recent value passed to
+ * {@link #onUserPasswordChanged} for the user.
+ *
+ * @return whether the keystore was unlocked.
+ */
+ public boolean unlock(int userId, String password) {
try {
- mError = mBinder.unlock(password);
+ mError = mBinder.unlock(userId, password);
return mError == NO_ERROR;
} catch (RemoteException e) {
Log.w(TAG, "Cannot connect to keystore", e);
@@ -240,6 +244,10 @@ public class KeyStore {
}
}
+ public boolean unlock(String password) {
+ return unlock(UserHandle.getUserId(Process.myUid()), password);
+ }
+
public boolean isEmpty() {
try {
return mBinder.zero() == KEY_NOT_FOUND;
@@ -540,6 +548,30 @@ public class KeyStore {
}
/**
+ * Notify keystore that a user's password has changed.
+ *
+ * @param userId the user whose password changed.
+ * @param newPassword the new password or "" if the password was removed.
+ */
+ public boolean onUserPasswordChanged(int userId, String newPassword) {
+ // Parcel.cpp doesn't support deserializing null strings and treats them as "". Make that
+ // explicit here.
+ if (newPassword == null) {
+ newPassword = "";
+ }
+ try {
+ return mBinder.onUserPasswordChanged(userId, newPassword) == NO_ERROR;
+ } catch (RemoteException e) {
+ Log.w(TAG, "Cannot connect to keystore", e);
+ return false;
+ }
+ }
+
+ public boolean onUserPasswordChanged(String newPassword) {
+ return onUserPasswordChanged(UserHandle.getUserId(Process.myUid()), newPassword);
+ }
+
+ /**
* Returns a {@link KeyStoreException} corresponding to the provided keystore/keymaster error
* code.
*/