Search in sources :

Example 31 with SensitiveArg

use of com.android.server.NativeDaemonConnector.SensitiveArg in project android_frameworks_base by AOSPA.

the class MountService method changeEncryptionPassword.

/** Set the password for encrypting the master key.
     *  @param type One of the CRYPTO_TYPE_XXX consts defined in StorageManager.
     *  @param password The password to set.
     */
public int changeEncryptionPassword(int type, String password) {
    mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, "no permission to access the crypt keeper");
    waitForReady();
    if (DEBUG_EVENTS) {
        Slog.i(TAG, "changing encryption password...");
    }
    ILockSettings lockSettings = ILockSettings.Stub.asInterface(ServiceManager.getService("lock_settings"));
    String currentPassword = "default_password";
    try {
        currentPassword = lockSettings.getPassword();
    } catch (RemoteException e) {
        Slog.e(TAG, "Couldn't get password" + e);
    }
    try {
        NativeDaemonEvent event = mCryptConnector.execute("cryptfs", "changepw", CRYPTO_TYPES[type], new SensitiveArg(currentPassword), new SensitiveArg(password));
        try {
            lockSettings.sanitizePassword();
        } catch (RemoteException e) {
            Slog.e(TAG, "Couldn't sanitize password" + e);
        }
        return Integer.parseInt(event.getMessage());
    } catch (NativeDaemonConnectorException e) {
        // Encryption failed
        return e.getCode();
    }
}
Also used : ILockSettings(com.android.internal.widget.ILockSettings) SensitiveArg(com.android.server.NativeDaemonConnector.SensitiveArg) RemoteException(android.os.RemoteException)

Example 32 with SensitiveArg

use of com.android.server.NativeDaemonConnector.SensitiveArg in project android_frameworks_base by AOSPA.

the class MountService method mountSecureContainer.

public int mountSecureContainer(String id, String key, int ownerUid, boolean readOnly) {
    enforcePermission(android.Manifest.permission.ASEC_MOUNT_UNMOUNT);
    waitForReady();
    warnOnNotMounted();
    synchronized (mAsecMountSet) {
        if (mAsecMountSet.contains(id)) {
            return StorageResultCode.OperationFailedStorageMounted;
        }
    }
    int rc = StorageResultCode.OperationSucceeded;
    try {
        mConnector.execute("asec", "mount", id, new SensitiveArg(key), ownerUid, readOnly ? "ro" : "rw");
    } catch (NativeDaemonConnectorException e) {
        int code = e.getCode();
        if (code != VoldResponseCode.OpFailedStorageBusy) {
            rc = StorageResultCode.OperationFailedInternalError;
        }
    }
    if (rc == StorageResultCode.OperationSucceeded) {
        synchronized (mAsecMountSet) {
            mAsecMountSet.add(id);
        }
    }
    return rc;
}
Also used : SensitiveArg(com.android.server.NativeDaemonConnector.SensitiveArg)

Example 33 with SensitiveArg

use of com.android.server.NativeDaemonConnector.SensitiveArg in project android_frameworks_base by ResurrectionRemix.

the class NativeDaemonConnectorTest method testSensitiveArgs.

public void testSensitiveArgs() throws Exception {
    final StringBuilder rawBuilder = new StringBuilder();
    final StringBuilder logBuilder = new StringBuilder();
    rawBuilder.setLength(0);
    logBuilder.setLength(0);
    makeCommand(rawBuilder, logBuilder, 1, "foo", "bar", "baz");
    assertEquals("1 foo bar baz\0", rawBuilder.toString());
    assertEquals("1 foo bar baz", logBuilder.toString());
    rawBuilder.setLength(0);
    logBuilder.setLength(0);
    makeCommand(rawBuilder, logBuilder, 1, "foo", new SensitiveArg("bar"), "baz");
    assertEquals("1 foo bar baz\0", rawBuilder.toString());
    assertEquals("1 foo [scrubbed] baz", logBuilder.toString());
    rawBuilder.setLength(0);
    logBuilder.setLength(0);
    makeCommand(rawBuilder, logBuilder, 1, "foo", new SensitiveArg("foo bar"), "baz baz", new SensitiveArg("wat"));
    assertEquals("1 foo \"foo bar\" \"baz baz\" wat\0", rawBuilder.toString());
    assertEquals("1 foo [scrubbed] \"baz baz\" [scrubbed]", logBuilder.toString());
}
Also used : SensitiveArg(com.android.server.NativeDaemonConnector.SensitiveArg)

Example 34 with SensitiveArg

use of com.android.server.NativeDaemonConnector.SensitiveArg in project android_frameworks_base by ResurrectionRemix.

the class MountService method mountSecureContainer.

public int mountSecureContainer(String id, String key, int ownerUid, boolean readOnly) {
    enforcePermission(android.Manifest.permission.ASEC_MOUNT_UNMOUNT);
    waitForReady();
    warnOnNotMounted();
    synchronized (mAsecMountSet) {
        if (mAsecMountSet.contains(id)) {
            return StorageResultCode.OperationFailedStorageMounted;
        }
    }
    int rc = StorageResultCode.OperationSucceeded;
    try {
        mConnector.execute("asec", "mount", id, new SensitiveArg(key), ownerUid, readOnly ? "ro" : "rw");
    } catch (NativeDaemonConnectorException e) {
        int code = e.getCode();
        if (code != VoldResponseCode.OpFailedStorageBusy) {
            rc = StorageResultCode.OperationFailedInternalError;
        }
    }
    if (rc == StorageResultCode.OperationSucceeded) {
        synchronized (mAsecMountSet) {
            mAsecMountSet.add(id);
        }
    }
    return rc;
}
Also used : SensitiveArg(com.android.server.NativeDaemonConnector.SensitiveArg)

Example 35 with SensitiveArg

use of com.android.server.NativeDaemonConnector.SensitiveArg in project android_frameworks_base by ResurrectionRemix.

the class MountService method createSecureContainer.

public int createSecureContainer(String id, int sizeMb, String fstype, String key, int ownerUid, boolean external) {
    enforcePermission(android.Manifest.permission.ASEC_CREATE);
    waitForReady();
    warnOnNotMounted();
    int rc = StorageResultCode.OperationSucceeded;
    try {
        mConnector.execute("asec", "create", id, sizeMb, fstype, new SensitiveArg(key), ownerUid, external ? "1" : "0");
    } catch (NativeDaemonConnectorException e) {
        rc = StorageResultCode.OperationFailedInternalError;
    }
    if (rc == StorageResultCode.OperationSucceeded) {
        synchronized (mAsecMountSet) {
            mAsecMountSet.add(id);
        }
    }
    return rc;
}
Also used : SensitiveArg(com.android.server.NativeDaemonConnector.SensitiveArg)

Aggregations

SensitiveArg (com.android.server.NativeDaemonConnector.SensitiveArg)42 RemoteException (android.os.RemoteException)3 ILockSettings (com.android.internal.widget.ILockSettings)3