Check crypto footer before offering to decrypt
Verify that we have a valid footer with proper magic before
setting things up for decryption to help prevent user confusion
when dealing with data partitions that fail to mount. Also check
to make sure that the block device for /data is present.
Change-Id: Ie87818fe4505a8bf71df7d3934c114e7328ef3ca
diff --git a/crypto/ics/cryptfs.c b/crypto/ics/cryptfs.c
index 193339e..4f3d5d0 100644
--- a/crypto/ics/cryptfs.c
+++ b/crypto/ics/cryptfs.c
@@ -653,6 +653,28 @@
return -1;
}
+int cryptfs_check_footer(void)
+{
+ int rc = -1;
+ char fs_type[PROPERTY_VALUE_MAX];
+ char real_blkdev[MAXPATHLEN];
+ char fs_options[PROPERTY_VALUE_MAX];
+ unsigned long mnt_flags;
+ struct crypt_mnt_ftr crypt_ftr;
+ /* Allocate enough space for a 256 bit key, but we may use less */
+ unsigned char encrypted_master_key[256];
+ unsigned char salt[SALT_LEN];
+
+ if (get_orig_mount_parms(DATA_MNT_POINT, fs_type, real_blkdev, &mnt_flags, fs_options)) {
+ printf("Error reading original mount parms for mount point %s\n", DATA_MNT_POINT);
+ return rc;
+ }
+
+ rc = get_crypt_ftr_and_key(real_blkdev, &crypt_ftr, encrypted_master_key, salt);
+
+ return rc;
+}
+
int cryptfs_check_passwd(const char *passwd)
{
char pwbuf[256];
diff --git a/crypto/ics/cryptfs.h b/crypto/ics/cryptfs.h
index eee43b3..8c80376 100644
--- a/crypto/ics/cryptfs.h
+++ b/crypto/ics/cryptfs.h
@@ -76,6 +76,7 @@
#ifdef __cplusplus
extern "C" {
#endif
+ int cryptfs_check_footer(void);
int cryptfs_check_passwd(const char *pw);
#ifdef __cplusplus
}