summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Bestas <mkbestas@lineageos.org>2017-12-20 17:12:59 (GMT)
committerMichael Bestas <mkbestas@lineageos.org>2019-01-03 22:10:10 (GMT)
commit83ec2af13a970695390b5a582692910d71ebf0b5 (patch)
tree789546859293fb64b35bcadd03caf798f887f741
parent9f74288f2ca0daad723414ee528cf4adc1eb6430 (diff)
downloadandroid_vendor_qcom_opensource_cryptfs_hw-83ec2af13a970695390b5a582692910d71ebf0b5.zip
android_vendor_qcom_opensource_cryptfs_hw-83ec2af13a970695390b5a582692910d71ebf0b5.tar.gz
android_vendor_qcom_opensource_cryptfs_hw-83ec2af13a970695390b5a582692910d71ebf0b5.tar.bz2
cryptfs_hw: Add compatibility for pre-O hw cryptorefs/changes/28/226128/9
* Restore compatibility for pre-O way of hw crypto interaction with qsee as the new way is not compatible with old blobs. * Old blobs and current OSS keymaster still use the old property to check if qseecomd is loaded. * This conditionally reverts: cryptfs_hw: Add new APIs for key management 84ac4882d6feeceb24e983a4eaba1d148c2ba3e6 cryptfs_hw: Use HW keymaster for FDE keys a5d3a02eb13362490222ac2a7eefde6543546e31 cryptfs_hw: Update listener status flag eec7d0b6d8e690ebe268965e89593812d607b3a8 Change-Id: I9a5db406c16c3610237a1b85fbfab5c0d63e4960
-rw-r--r--Android.bp8
-rw-r--r--cryptfs_hw.c124
2 files changed, 118 insertions, 14 deletions
diff --git a/Android.bp b/Android.bp
index 8aea8b6..12e2aa6 100644
--- a/Android.bp
+++ b/Android.bp
@@ -16,6 +16,14 @@ cc_library_shared {
srcs: sourceFiles,
shared_libs: commonSharedLibraries,
+ product_variables: {
+ lineage: {
+ supports_legacy_hw_fde: {
+ cflags: ["-DLEGACY_HW_DISK_ENCRYPTION"],
+ },
+ },
+ },
+
owner: "qti",
}
diff --git a/cryptfs_hw.c b/cryptfs_hw.c
index a5d76ef..36d5d48 100644
--- a/cryptfs_hw.c
+++ b/cryptfs_hw.c
@@ -45,6 +45,10 @@
#include "cutils/android_reboot.h"
#include "cryptfs_hw.h"
+#ifdef LEGACY_HW_DISK_ENCRYPTION
+#define QSEECOM_LIBRARY_NAME "libQSEEComAPI.so"
+#endif
+
/*
* When device comes up or when user tries to change the password, user can
* try wrong password upto a certain number of times. If user enters wrong
@@ -59,6 +63,13 @@
#define SET_HW_DISK_ENC_KEY 1
#define UPDATE_HW_DISK_ENC_KEY 2
+#ifdef LEGACY_HW_DISK_ENCRYPTION
+static int loaded_library = 0;
+static int (*qseecom_create_key)(int, void*);
+static int (*qseecom_update_key)(int, void*, void*);
+static int (*qseecom_wipe_key)(int);
+#endif
+
#define CRYPTFS_HW_KMS_CLEAR_KEY 0
#define CRYPTFS_HW_KMS_WIPE_KEY 1
#define CRYPTFS_HW_UP_CHECK_COUNT 10
@@ -85,6 +96,89 @@ static inline void* secure_memset(void* v, int c , size_t n)
return v;
}
+#ifdef LEGACY_HW_DISK_ENCRYPTION
+static int is_qseecom_up()
+{
+ int i = 0;
+ char value[PROPERTY_VALUE_MAX] = {0};
+
+ for (; i<CRYPTFS_HW_UP_CHECK_COUNT; i++) {
+ property_get("sys.keymaster.loaded", value, "");
+ if (!strncmp(value, "true", PROPERTY_VALUE_MAX))
+ return 1;
+ usleep(100000);
+ }
+ return 0;
+}
+
+static int load_qseecom_library()
+{
+ const char *error = NULL;
+ if (loaded_library)
+ return loaded_library;
+
+ if (!is_qseecom_up()) {
+ SLOGE("Timed out waiting for QSEECom listeners. Aborting FDE key operation");
+ return 0;
+ }
+
+ void * handle = dlopen(QSEECOM_LIBRARY_NAME, RTLD_NOW);
+ if (handle) {
+ dlerror(); /* Clear any existing error */
+ *(void **) (&qseecom_create_key) = dlsym(handle, "QSEECom_create_key");
+
+ if ((error = dlerror()) == NULL) {
+ SLOGD("Success loading QSEECom_create_key \n");
+ *(void **) (&qseecom_update_key) = dlsym(handle, "QSEECom_update_key_user_info");
+ if ((error = dlerror()) == NULL) {
+ SLOGD("Success loading QSEECom_update_key_user_info\n");
+ *(void **) (&qseecom_wipe_key) = dlsym(handle, "QSEECom_wipe_key");
+ if ((error = dlerror()) == NULL) {
+ loaded_library = 1;
+ SLOGD("Success loading QSEECom_wipe_key \n");
+ }
+ else
+ SLOGE("Error %s loading symbols for QSEECom APIs \n", error);
+ }
+ else
+ SLOGE("Error %s loading symbols for QSEECom APIs \n", error);
+ }
+ } else {
+ SLOGE("Could not load libQSEEComAPI.so \n");
+ }
+
+ if (error)
+ dlclose(handle);
+
+ return loaded_library;
+}
+
+static int cryptfs_hw_create_key(enum cryptfs_hw_key_management_usage_type usage,
+ unsigned char *hash32)
+{
+ if (load_qseecom_library())
+ return qseecom_create_key(usage, hash32);
+
+ return CRYPTFS_HW_CREATE_KEY_FAILED;
+}
+
+static int cryptfs_hw_wipe_key(enum cryptfs_hw_key_management_usage_type usage)
+{
+ if (load_qseecom_library())
+ return qseecom_wipe_key(usage);
+
+ return CRYPTFS_HW_WIPE_KEY_FAILED;
+}
+
+static int cryptfs_hw_update_key(enum cryptfs_hw_key_management_usage_type usage,
+ unsigned char *current_hash32, unsigned char *new_hash32)
+{
+ if (load_qseecom_library())
+ return qseecom_update_key(usage, current_hash32, new_hash32);
+
+ return CRYPTFS_HW_UPDATE_KEY_FAILED;
+}
+#else
static size_t memscpy(void *dst, size_t dst_size, const void *src, size_t src_size)
{
size_t min_size = (dst_size < src_size) ? dst_size : src_size;
@@ -258,6 +352,7 @@ static int cryptfs_hw_update_key(enum cryptfs_hw_key_management_usage_type usage
close(qseecom_fd);
return ret;
}
+#endif
static int map_usage(int usage)
{
@@ -292,20 +387,6 @@ static unsigned char* get_tmp_passwd(const char* passwd)
return tmp_passwd;
}
-static int is_qseecom_up()
-{
- int i = 0;
- char value[PROPERTY_VALUE_MAX] = {0};
-
- for (; i<CRYPTFS_HW_UP_CHECK_COUNT; i++) {
- property_get("vendor.sys.keymaster.loaded", value, "");
- if (!strncmp(value, "true", PROPERTY_VALUE_MAX))
- return 1;
- usleep(100000);
- }
- return 0;
-}
-
/*
* For NON-ICE targets, it would return 0 on success. On ICE based targets,
* it would return key index in the ICE Key LUT
@@ -383,6 +464,7 @@ int clear_hw_device_encryption_key()
return cryptfs_hw_wipe_key(map_usage(CRYPTFS_HW_KM_USAGE_DISK_ENCRYPTION));
}
+#ifdef LEGACY_HW_DISK_ENCRYPTION
static int get_keymaster_version()
{
int rc = -1;
@@ -395,11 +477,25 @@ static int get_keymaster_version()
return mod->module_api_version;
}
+#endif
int should_use_keymaster()
{
+#ifdef LEGACY_HW_DISK_ENCRYPTION
+ /*
+ * HW FDE key should be tied to keymaster only if
+ * new Keymaster is available
+ */
+ int rc = 0;
+ if (get_keymaster_version() != KEYMASTER_MODULE_API_VERSION_1_0) {
+ SLOGI("Keymaster version is not 1.0");
+ return rc;
+ }
+#else
/*
* HW FDE key should be tied to keymaster
*/
+#endif
+
return 1;
}