From 6864b7ec94a57b73c300457955d86dc604aeddf5 Mon Sep 17 00:00:00 2001 From: Ken Sumrall Date: Fri, 14 Jan 2011 15:20:02 -0800 Subject: [PATCH] Change the cryptfs command to separate out checking the password and restarting In order to make the animations and the UI look right, we need to change the cryptfs checkpw command to return a status if the password was correct or not, and not have it automatically restart if it's correct. There is a new command restart that will restart the framework with the encrypted filesystem. Change-Id: Ia8ae00d7ed8667699aa58d05ad8ba953cca9316e --- CommandListener.cpp | 6 ++++++ cryptfs.c | 16 ++++++++++++---- cryptfs.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CommandListener.cpp b/CommandListener.cpp index ac46ac9..c38a6d1 100644 --- a/CommandListener.cpp +++ b/CommandListener.cpp @@ -529,6 +529,12 @@ int CommandListener::CryptfsCmd::runCommand(SocketClient *cli, return 0; } rc = cryptfs_check_passwd(argv[2]); + } else if (!strcmp(argv[1], "restart")) { + if (argc != 2) { + cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs restart", false); + return 0; + } + rc = cryptfs_restart(); } else if (!strcmp(argv[1], "enablecrypto")) { if ( (argc != 4) || (strcmp(argv[2], "wipe") && strcmp(argv[2], "inplace")) ) { cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs enablecrypto ", false); diff --git a/cryptfs.c b/cryptfs.c index cf509c9..86cf17a 100644 --- a/cryptfs.c +++ b/cryptfs.c @@ -482,10 +482,11 @@ static int wait_and_unmount(char *mountpoint) return rc; } -static int cryptfs_restart(char *crypto_blkdev) +int cryptfs_restart(void) { char fs_type[32]; char real_blkdev[MAXPATHLEN]; + char crypto_blkdev[MAXPATHLEN]; char fs_options[256]; unsigned long mnt_flags; struct stat statbuf; @@ -516,6 +517,12 @@ static int cryptfs_restart(char *crypto_blkdev) * the tmpfs filesystem, and mount the real one. */ + property_get("ro.crypto.fs_crypto_blkdev", crypto_blkdev, ""); + if (strlen(crypto_blkdev) == 0) { + SLOGE("fs_crypto_blkdev not set\n"); + return -1; + } + if (! get_orig_mount_parms("/data", fs_type, real_blkdev, &mnt_flags, fs_options)) { SLOGD("Just got orig mount parms\n"); @@ -622,10 +629,11 @@ static int test_mount_encrypted_fs(char *passwd, char *mount_point) rc = crypt_ftr.failed_decrypt_count; } else { - /* Woot! Success! Time to do the magic of unmounting the tmpfs - * disk and mounting the encrypted one. + /* Woot! Success! Save the name of the crypto block device + * so we can mount it when restarting the framework. */ - rc = cryptfs_restart(crypto_blkdev); + property_set("ro.crypto.fs_crypto_blkdev", crypto_blkdev); + rc = 0; } return rc; diff --git a/cryptfs.h b/cryptfs.h index 32f1724..10b3b7d 100644 --- a/cryptfs.h +++ b/cryptfs.h @@ -53,6 +53,7 @@ struct crypt_mnt_ftr { extern "C" { #endif int cryptfs_check_passwd(char *pw); + int cryptfs_restart(void); int cryptfs_enable(char *flag, char *passwd); #ifdef __cplusplus }