Skip to content

Commit

Permalink
Keymaster: Check that keymaster app is loaded
Browse files Browse the repository at this point in the history
qseecomd sets a property to indicate that it has successfully loaded
keymaster app. This patch ensures that keystore checks for this property
and waits for it to get set.

Change-Id: I2fec789208b30a51f23b49c9d09d6c5108629bcd
  • Loading branch information
Jyoti Wadhwani authored and ciwrl committed Dec 1, 2015
1 parent 8e39456 commit 2ff30db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Android.mk
Expand Up @@ -31,7 +31,8 @@ LOCAL_SHARED_LIBRARIES := \
libcrypto \
liblog \
libc \
libdl
libdl \
libcutils

LOCAL_ADDITIONAL_DEPENDENCIES := \
$(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr \
Expand Down
25 changes: 25 additions & 0 deletions keymaster_qcom.cpp
Expand Up @@ -43,6 +43,7 @@
#include <dlfcn.h>

#include <UniquePtr.h>
#include <cutils/properties.h>

#include "QSEEComAPI.h"
#include "keymaster_qcom.h"
Expand All @@ -53,6 +54,8 @@
#define LOG_TAG "QCOMKeyMaster"
#define UNUSED(x) (void)(x)
#define KM_SB_LENGTH (4096 * 2)
#define MAX_PROPERTY_GET_ATTEMPTS 60
#define PROPERTY_GET_SLEEP_INTERVAL 1

#include <cutils/log.h>
struct qcom_km_ion_info_t {
Expand Down Expand Up @@ -738,6 +741,8 @@ static int qcom_km_open(const hw_module_t* module, const char* name,
hw_device_t** device)
{
int ret = 0;
unsigned int attempt_num = 0;
char property_val[PROPERTY_VALUE_MAX] = {0};
qcom_keymaster_handle_t* km_handle;
if (strcmp(name, KEYSTORE_KEYMASTER) != 0)
return -EINVAL;
Expand All @@ -760,6 +765,26 @@ static int qcom_km_open(const hw_module_t* module, const char* name,
return -ENOMEM;
}
dev->context = (void *)km_handle;
while (attempt_num < MAX_PROPERTY_GET_ATTEMPTS)
{
property_get("sys.keymaster.loaded", property_val, "");
if (strncmp(property_val, "true", sizeof(property_val)) == 0)
{
ALOGD("keymaster app is loaded");
break;
}
if (attempt_num == 0)
ALOGE("keymaster app is not loaded, attempt num: %d", attempt_num);
attempt_num++;
sleep(PROPERTY_GET_SLEEP_INTERVAL);
}
if (attempt_num == MAX_PROPERTY_GET_ATTEMPTS)
{
ALOGE("keymaster app not loaded: Max attempts reached");
free(km_handle);
return -1;
}
ALOGD("keymaster app got loaded at attempt number %d", attempt_num);
ret = (*km_handle->QSEECom_start_app)((struct QSEECom_handle **)&km_handle->qseecom,
"/vendor/firmware/keymaster", "keymaster", KM_SB_LENGTH);
if(ret)
Expand Down

0 comments on commit 2ff30db

Please sign in to comment.