Merge "Keystore 2.0: Clear Uid/Namesapce" am: a51a74a8c5 am: 6413a11508

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1604089

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I99a812efeb0ad269f59118cecee7cae183bac041
This commit is contained in:
Janis Danisevskis
2021-02-26 04:33:55 +00:00
committed by Automerger Merge Worker
2 changed files with 26 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ import android.annotation.Nullable;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.os.ServiceSpecificException; import android.os.ServiceSpecificException;
import android.security.usermanager.IKeystoreUserManager; import android.security.usermanager.IKeystoreUserManager;
import android.system.keystore2.Domain;
import android.system.keystore2.ResponseCode; import android.system.keystore2.ResponseCode;
import android.util.Log; import android.util.Log;
@@ -39,7 +40,7 @@ public class AndroidKeyStoreMaintenance {
} }
/** /**
* Informs keystore2 about adding a user * Informs Keystore 2.0 about adding a user
* *
* @param userId - Android user id of the user being added * @param userId - Android user id of the user being added
* @return 0 if successful or a {@code ResponseCode} * @return 0 if successful or a {@code ResponseCode}
@@ -60,7 +61,7 @@ public class AndroidKeyStoreMaintenance {
} }
/** /**
* Informs keystore2 about removing a usergit mer * Informs Keystore 2.0 about removing a usergit mer
* *
* @param userId - Android user id of the user being removed * @param userId - Android user id of the user being removed
* @return 0 if successful or a {@code ResponseCode} * @return 0 if successful or a {@code ResponseCode}
@@ -81,7 +82,7 @@ public class AndroidKeyStoreMaintenance {
} }
/** /**
* Informs keystore2 about changing user's password * Informs Keystore 2.0 about changing user's password
* *
* @param userId - Android user id of the user * @param userId - Android user id of the user
* @param password - a secret derived from the synthetic password provided by the * @param password - a secret derived from the synthetic password provided by the
@@ -102,4 +103,22 @@ public class AndroidKeyStoreMaintenance {
return SYSTEM_ERROR; return SYSTEM_ERROR;
} }
} }
/**
* Informs Keystore 2.0 that an app was uninstalled and the corresponding namspace is to
* be cleared.
*/
public static int clearNamespace(@Domain int domain, long namespace) {
if (!android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) return 0;
try {
getService().clearNamespace(domain, namespace);
return 0;
} catch (ServiceSpecificException e) {
Log.e(TAG, "clearNamespace failed", e);
return e.errorCode;
} catch (Exception e) {
Log.e(TAG, "Can not connect to keystore", e);
return SYSTEM_ERROR;
}
}
} }

View File

@@ -43,6 +43,7 @@ import android.security.keystore.KeyPermanentlyInvalidatedException;
import android.security.keystore.KeyProperties; import android.security.keystore.KeyProperties;
import android.security.keystore.KeystoreResponse; import android.security.keystore.KeystoreResponse;
import android.security.keystore.UserNotAuthenticatedException; import android.security.keystore.UserNotAuthenticatedException;
import android.system.keystore2.Domain;
import android.util.Log; import android.util.Log;
import com.android.internal.org.bouncycastle.asn1.ASN1InputStream; import com.android.internal.org.bouncycastle.asn1.ASN1InputStream;
@@ -466,6 +467,9 @@ public class KeyStore {
public boolean clearUid(int uid) { public boolean clearUid(int uid) {
try { try {
if (android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) {
return AndroidKeyStoreMaintenance.clearNamespace(Domain.APP, uid) == 0;
}
return mBinder.clear_uid(uid) == NO_ERROR; return mBinder.clear_uid(uid) == NO_ERROR;
} catch (RemoteException e) { } catch (RemoteException e) {
Log.w(TAG, "Cannot connect to keystore", e); Log.w(TAG, "Cannot connect to keystore", e);