diff options
Diffstat (limited to 'cryptfs_hw.c')
-rwxr-xr-x | cryptfs_hw.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/cryptfs_hw.c b/cryptfs_hw.c index 109d406..b2efa4a 100755 --- a/cryptfs_hw.c +++ b/cryptfs_hw.c @@ -38,6 +38,8 @@ #include "cutils/log.h" #include "cutils/properties.h" #include "cutils/android_reboot.h" +#include "keymaster_common.h" +#include "hardware.h" #if defined(__LP64__) #define QSEECOM_LIBRARY_PATH "/vendor/lib64/libQSEEComAPI.so" @@ -63,6 +65,8 @@ #define SET_HW_DISK_ENC_KEY 1 #define UPDATE_HW_DISK_ENC_KEY 2 +#define KEYMASTER_PARTITION_NAME "/dev/block/bootdevice/by-name/keymaster" + static int loaded_library = 0; static int (*qseecom_create_key)(int, void*); static int (*qseecom_update_key)(int, void*, void*); @@ -228,3 +232,36 @@ int clear_hw_device_encryption_key() return 0; } + +static int get_keymaster_version() +{ + int rc = -1; + const hw_module_t* mod; + rc = hw_get_module_by_class(KEYSTORE_HARDWARE_MODULE_ID, NULL, &mod); + if (rc) { + SLOGE("could not find any keystore module"); + return rc; + } + + return mod->module_api_version; +} + +int should_use_keymaster() +{ + /* HW FDE key would be tied to keymaster only if: + * New Keymaster is available + * keymaster partition exists on the device + */ + int rc = 0; + if (get_keymaster_version() != KEYMASTER_MODULE_API_VERSION_1_0) { + SLOGI("Keymaster version is not 1.0"); + return rc; + } + + if (access(KEYMASTER_PARTITION_NAME, F_OK) == -1) { + SLOGI("Keymaster partition does not exists"); + return rc; + } + + return 1; +} |