keymaster调试的几个辅助函数
CA侧打印cmd id字串:
const char* get_cmd(uint32_t cmd) { switch(cmd) { case KM_GENERATE_KEY: return "KM_GENERATE_KEY"; case KM_BEGIN_OPERATION: return "KM_BEGIN_OPERATION"; case KM_UPDATE_OPERATION: return "KM_UPDATE_OPERATION"; case KM_FINISH_OPERATION: return "KM_FINISH_OPERATION"; case KM_ABORT_OPERATION: return "KM_ABORT_OPERATION"; case KM_IMPORT_KEY: return "KM_IMPORT_KEY"; case KM_EXPORT_KEY: return "KM_EXPORT_KEY"; case KM_GET_VERSION: return "KM_GET_VERSION"; case KM_ADD_RNG_ENTROPY: return "KM_ADD_RNG_ENTROPY"; case KM_ATTEST_KEY: return "KM_ATTEST_KEY"; case KM_UPGRADE_KEY: return "KM_UPGRADE_KEY"; case KM_CONFIGURE: return "KM_CONFIGURE"; case KM_COMPUTE_SHARED_HMAC: return "KM_COMPUTE_SHARED_HMAC"; case KM_GET_HMAC_SHARING_PARAMETERS: return "KM_GET_HMAC_SHARING_PARAMETERS"; case KM_VERIFY_AUTHORIZATION: return "KM_VERIFY_AUTHORIZATION"; case KM_DELETE_KEY: return "KM_DELETE_KEY"; case KM_DELETE_ALL_KEYS: return "KM_DELETE_ALL_KEYS"; default: return "OTHER_CMD"; } }
TA侧打印param tag字串:
可放在ta_ca_defs.h中:
static inline char * get_keymaster_tag_string(keymaster_tag_t tag) { switch(tag) { case KM_TAG_INVALID : return "KM_TAG_INVALID"; case KM_TAG_PURPOSE : return "KM_TAG_PURPOSE"; case KM_TAG_ALGORITHM : return "KM_TAG_ALGORITHM"; case KM_TAG_KEY_SIZE : return "KM_TAG_KEY_SIZE"; case KM_TAG_BLOCK_MODE : return "KM_TAG_BLOCK_MODE"; case KM_TAG_DIGEST : return "KM_TAG_DIGEST"; case KM_TAG_PADDING : return "KM_TAG_PADDING"; case KM_TAG_CALLER_NONCE : return "KM_TAG_CALLER_NONCE"; case KM_TAG_MIN_MAC_LENGTH : return "KM_TAG_MIN_MAC_LENGTH"; case KM_TAG_KDF : return "KM_TAG_KDF"; case KM_TAG_EC_CURVE : return "KM_TAG_EC_CURVE"; case KM_TAG_RSA_PUBLIC_EXPONENT : return "KM_TAG_RSA_PUBLIC_EXPONENT"; case KM_TAG_ECIES_SINGLE_HASH_MODE : return "KM_TAG_ECIES_SINGLE_HASH_MODE"; case KM_TAG_INCLUDE_UNIQUE_ID : return "KM_TAG_INCLUDE_UNIQUE_ID"; case KM_TAG_BLOB_USAGE_REQUIREMENTS : return "KM_TAG_BLOB_USAGE_REQUIREMENTS"; case KM_TAG_BOOTLOADER_ONLY : return "KM_TAG_BOOTLOADER_ONLY"; case KM_TAG_ACTIVE_DATETIME : return "KM_TAG_ACTIVE_DATETIME"; case KM_TAG_ORIGINATION_EXPIRE_DATETIME : return "KM_TAG_ORIGINATION_EXPIRE_DATETIME"; case KM_TAG_USAGE_EXPIRE_DATETIME : return "KM_TAG_USAGE_EXPIRE_DATETIME"; case KM_TAG_MIN_SECONDS_BETWEEN_OPS : return "KM_TAG_MIN_SECONDS_BETWEEN_OPS"; case KM_TAG_MAX_USES_PER_BOOT : return "KM_TAG_MAX_USES_PER_BOOT"; case KM_TAG_ALL_USERS : return "KM_TAG_ALL_USERS"; case KM_TAG_USER_ID : return "KM_TAG_USER_ID"; case KM_TAG_USER_SECURE_ID : return "KM_TAG_USER_SECURE_ID"; case KM_TAG_NO_AUTH_REQUIRED : return "KM_TAG_NO_AUTH_REQUIRED"; case KM_TAG_USER_AUTH_TYPE : return "KM_TAG_USER_AUTH_TYPE"; case KM_TAG_AUTH_TIMEOUT : return "KM_TAG_AUTH_TIMEOUT"; case KM_TAG_ALLOW_WHILE_ON_BODY : return "KM_TAG_ALLOW_WHILE_ON_BODY"; case KM_TAG_ALL_APPLICATIONS : return "KM_TAG_ALL_APPLICATIONS"; case KM_TAG_APPLICATION_ID : return "KM_TAG_APPLICATION_ID"; case KM_TAG_EXPORTABLE : return "KM_TAG_EXPORTABLE"; case KM_TAG_APPLICATION_DATA : return "KM_TAG_APPLICATION_DATA"; case KM_TAG_CREATION_DATETIME : return "KM_TAG_CREATION_DATETIME"; case KM_TAG_ORIGIN : return "KM_TAG_ORIGIN"; case KM_TAG_ROLLBACK_RESISTANT : return "KM_TAG_ROLLBACK_RESISTANT"; case KM_TAG_ROOT_OF_TRUST : return "KM_TAG_ROOT_OF_TRUST"; case KM_TAG_OS_VERSION : return "KM_TAG_OS_VERSION"; case KM_TAG_OS_PATCHLEVEL : return "KM_TAG_OS_PATCHLEVEL"; case KM_TAG_UNIQUE_ID : return "KM_TAG_UNIQUE_ID"; case KM_TAG_ATTESTATION_CHALLENGE : return "KM_TAG_ATTESTATION_CHALLENGE"; case KM_TAG_ATTESTATION_APPLICATION_ID : return "KM_TAG_ATTESTATION_APPLICATION_ID"; case KM_TAG_ATTESTATION_ID_BRAND : return "KM_TAG_ATTESTATION_ID_BRAND"; case KM_TAG_ATTESTATION_ID_DEVICE : return "KM_TAG_ATTESTATION_ID_DEVICE"; case KM_TAG_ATTESTATION_ID_PRODUCT : return "KM_TAG_ATTESTATION_ID_PRODUCT"; case KM_TAG_ATTESTATION_ID_SERIAL : return "KM_TAG_ATTESTATION_ID_SERIAL"; case KM_TAG_ATTESTATION_ID_IMEI : return "KM_TAG_ATTESTATION_ID_IMEI"; case KM_TAG_ATTESTATION_ID_MEID : return "KM_TAG_ATTESTATION_ID_MEID"; case KM_TAG_ATTESTATION_ID_MANUFACTURER : return "KM_TAG_ATTESTATION_ID_MANUFACTURER"; case KM_TAG_ATTESTATION_ID_MODEL : return "KM_TAG_ATTESTATION_ID_MODEL"; case KM_TAG_ASSOCIATED_DATA : return "KM_TAG_ASSOCIATED_DATA"; case KM_TAG_NONCE : return "KM_TAG_NONCE"; case KM_TAG_AUTH_TOKEN : return "KM_TAG_AUTH_TOKEN"; case KM_TAG_MAC_LENGTH : return "KM_TAG_MAC_LENGTH"; case KM_TAG_RESET_SINCE_ID_ROTATION : return "KM_TAG_RESET_SINCE_ID_ROTATION"; default: return "default value"; } }
TA中dump数组:
一般用来dump来自CA的request数据进行分析:
#include <tee_internal_api_extensions.h> #include "log.h" void dump_hex_data(uint8_t *data, uint32_t data_len) { char buf[128]; int n = 0; int size = 0; int count = data_len/16; if(data_len % 16 != 0) { count++; } DMSG("dump hex data:data_len = %u, count = %d\n", data_len, count); for (uint32_t i = 0; i < count; i++) { n = 0; size = snprintf(&buf[n], sizeof(buf) - n, "[%03x]", i); n += size; uint32_t count_j = 16; if (i == count - 1 && data_len % 16 != 0) { count_j = data_len % 16; } for (uint32_t j = 0; j < count_j; j++) { size = snprintf(&buf[n], sizeof(buf) - n, " %02x", data[16 * i + j]); n += size; } buf[n] = '\0'; DMSG("%s\n", buf); } }