Merge "Keystore 2.0: Revisite Authorization.java"
This commit is contained in:
@@ -33,20 +33,12 @@ import android.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class Authorization {
|
public class Authorization {
|
||||||
private static final String TAG = "KeystoreAuthorization";
|
private static final String TAG = "KeystoreAuthorization";
|
||||||
private static IKeystoreAuthorization sIKeystoreAuthorization;
|
|
||||||
|
|
||||||
public static final int SYSTEM_ERROR = ResponseCode.SYSTEM_ERROR;
|
public static final int SYSTEM_ERROR = ResponseCode.SYSTEM_ERROR;
|
||||||
|
|
||||||
public Authorization() {
|
private static IKeystoreAuthorization getService() {
|
||||||
sIKeystoreAuthorization = null;
|
return IKeystoreAuthorization.Stub.asInterface(
|
||||||
}
|
|
||||||
|
|
||||||
private static synchronized IKeystoreAuthorization getService() {
|
|
||||||
if (sIKeystoreAuthorization == null) {
|
|
||||||
sIKeystoreAuthorization = IKeystoreAuthorization.Stub.asInterface(
|
|
||||||
ServiceManager.checkService("android.security.authorization"));
|
ServiceManager.checkService("android.security.authorization"));
|
||||||
}
|
|
||||||
return sIKeystoreAuthorization;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,12 +47,12 @@ public class Authorization {
|
|||||||
* @param authToken created by Android authenticators.
|
* @param authToken created by Android authenticators.
|
||||||
* @return 0 if successful or {@code ResponseCode.SYSTEM_ERROR}.
|
* @return 0 if successful or {@code ResponseCode.SYSTEM_ERROR}.
|
||||||
*/
|
*/
|
||||||
public int addAuthToken(@NonNull HardwareAuthToken authToken) {
|
public static int addAuthToken(@NonNull HardwareAuthToken authToken) {
|
||||||
if (!android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) return 0;
|
if (!android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) return 0;
|
||||||
try {
|
try {
|
||||||
getService().addAuthToken(authToken);
|
getService().addAuthToken(authToken);
|
||||||
return 0;
|
return 0;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException | NullPointerException e) {
|
||||||
Log.w(TAG, "Can not connect to keystore", e);
|
Log.w(TAG, "Can not connect to keystore", e);
|
||||||
return SYSTEM_ERROR;
|
return SYSTEM_ERROR;
|
||||||
} catch (ServiceSpecificException e) {
|
} catch (ServiceSpecificException e) {
|
||||||
@@ -73,7 +65,7 @@ public class Authorization {
|
|||||||
* @param authToken
|
* @param authToken
|
||||||
* @return 0 if successful or a {@code ResponseCode}.
|
* @return 0 if successful or a {@code ResponseCode}.
|
||||||
*/
|
*/
|
||||||
public int addAuthToken(@NonNull byte[] authToken) {
|
public static int addAuthToken(@NonNull byte[] authToken) {
|
||||||
return addAuthToken(AuthTokenUtils.toHardwareAuthToken(authToken));
|
return addAuthToken(AuthTokenUtils.toHardwareAuthToken(authToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +78,7 @@ public class Authorization {
|
|||||||
*
|
*
|
||||||
* @return 0 if successful or a {@code ResponseCode}.
|
* @return 0 if successful or a {@code ResponseCode}.
|
||||||
*/
|
*/
|
||||||
public int onLockScreenEvent(@NonNull boolean locked, @NonNull int userId,
|
public static int onLockScreenEvent(@NonNull boolean locked, @NonNull int userId,
|
||||||
@Nullable byte[] syntheticPassword) {
|
@Nullable byte[] syntheticPassword) {
|
||||||
if (!android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) return 0;
|
if (!android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) return 0;
|
||||||
try {
|
try {
|
||||||
@@ -96,7 +88,7 @@ public class Authorization {
|
|||||||
getService().onLockScreenEvent(LockScreenEvent.UNLOCK, userId, syntheticPassword);
|
getService().onLockScreenEvent(LockScreenEvent.UNLOCK, userId, syntheticPassword);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException | NullPointerException e) {
|
||||||
Log.w(TAG, "Can not connect to keystore", e);
|
Log.w(TAG, "Can not connect to keystore", e);
|
||||||
return SYSTEM_ERROR;
|
return SYSTEM_ERROR;
|
||||||
} catch (ServiceSpecificException e) {
|
} catch (ServiceSpecificException e) {
|
||||||
|
|||||||
@@ -996,7 +996,7 @@ public class KeyStore {
|
|||||||
*/
|
*/
|
||||||
public int addAuthToken(byte[] authToken) {
|
public int addAuthToken(byte[] authToken) {
|
||||||
try {
|
try {
|
||||||
new Authorization().addAuthToken(authToken);
|
Authorization.addAuthToken(authToken);
|
||||||
return mBinder.addAuthToken(authToken);
|
return mBinder.addAuthToken(authToken);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.w(TAG, "Cannot connect to keystore", e);
|
Log.w(TAG, "Cannot connect to keystore", e);
|
||||||
|
|||||||
@@ -107,7 +107,6 @@ public class KeyStore2 {
|
|||||||
try {
|
try {
|
||||||
return request.execute(service);
|
return request.execute(service);
|
||||||
} catch (ServiceSpecificException e) {
|
} catch (ServiceSpecificException e) {
|
||||||
Log.e(TAG, "KeyStore exception", e);
|
|
||||||
throw getKeyStoreException(e.errorCode);
|
throw getKeyStoreException(e.errorCode);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
if (firstTry) {
|
if (firstTry) {
|
||||||
|
|||||||
@@ -1280,7 +1280,7 @@ public class LockSettingsService extends ILockSettings.Stub {
|
|||||||
|
|
||||||
private void unlockKeystore(byte[] password, int userHandle) {
|
private void unlockKeystore(byte[] password, int userHandle) {
|
||||||
if (DEBUG) Slog.v(TAG, "Unlock keystore for user: " + userHandle);
|
if (DEBUG) Slog.v(TAG, "Unlock keystore for user: " + userHandle);
|
||||||
new Authorization().onLockScreenEvent(false, userHandle, password);
|
Authorization.onLockScreenEvent(false, userHandle, password);
|
||||||
// TODO(b/120484642): Update keystore to accept byte[] passwords
|
// TODO(b/120484642): Update keystore to accept byte[] passwords
|
||||||
String passwordString = password == null ? null : new String(password);
|
String passwordString = password == null ? null : new String(password);
|
||||||
final KeyStore ks = KeyStore.getInstance();
|
final KeyStore ks = KeyStore.getInstance();
|
||||||
|
|||||||
@@ -700,7 +700,7 @@ public class TrustManagerService extends SystemService {
|
|||||||
if (changed) {
|
if (changed) {
|
||||||
dispatchDeviceLocked(userId, locked);
|
dispatchDeviceLocked(userId, locked);
|
||||||
|
|
||||||
mAuthorizationService.onLockScreenEvent(locked, userId, null);
|
Authorization.onLockScreenEvent(locked, userId, null);
|
||||||
KeyStore.getInstance().onUserLockedStateChanged(userId, locked);
|
KeyStore.getInstance().onUserLockedStateChanged(userId, locked);
|
||||||
// Also update the user's profiles who have unified challenge, since they
|
// Also update the user's profiles who have unified challenge, since they
|
||||||
// share the same unlocked state (see {@link #isDeviceLocked(int)})
|
// share the same unlocked state (see {@link #isDeviceLocked(int)})
|
||||||
@@ -1258,7 +1258,7 @@ public class TrustManagerService extends SystemService {
|
|||||||
mDeviceLockedForUser.put(userId, locked);
|
mDeviceLockedForUser.put(userId, locked);
|
||||||
}
|
}
|
||||||
|
|
||||||
mAuthorizationService.onLockScreenEvent(locked, userId, null);
|
Authorization.onLockScreenEvent(locked, userId, null);
|
||||||
KeyStore.getInstance().onUserLockedStateChanged(userId, locked);
|
KeyStore.getInstance().onUserLockedStateChanged(userId, locked);
|
||||||
|
|
||||||
if (locked) {
|
if (locked) {
|
||||||
|
|||||||
Reference in New Issue
Block a user