Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fbc65644 authored by Robin Lee's avatar Robin Lee
Browse files

DevicePolicy API to remove an installed KeyPair

The keypair is specified by alias and removed via a call to the
KeyChainService, which will have installed the pair in the first place.

Bug: 22541933
Change-Id: I37317e7c22e89816156e6e9a7abf4c5a59e8440a
parent f12288bd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5802,6 +5802,7 @@ package android.app.admin {
    method public void lockNow();
    method public void removeActiveAdmin(android.content.ComponentName);
    method public boolean removeCrossProfileWidgetProvider(android.content.ComponentName, java.lang.String);
    method public boolean removeKeyPair(android.content.ComponentName, java.lang.String);
    method public boolean removeUser(android.content.ComponentName, android.os.UserHandle);
    method public boolean resetPassword(java.lang.String, int);
    method public void setAccountManagementDisabled(android.content.ComponentName, java.lang.String, boolean);
+1 −0
Original line number Diff line number Diff line
@@ -5935,6 +5935,7 @@ package android.app.admin {
    method public void notifyPendingSystemUpdate(long);
    method public void removeActiveAdmin(android.content.ComponentName);
    method public boolean removeCrossProfileWidgetProvider(android.content.ComponentName, java.lang.String);
    method public boolean removeKeyPair(android.content.ComponentName, java.lang.String);
    method public boolean removeUser(android.content.ComponentName, android.os.UserHandle);
    method public boolean resetPassword(java.lang.String, int);
    method public void setAccountManagementDisabled(android.content.ComponentName, java.lang.String, boolean);
+20 −2
Original line number Diff line number Diff line
@@ -2325,8 +2325,8 @@ public class DevicePolicyManager {
     * with that alias already exists, it will be overwritten.
     * @return {@code true} if the keys were installed, {@code false} otherwise.
     */
    public boolean installKeyPair(@Nullable ComponentName admin, PrivateKey privKey, Certificate cert,
            String alias) {
    public boolean installKeyPair(@Nullable ComponentName admin, @NonNull PrivateKey privKey,
            @NonNull Certificate cert, @NonNull String alias) {
        try {
            final byte[] pemCert = Credentials.convertToPem(cert);
            final byte[] pkcs8Key = KeyFactory.getInstance(privKey.getAlgorithm())
@@ -2342,6 +2342,24 @@ public class DevicePolicyManager {
        return false;
    }

    /**
     * Called by a device or profile owner to remove all user credentials installed under a given
     * alias.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
     *            {@code null} if calling from a delegated certificate installer.
     * @param alias The private key alias under which the certificate is installed.
     * @return {@code true} if the keys were both removed, {@code false} otherwise.
     */
    public boolean removeKeyPair(@Nullable ComponentName admin, @NonNull String alias) {
        try {
            return mService.removeKeyPair(admin, alias);
        } catch (RemoteException e) {
            Log.w(TAG, "Failed talking with device policy service", e);
        }
        return false;
    }

    /**
     * @return the alias of a given CA certificate in the certificate store, or {@code null} if it
     * doesn't exist.
+1 −0
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ interface IDevicePolicyManager {
    void enforceCanManageCaCerts(in ComponentName admin);

    boolean installKeyPair(in ComponentName who, in byte[] privKeyBuffer, in byte[] certBuffer, String alias);
    boolean removeKeyPair(in ComponentName who, String alias);
    void choosePrivateKeyAlias(int uid, in Uri uri, in String alias, IBinder aliasCallback);

    void setCertInstallerPackage(in ComponentName who, String installerPackage);
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ interface IKeyChainService {

    // APIs used by DevicePolicyManager
    boolean installKeyPair(in byte[] privateKey, in byte[] userCert, String alias);
    boolean removeKeyPair(String alias);

    // APIs used by Settings
    boolean deleteCaCertificate(String alias);
Loading