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

Commit 094c8cc9 authored by Brahmaji K's avatar Brahmaji K Committed by Gerrit - the friendly Code Review server
Browse files

LockSettings: fix the get password issue during boot up

Use the lock setting service info from ILockSettings class
instead of LockSettingsService classs to get the stored
password the stored passed during bootup. Also check whether
called process has cryptkeeper or Admin permissions to get
the password.

Change-Id: I5970168853f1e4cca876f6ae767b0702368663b3
parent 739f7ac3
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -40,4 +40,5 @@ interface ILockSettings {
    void registerStrongAuthTracker(in IStrongAuthTracker tracker);
    void registerStrongAuthTracker(in IStrongAuthTracker tracker);
    void unregisterStrongAuthTracker(in IStrongAuthTracker tracker);
    void unregisterStrongAuthTracker(in IStrongAuthTracker tracker);
    void requireStrongAuth(int strongAuthReason, int userId);
    void requireStrongAuth(int strongAuthReason, int userId);
    String getPassword();
}
}
+21 −1
Original line number Original line Diff line number Diff line
@@ -388,7 +388,27 @@ public class LockSettingsService extends ILockSettings.Stub {
        }
        }
    }
    }


    private boolean checkCryptKeeperPermissions() {
        boolean permission_err = false;
        try {
            mContext.enforceCallingOrSelfPermission(
                       android.Manifest.permission.CRYPT_KEEPER,
                       "no permission to get the password");
        } catch (SecurityException e) {
            permission_err = true;
        }
        return permission_err;
    }

    public String getPassword() {
    public String getPassword() {
       /** if calling process does't have crypt keeper or admin permissions,
         * throw the exception.
         */
       if (checkCryptKeeperPermissions())
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.MANAGE_DEVICE_ADMINS,
                    "no crypt_keeper or admin permission to get the password");

       return mSavePassword;
       return mSavePassword;
    }
    }


+15 −3
Original line number Original line Diff line number Diff line
@@ -101,6 +101,7 @@ import com.android.internal.util.Preconditions;
import com.android.server.NativeDaemonConnector.Command;
import com.android.server.NativeDaemonConnector.Command;
import com.android.server.NativeDaemonConnector.SensitiveArg;
import com.android.server.NativeDaemonConnector.SensitiveArg;
import com.android.server.pm.PackageManagerService;
import com.android.server.pm.PackageManagerService;
import com.android.internal.widget.ILockSettings;


import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserException;
@@ -2460,13 +2461,24 @@ class MountService extends IMountService.Stub
            Slog.i(TAG, "changing encryption password...");
            Slog.i(TAG, "changing encryption password...");
        }
        }


        LockSettingsService lockSettings = new LockSettingsService(mContext);
        ILockSettings lockSettings = ILockSettings.Stub.asInterface(
        String currentPassword = lockSettings.getPassword();
                    ServiceManager.getService("lock_settings"));
        String currentPassword="default_password";
        try {
            currentPassword = lockSettings.getPassword();
        } catch (RemoteException e) {
            Slog.e(TAG, "Couldn't get password" + e);
        }


        try {
        try {
            NativeDaemonEvent event = mCryptConnector.execute("cryptfs", "changepw", CRYPTO_TYPES[type],
            NativeDaemonEvent event = mCryptConnector.execute("cryptfs", "changepw", CRYPTO_TYPES[type],
                        new SensitiveArg(currentPassword), new SensitiveArg(password));
                        new SensitiveArg(currentPassword), new SensitiveArg(password));
            try {
                lockSettings.sanitizePassword();
                lockSettings.sanitizePassword();
            } catch (RemoteException e) {
                Slog.e(TAG, "Couldn't sanitize password" + e);
            }

            return Integer.parseInt(event.getMessage());
            return Integer.parseInt(event.getMessage());
        } catch (NativeDaemonConnectorException e) {
        } catch (NativeDaemonConnectorException e) {
            // Encryption failed
            // Encryption failed